Boost logo

Boost Users :

Subject: Re: [Boost-users] [fusion] nth runtime element of a sequence
From: Larry Evans (cppljevans_at_[hidden])
Date: 2014-02-24 16:27:11


On 02/24/14 12:51, Larry Evans wrote:
> On 02/24/14 11:55, MM wrote:
>>
>>
>> On 24 February 2014 14:28, Larry Evans <cppljevans_at_[hidden]
>> <mailto:cppljevans_at_[hidden]>> wrote:
>>
>> On 02/24/14 05:04, Krzysztof Czainski wrote:
>>
>> 2014-02-24 11:55 GMT+01:00 MM <finjulhich_at_[hidden]
>> <mailto:finjulhich_at_[hidden]>
>> <mailto:finjulhich_at_[hidden] <mailto:finjulhich_at_[hidden]>>>__:
>>
>>
>> Hello,
>>
>> I just wanted to confirm there's no provided method to get
>> the n'th
>> element of say a fusion vector where n is known at runtime,
>> except
>> of handling it explicitkly with a switch case?
>>
>> Thanks
>>
>> MM
>>
>>
>> If such a function existed, what return type would it have?
>>
>> Regards,
>> Kris
>>
>> What about:
>> variant<T1,T2,T3> get(unsigned n, vector<T1,T2,T3>)
>> ? For example:
>>
>> vector<T1,T2,T3> vec(T1(),T2(),T3());
>> variant<T1,T2,T3> var;
>> var = get(2,vec);
>> assert(var.which(),2);
>>
>> -regards,
>> Larry
>>
>> Possible, a variant over the unique types in the sequence.
>> What would the impl look like though?
>>
> I'd guess it would have switch statements, as you surmised
> in your OP. I'd also guess it could be implemented with
> some sort of vector of n functors, where n is the
> size of the fusion vector, and the i-th functor simply
> call fusion's get<i>(vec) and assigns the result to
> the variant. This vector of functors would then be used
> in the implementation of the get(i,vec) mentioned in my
> post.

This vector of functors was proposed for variant here:

http://lists.boost.org/Archives/boost/2012/04/192357.php

IIRC, there was also a preprocessor generated switch
statement as an alternative implementation. I'd guess
this should give some idea of how to do what you want.

HTH.

>
> HTH
> -regards,
> Larry


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net