
Hello, Is there a variant of this int i = 0; lambda::var( i )++; in which I can do away with the external variable, i? In other words, a nullary functor that returns 0, 1, 2, successively? Thanks.

AMDG On 03/09/2011 03:26 PM, er wrote:
Is there a variant of this
int i = 0; lambda::var( i )++;
in which I can do away with the external variable, i? In other words, a nullary functor that returns 0, 1, 2, successively?
No. Remember that function objects are copyable. The state needs to be stored separately to avoid problems. In Christ, Steven Watanabe

On 3/9/11 6:35 PM, Steven Watanabe wrote:
AMDG
On 03/09/2011 03:26 PM, er wrote:
Is there a variant of this
int i = 0; lambda::var( i )++;
in which I can do away with the external variable, i? In other words, a nullary functor that returns 0, 1, 2, successively?
No. Remember that function objects are copyable. The state needs to be stored separately to avoid problems.
Thanks. I was hoping new_ptr<>() could come to the rescue...
In Christ, Steven Watanabe

On 9 Mar 2011, at 23:26, er wrote:
Hello,
Is there a variant of this
int i = 0; lambda::var( i )++;
in which I can do away with the external variable, i? In other words, a nullary functor that returns 0, 1, 2, successively?
You could write one, something like (not compile tested!) struct Counter { boost::shared_ptr<int> ptr; Counter() : ptr(new int(-1)) {} int operator()() { *(ptr)++; return *ptr; } };
participants (3)
-
Christopher Jefferson
-
er
-
Steven Watanabe