const TBigType& a = [](){
TBigType result;
// ...
return result;
}();
use(a); // by const ref
像这样捕获结果到const引用中是否可行?
const TBigType& a = [](){
TBigType result;
// ...
return result;
}();
use(a); // by const ref
像这样捕获结果到const引用中是否可行?
int f() { return 12; }
const int& a = f();
这里a
被绑定到一个临时对象,类型为int
,值为12
。
如果您没有指定lambda的返回类型,则返回类型始终为void
或对象类型。如果您希望您的lambda返回一个lvalue或xvalue,则需要显式指定返回类型,例如-> int&
,-> auto&
,-> decltype(auto)
等。
TBigType
一个移动构造函数。 - Lightness Races in Orbit