Я провожу некоторые эксперименты с вариационными параметрами и столкнулся с проблемой. Я не могу найти решение -в основном я пытаюсь построить дерево с компонентами произвольных типов данных -вот некоторый код:
template <class A, class B>
struct SeqExpression
{
const A & first;
const B & then;
};
template <class A, class B>
SeqExpression<A,B>
make_seq(const A & a, const B & b)
{
return {a,b};
}
template <class A, class B, class...T>
auto
make_seq(const A & first, const B & second, T...rest) -> decltype(make_seq(make_seq(first,second),rest...))
{
return make_seq(make_seq(first,second),rest...);
}
Затем я пытаюсь:
auto x = make_seq("X","Y",'z');
Но GCC (4.7 )говорит мне:
error: template instantiation depth exceeds maximum of 900 (use -ftemplate-depth= to increase the maximum) substituting ‘template<class A, class B, class... T> decltype (make_seq(make_seq(first, second), rest...)) make_seq(const A&, const B&, T...) [with A = SeqExpression<char [2], char [2]>; B = char; T = {}]’
recursively required by substitution of ‘template<class A, class B, class... T> decltype (make_seq(make_seq(first, second), rest...)) make_seq(const A&, const B&, T...) [with A = SeqExpression<char [2], char [2]>; B = char; T = {}]’
required by substitution of ‘template<class A, class B, class... T> decltype (make_seq(make_seq(first, second), rest...)) make_seq(const A&, const B&, T...) [with A = char [2]; B = char [2]; T = {char}]’
Хотя мне кажется, что это должно быть решаемо!
make_seq("X","Y")
имеет тип SeqExpression< char[2],char[2] >
поэтому make_seq(make_seq("X","Y"),'z')
имеет типSeqExpression< SeqExpression< char[2],char[2] >,char >
и мне он кажется относительно не -зацикленным.
есть идеи?