Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.
7953 Discussions

ICC 12.1.0e compile failure with lambda function.

Pallav_G_Intel
Employee
374 Views
Hi,

Consider the code in this example:

test.cpp


This code compiles/run fine on GCC 4.6.2, but on ICC 12.1.0e, I get the following error:

$ icpc test.cpp
test.cpp(22): error: expected an expression
for_each(idx.begin(), idx.end(), [&m_vec](int x) { cout << m_vec << "\\n"; });
^

compilation aborted for test.cpp (code 2)

The [&m_vec] should be [this]. It seems like there is compatibility issues between ICC/GNU GCC on this. The standard seems to say [this] is correct. Perhaps this issue could be resolved to make ICC compatible with GCC?

Thanks.

0 Kudos
1 Reply
SergeyKostrov
Valued Contributor II
374 Views
...
for_each( idx.begin(), idx.end(), [&m_vec](int x) { cout << m_vec << "\n"; } );
...

Are you sure thatthe Last term of 'for_each'statement can't be evaluated bythe C++ compilerto a function with one argument?
0 Kudos
Reply