相关疑难解决方法(0)

尾随返回类型语法样式应该成为新C++ 11程序的默认样式吗?

C++ 11支持新的函数语法:

auto func_name(int x, int y) -> int;
Run Code Online (Sandbox Code Playgroud)

目前此函数将声明为:

int func_name(int x, int y);
Run Code Online (Sandbox Code Playgroud)

新风格似乎还没有被广泛采用(比如在gcc stl中)

但是,这种新风格是否应该在新的C++ 11程序中随处可见,还是仅在需要时使用?

就个人而言,我更喜欢旧款式,但是混合风格的代码库看起来很丑陋.

c++ auto c++11 trailing-return-type

80
推荐指数
4
解决办法
2万
查看次数

auto,decltype(auto)和尾随返回类型

是否有区别:

template <class T>
constexpr decltype(auto) f(T&& x) -> decltype(std::get<0>(std::forward<T>(x)))
{
    return std::get<0>(std::forward<T>(x));
}
Run Code Online (Sandbox Code Playgroud)

和:

template <class T>
constexpr auto f(T&& x) -> decltype(std::get<0>(std::forward<T>(x)))
{
    return std::get<0>(std::forward<T>(x));
}
Run Code Online (Sandbox Code Playgroud)

如果是的话,它是什么,我应该使用哪一个来完美转发?

c++ decltype auto trailing-return-type c++14

3
推荐指数
1
解决办法
1004
查看次数

标签 统计

auto ×2

c++ ×2

trailing-return-type ×2

c++11 ×1

c++14 ×1

decltype ×1