问题描述
struct Test
{
static const int value = []() - > int {return 0; }();
};
使用gcc-4.6,我得到类似于错误:function需要constexpr
。我尝试了多种组合在 constexpr
在各个地方,但没有运气。
是 constexpr
也支持lambda函数(不管 return
是否指定类型)?
> Lambdas目前(C ++ 14)不允许在[expr.const] /(2.6)的常量表达式中,但他们会一次(可在工作草案N4582中找到):
struct Test
{
static const int value = []() -> int { return 0; } ();
};
With gcc-4.6 I get something like, error: function needs to be constexpr
. I have tried multiple combinations of putting constexpr
at various places, but no luck.
Is constexpr
supported for lambda functions as well (irrespective of return
type specified or not) ? What is the correct syntax ?
Any work around possible ?
Lambdas are currently (C++14) not allowed in constant expressions as per [expr.const]/(2.6), but they will once N4487 is accepted (which can be found in the working draft N4582):
这篇关于constexpr是否支持lambda函数/表达式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!