mercredi 25 mars 2015

template looping through tuple

I'm playing with variadic templates and I'm currently trying to implement operator<< for tuple.


I've tried the following code but it doesn't compile (GCC 4.9 with -std=c++11).



template<int I, typename ... Tlist>
void print(ostream& s, tuple<Tlist...>& t)
{
s << get<I>(t) << ", ";
if(I < sizeof...(Tlist)){
print<I+1>(s,t);
}
}
template<typename ... Tlist>
ostream& operator<<(ostream& s, tuple<Tlist...> t)
{
print<0>(s,t);
return s;
}


The error message is very cryptic and long, but it basically says that there is no matching function call for get. Can someone explain to me why? Thanks.


EDIT: Here is the template instantiation I'm using



auto t = make_tuple(5,6,true,"aaa");
cout << t << endl;

Aucun commentaire:

Enregistrer un commentaire