前提・実現したいこと
map_doubleという関数を使って全ての要素を2倍にしたいのですが、うまくいきません。
c++
1#include <iostream> 2 3using namespace std; 4 5 6template<int head = 0, int... tail> 7class Turing{ 8public: 9 template <int new_head> 10 Turing<new_head, head, tail...> cons(){ 11 return Turing<new_head, head, tail...>(); 12 } 13 14 void print(){ 15 cout << head << " " << endl; 16 if(sizeof...(tail) != 0) Turing<tail...>().print(); 17 } 18 19 auto map_double(){ 20 cout << head << " " << endl; 21 if(sizeof...(tail) != 0){ 22 return Turing<tail...>().map_double().cons<head * 2>(); 23 } 24 return Turing<head * 2>(); 25 } 26}; 27 28int main(){ 29 auto a = Turing<1, 2, 3>().map_double().print(); 30 return 0; 31}
発生している問題・エラーメッセージ
template_test.cpp:22:66: error: expected expression return Turing<tail...>().map_double().cons<head * 2>(); ^ 1 error generated.
補足情報(FW/ツールのバージョンなど)
Apple LLVM version 9.0.0 (clang-900.0.39.2)
Target: x86_64-apple-darwin16.7.0
Thread model: posix
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/04/30 06:27