Boost logo

Boost :

Subject: Re: [boost] [local] "true" lambdas without C++11 but only on GCC
From: Lorenzo Caminiti (lorcaminiti_at_[hidden])
Date: 2011-11-29 05:01:24

On Mon, Nov 28, 2011 at 7:02 PM, Dave Abrahams <dave_at_[hidden]> wrote:
> on Thu Nov 17 2011, Lorenzo Caminiti <> wrote:
>> 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.

Yes, I found on-line that these compilers support expression statements:

GCC >=3
Intel C++ Compiler >=?
Clang/LLVM >= ?
Sun Studio >= 12 (New Language Extensions)
IBM XL for z/OS (marked as IBM extension)
Open64 (as it use osprey-gcc frontend)
PathScale® EKOPath
Any more? EDG? Comeau?

The LAMBDA macros could be implemented to expand using C++11 lambdas
on compilers that have them (MSVC>=10, later GCC, etc), to expand
using expression statements + Boost.Local on the above compilers, and
to generate a compiler error otherwise. That way we'd have "true"
lambdas for MSVC plus the compilers above...

Would this be useful to Boost?

Thanks a lot.

Boost list run by bdawes at, gregod at, cpdaniel at, john at