|
Boost Users : |
Subject: Re: [Boost-users] lambda::var( i )++
From: Christopher Jefferson (chris_at_[hidden])
Date: 2011-03-10 04:01:52
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;
}
};
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