Boost logo

Boost :

From: Joel de Guzman (joel_at_[hidden])
Date: 2007-09-24 04:17:44


Dean Michael Berris wrote:

>> The world fusion (and for that matter, mpl) lives in has some peculiar
>> constraints. As I noted above, one is that you cannot determine a type
>> from a runtime predicate. You can, however, do it inside-out. IOTW,
>> let the predicate itself get the info that you need. If you really
>> need to return a type, somehow, you can, for example, use a pointer
>> to a base class, hold the value in a boost::any, etc. In other words
>> use type erasure. If I were you, I'd use the visitor, f, itself to
>> do the action as soon as the correct type is obtained. No type
>> erasure magic.
>>
>
> This makes sense, though there might be a possibility where a
> homogeneous tuple would be able to return just a single value:
>
> struct equals_2 {
> template <typename T>
> T operator() (T element) const {
> if (element == 2) return element;
> };
> };
>
> typedef fusion::tuple<int, int, int> point_type;
> point_type point(1, 2, 3);
> assert(fusion::is_homogenous<point_type>::value == true);
> assert(fusion::find_first_if<equals_2>(point) == 2); // only works if
> 'point' is a homogeneous container

If that was the case, I'd use boost::array which is a nice data structure
that has a special property: it is *both* a fusion sequence *and* an stl
sequence.

Regards,

-- 
Joel de Guzman
http://www.boost-consulting.com
http://spirit.sf.net

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk