With the -Winline I want to check the inlining of lambda into the code.
Where should the inline keyword be to make inline-lambda in GCC in a function call?
#include <iostream>
#include <algorithm>
#include <vector>
int main() {
std::vector<int> numbers{3, 4, 2, 9, 15, 267};
std::for_each(numbers.begin(), numbers.end(), /* inline */ [](int &n){ n++; });
return 0;
}
I tried a lambda variable, but it fails:
inline auto inc = [](int &n){ n++ };
$ g++ -std=c++11 -Winline test.cpp
test.cpp:13:15: error: ‘x’ declared as an ‘inline’ variable
inline auto x = [](int &n) { return n++; };
Aucun commentaire:
Enregistrer un commentaire