2
decltype(auto)有什么用?
Наэтотвопросестьответына 堆栈溢出нарусском:Конструкцияdecltype(自动) 在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)]; } 还有其他使用此新语言功能的示例吗?