I am experimenting with variators, and I came across a problem, I can’t understand the solution - basically I try to build a tree with components of arbitrary data types - here is some code:
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...);
}
Then I try:
auto x = make_seq("X","Y",'z');
But GCC (4.7) tells me:
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}]’
It seems to me that it should be solvable!
make_seq("X","Y")has type SeqExpression< char[2],char[2] >
therefore make_seq(make_seq("X","Y"),'z')has typeSeqExpression< SeqExpression< char[2],char[2] >,char >
and for me it looks relatively non-loopback.
Any thoughts?