How to use boost::fusion::transform on heterogeneous containers?

Posted by Kyle on Stack Overflow See other posts from Stack Overflow or by Kyle
Published on 2010-05-15T23:05:36Z Indexed on 2010/05/15 23:10 UTC
Read the original article Hit count: 244

Filed under:
|
|
|

Boost.org's example given for fusion::transform is as follows:

struct triple
{
    typedef int result_type;

    int operator()(int t) const
    {
        return t * 3;
    };
};
// ...
assert(transform(make_vector(1,2,3), triple()) == make_vector(3,6,9));

Yet I'm not "getting it." The vector in their example contains elements all of the same type, but a major point of using fusion is containers of heterogeneous types. What if they had used make_vector(1, 'a', "howdy") instead?

int operator()(int t)
would need to become
template<typename T> T& operator()(T& const t)

But how would I write the result_type? template<typename T> typedef T& result_type certainly isn't valid syntax, and it wouldn't make sense even if it was, because it's not tied to the function.

© Stack Overflow or respective owner

Related posts about c++

Related posts about boost