|
Boost : |
From: Brian Braatz (brianb_at_[hidden])
Date: 2005-06-02 17:43:46
I am using the fusion code in 1.32 with the vc 71. compiler.
My question is, considering the following unit test (for_each_tests.cpp)
struct print
{
template <typename T>
void operator()(T const& v) const
{
std::cout << "[ " << v << " ] ";
}
};
{
typedef tuple<int, char, double, char const*> tuple_type;
tuple_type t(1, 'x', 3.3, "Ruby");
for_each(t, print());
std::cout << std::endl;
}
(this code runs correctly for me)
If I change the function to:
struct print
{
template <typename T>
void operator()(T & v) const
{
std::cout << "[ " << v << " ] ";
}
};
It still works, but changing it to
struct print
{
template <typename T>
void operator()(T & v)
{
std::cout << "[ " << v << " ] ";
}
};
Does not work.
Why does the functor need to have a const operator()?
I have been trying to take a tuple<> and touch each node in the tuple
(ala for_each in fusion), which I was *very* happy to find fusion has
this as working functionality.
But, the next step for me is to have the functor write to its local
member variables. I.e. requiring const here really limits the usefulness
of the fusion::for_each.
I look in my compilers header and noticed that stl::for_each does not
have a const requirement on the functor.
Is this a mistake? Is there a reason I am not seeing why for_each would
have this limitation?
Thanks for any help and guidance.
Brian
"Remember, there are no stupid questions. Only stupid people....."
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk