Your problem is that the T&&
template magic only works for type parameters (it works by deducing T
as eg. int&
if needed - for lvalue arguments). It can't work for template template arguments, where the actual type is X<T>&&
- X
must be a class template in this case, not something like "reference-to-class-template". So in the end you have to pass a rvalue-reference, which you cannot implicitly get from a lvalue (variable).
That said, I would suggest you to revert to your earlier code and check that the value_type
s are the same (or compatible, etc., whatever gets you going) with SFINAE.
Rough code sketch (for strict equality):
template <class ... Ts> struct all_types_equal
{
static const bool value = false;
};
template <class T>
struct all_types_equal<T>
{
static const bool value = true;
};
template <class T, class ... Rest>
struct all_types_equal<T, T, Rest...>
{
static const bool value = all_types_equal<T, Rest...>::value;
};
template<typename... Iterables>
auto chain(Iterables&&... iters)
-> typename std::enable_if<all_types_equal<Iterable::value_type...>::value, ChainObject<Iterables...> >::type