[Fusion] fusion::for_each with stateful functors
Hello Boost Users, More than three years ago this question arose in this list: http://lists.boost.org/boost-users/2007/03/26338.php And as I understand it was concluded that overload for non-const references should be added. But now there are only const references to functor available. Was it forgotten or there are some reasons not to have such overload? What is the best way to solve the problem? Mutable members or some proxies look quirky. Thanks!
2010/9/20 Paul Graphov
What is the best way to solve the problem? Mutable members or some proxies look quirky.
I do use some proxies, like fref<Signature>(functor) which returns a functor_reference_wrapper to solve this. fref is what I made myself, not part of Boost, I don't know if anyone else would think this useful.
Zitat von Paul Graphov
Hello Boost Users,
More than three years ago this question arose in this list:
http://lists.boost.org/boost-users/2007/03/26338.php
And as I understand it was concluded that overload for non-const references should be added. But now there are only const references to functor available. Was it forgotten or there are some reasons not to have such overload?
What is the best way to solve the problem? Mutable members or some proxies look quirky.
without reading the thread, I doubt there is a consensus that algorithm functors should be mutable. you can create a functor that refers to mutable state, e.g. using Boost.Bind: void f(int &state,T &e); int main(){ int state=0; fusion::for_each(vec,bind(&f,ref(state),_1)); }
Hello,
Indeed, binding the state looks better. Thanks!
On 20 September 2010 22:00, Stefan Strasser
Zitat von Paul Graphov
: Hello Boost Users,
More than three years ago this question arose in this list:
http://lists.boost.org/boost-users/2007/03/26338.php
And as I understand it was concluded that overload for non-const references should be added. But now there are only const references to functor available. Was it forgotten or there are some reasons not to have such overload?
What is the best way to solve the problem? Mutable members or some proxies look quirky.
without reading the thread, I doubt there is a consensus that algorithm functors should be mutable. you can create a functor that refers to mutable state, e.g. using Boost.Bind:
void f(int &state,T &e);
int main(){ int state=0; fusion::for_each(vec,bind(&f,ref(state),_1)); }
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (3)
-
Paul Graphov
-
Stefan Strasser
-
TONGARI