|
Boost Users : |
Subject: Re: [Boost-users] [Fusion] fusion::for_each with stateful functors
From: Stefan Strasser (strasser_at_[hidden])
Date: 2010-09-20 14:00:57
Zitat von Paul Graphov <graphov_at_[hidden]>:
> 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 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