Re: [Boost-users] Using Boost.Fusion transform on vector<int&>

Martin Ecker wrote:
I need something like the following (somewhat contrived) example to work with boost::fusion::transform on a boost::fusion::vector<int&> or other vector types that have reference types. Note that the following doesn't compile.
<snip original example> The following code allows references to pass through, as I believe you want. It just uses a slight modification to your function object to allow it to cope with references correctly. namespace { struct pass_through { template<typename Sig> struct result; template<typename T> struct result<pass_through(T&)> { typedef T& type; }; template<typename T> T& operator()(T& t) const { return t; } }; } int main() { typedef fusion::vector<int&> vec; int i = 202; vec v1(i); vec v2(fusion::transform(v1, pass_through())); std::cout << fusion::at_c<0>(v2) << std::endl; // Output 202 } Is this ok for your needs? Cheers Dan ___________________________________________________________ Yahoo! Answers - Got a question? Someone out there knows the answer. Try it now. http://uk.answers.yahoo.com/

Hi Dan, dan marsden wrote:
The following code allows references to pass through, as I believe you want. It just uses a slight modification to your function object to allow it to cope with references correctly.
<snip modified code> My problem is that in pass_through::operator () I need to know the actual type stored in the vector. With your modified code I would not necessarily get that, e.g. for vector<int, int&> where I would not have any way of distinguishing whether T is a reference or not. That's what I need actually. My example might have been a bit contrived. To give more context: For each type T in a vector I want to conditionally transform the type T to another type to get a new vector where some of the types and values have been changed and some have simply been passed through. Thanks, Martin
participants (2)
-
dan marsden
-
Martin Ecker