|
Boost Users : |
From: dan marsden (danmarsden_at_[hidden])
Date: 2007-09-12 02:22:47
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/
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