を任意の式をキャプチャ、GCC 4.7.2は、次のコードで何の問題もないように見える:記載されていないGCC C++ 11拡張?不思議なことに、ラムダキャプチャリストに
template<typename T>
T&& identity(T&& x1) {
return std::forward<T>(x1);
}
int main(int, char**) {
int x1 = 1;
int &x2 = identity(x1);
auto f = [&x1]() mutable {
x1 = x1 + 1;
};
auto g1 = [y=x2+1]() {
static_assert(std::is_same<decltype(y), const int>::value, "fail");
std::cout << "g1: " << y << std::endl;
};
auto h1 = [y=identity(x1)+1]() {
static_assert(std::is_same<decltype(y), const int>::value, "fail");
std::cout << "h1: " << y << std::endl;
};
auto g2 = [&y=x2]() {
static_assert(std::is_same<decltype(y), int&>::value, "fail");
std::cout << "g2: " << y << std::endl;
};
auto h2 = [&y=identity(x1)]() {
static_assert(std::is_same<decltype(y), int&>::value, "fail");
std::cout << "h2: " << y << std::endl;
};
f(); g1(); h1(); g2(); h2();
f(); g1(); h1(); g2(); h2();
return 0;
}
結果は以下の通りである:
g1: 2
h1: 2
g2: 2
h2: 2
g1: 2
h1: 2
g2: 3
h2: 3
私はできませんn3285(2012年10月2日付)であっても、ラムダキャプチャリストの任意の表現をキャプチャすることについて言及しているようです。また、私は公式のGCC拡張としてどこのドキュメントも見つけられないようです。
は、文書化されていないGCCの拡張機能(ラVLAs as structure members、GCCは先に行って、早期実施していることを特徴と++提案/次期C、どちらも、両方、または何本か?
このようなものについて[提案](http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2013/n3610.html)があります。 –
@JohnSchugああ、それは2013年3月15日となっています!答えは「両方」ですか? (これは提案よりも前にあると思われます) –
(これはGCCの実装について言及していないので、これとは完全に独立して開発されるかもしれません) –