Boost logo

Boost :

Subject: Re: [boost] [local] "true" lambdas without C++11 but only on GCC
From: Dave Abrahams (dave_at_[hidden])
Date: 2011-11-28 19:02:36


on Thu Nov 17 2011, Lorenzo Caminiti <lorcaminiti-AT-gmail.com> wrote:

> Hello all,
>
> A curiosity: On GCC compilers (but _only_ on GCC compilers) it is
> possible to combine Boost.Local and the non-standard GCC "expression
> statements" feature to implement lambda functions. In other words, it
> is possible to define a Boost.Local closure within a GCC expression
> statement:
>
> std::vector<int> v(3);
> v[0] = 1; v[1] = 2; v[2] = 3;
> int factor = 10;
>
> std::for_each(v.begin(), v.end(),
> LAMBDA(int x, const bind& factor) {
> std::cout << x * factor << std::endl;
> } LAMBDA_END
> );
>
> This is just a curiosity because it is NOT standard C++03 and it will
> ONLY work with GCC compilers.

I think other compilers such as EDG and Clang may support this extension
for GCC-compatibility.

-- 
Dave Abrahams
BoostPro Computing
http://www.boostpro.com

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk