autoとdecltypeを用いて以下のプログラムを書いたところ、
C++
1#include <iostream> 2 3template <typename T, typename... R> 4T head(T value, R... Rest){ 5 return value; 6} 7 8template <typename... T> 9auto Func(const T... Args) -> decltype(head(Args...)){ 10 return head(Args...); 11} 12 13int main(){ 14 std::cout << Func(1, 2, 3) << std::endl; 15}
以下のエラーが出力されてしまい、コンパイルが通りませんでした。
error: 'auto' not allowed in function return type auto Func(const T... Args) -> decltype(head(Args...)){ ^~~~ error: cannot use arrow operator on a type auto Func(const T... Args) -> decltype(head(Args...)){
C++11のautoを関数の戻り値に使ってはいけないルールが適用されてしまっているようなのですが、どのようにすればコンパイルが通るのでしょうか。もしくは書き方に誤りがあるのでしょうか。
コンパイルはOSX 10.11 El Capitan、XCode 8.0と以下の環境を用いています。
$ g++ -v Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1 Apple LLVM version 8.0.0 (clang-800.0.38) Target: x86_64-apple-darwin15.6.0 Thread model: posix InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
回答宜しくお願いします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2016/10/26 01:26