查看了一些关于C++ 14的在线文档后,我发现以下语法用于在C++ 14中定义一个函数,该函数使用尾随返回类型: auto myFunc() -> int {}
我的问题是,其他然后用这种方式为参数和其他一些情况下使用decltype,和是有区别或者使用上述语法沼泽标准功能,如任何好处: int myFunc() {}
int main()
{
auto l = [x = 10]() -> decltype(x) {};
}
clang++ 4.0 rejects this code,错误如下: error: use of undeclared identifier 'x'
auto l = [x = 10]() -> decltype(x) {};
^
我需要从函数返回一个const引用。此代码的东西: auto test()->add_lvalue_reference<const int>::type
{
static int i{50};
return i;
}
int & i{test()}; // doesn't compile
但这个片段中,看起来痛苦相似,给出了一个不正确的结果: auto const
§8/ 5: 在尾随收益型可选属性符-SEQ appertains到指定的回报类型。 type-id in a trailing-return-type包含最长可能的序列abstract-declarator s。 [注:这解决了数组和函数声明符的模糊绑定。 [示例: auto f()->int(*)[4]; // function returning a pointer to array[4]