A bit more obfuscated (for immutable bittypes only):
julia> immutable Foo{T}
a::T
b::T
c::T
end
julia> x = Foo([1,2,3]...)
Foo{Int64}(1,2,3)
julia> reinterpret(Int, [x])
3-element Array{Int64,1}:
1
2
3
On Thu, 2015-03-05 at 11:00, Simon Danisch <[email protected]> wrote:
> easiest would probably be: [foo.(i) for i=1:length(names(Foo))]
>
>
> Am Donnerstag, 5. März 2015 10:51:36 UTC+1 schrieb Tamas Papp:
>>
>> If I have a composite type
>>
>> type Foo
>> a
>> b
>> c
>> end
>>
>> I can initialize it with a vector like this:
>>
>> x = Foo([1,2,3]...)
>>
>> But how can I get the fields as a vector, eg [x.a,x.b,x.c] without
>> enumerating them? convert(x, Vector) does not work.
>>
>> I need this to go back and forth between the type and the vector
>> representation of a set of parameters when using NLopt.
>>
>> Best,
>>
>> Tamas
>>