|
Boost : |
From: Max Motovilov (max_at_[hidden])
Date: 2004-03-03 18:50:44
"Powell, Gary" <powellg_at_[hidden]> wrote in message
news:16D81990DBE42642A8CA977A55FF116A0BD398_at_ex-mail-sea-02.ant.amazon.com...
> In my plan, variables would have same scope in a function as they do now.
i.e. variables local to std::accumulate
> are not visible in the anonymous fn.
That's not what I was asking about. Will the anonymous function see the
names visible in the scope of its definition?
unsigned long foo (vector<X> const &xs)
{
unsigned y = 0;
unsigned long n = std::accumulate(
xs.begin(), xs.end(), 0UL,
unsigned long (unsigned long lhs, X const &rhs) // inline fn
with no name.
{
return ++y * (lhs + rhs.count);
}
);
return n;
}
A slightly brain-dead example, but it illustrates my question. As I
understand it, one can easily include references to local variables in a
lambda expression using ref(). Since current language does not allow us to
define one function body inside another, we can't really take "as it is now"
for a guideline. Nested blocks OTOH do not prevent access to outer local
variables, but you can't call nested blocks recursively...
...Max...
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk