2
decltype(auto)の用途は何ですか?
OverаэтотвопросестьответынаStack Overflowнарусском:Конструкция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)]; } この新しい言語機能が役立つ他の例はありますか?