相关疑难解决方法(0)

从C++ 14开始的尾随返回类型语法的合法使用

是否有任何理由再使用以下语法:

template<typename T>
auto access(T& t, int i)
  -> decltype(t[i])
{
    return t[i];
}
Run Code Online (Sandbox Code Playgroud)

现在我们可以使用:

template<typename T>
decltype(auto) access(T& t, int i)
{
    return t[i];
}
Run Code Online (Sandbox Code Playgroud)

现在,尾随返回类型语法似乎有点多余?

c++ trailing-return-type return-type-deduction c++14

7
推荐指数
2
解决办法
447
查看次数