fusion::for_each question: Why const operator in the fctor?

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....."

Brian Braatz wrote:
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)
[...]
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?
That's an oversight. It will be fixed immediately after 1.33. I am working on Fusion now. Thanks for noticing! Cheers, -- Joel de Guzman http://www.boost-consulting.com http://spirit.sf.net
participants (2)
-
Brian Braatz
-
Joel de Guzman