相关疑难解决方法(0)

decltype(auto)有哪些用途?

在c ++ 14 decltype(auto)中引入了成语.

通常,它的用途是允许auto声明使用decltype给定表达式的规则.

搜索成语的"好"用法示例我只能想到以下内容(由Scott Meyers提供),即函数的返回类型推导:

template<typename ContainerType, typename IndexType>                // C++14
decltype(auto) grab(ContainerType&& container, IndexType&& index)
{
  authenticateUser();
  return std::forward<ContainerType>(container)[std::forward<IndexType>(index)];
}
Run Code Online (Sandbox Code Playgroud)

这个新语言功能有用吗?

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

133
推荐指数
2
解决办法
5万
查看次数

标签 统计

auto ×1

c++ ×1

c++14 ×1

decltype ×1

return-type-deduction ×1