operator==
requires the tuples to be of equal lengths.
§ 20.4.2.7 [tuple.rel]:
template<class... TTypes, class... UTypes>
constexpr bool operator==(const tuple<TTypes...>& t, const tuple<UTypes...>& u);
1 Requires: For all i
, where 0 <= i
and i < sizeof...(TTypes)
, get<i>(t) == get<i>(u)
is a valid expression returning a type that is convertible to bool
. sizeof...(TTypes) == sizeof...(UTypes)
.
If you want two tuples of different lengths to be considered unequal, you'd need to implement this logic yourself:
template <typename... Ts, typename... Us>
auto compare(const std::tuple<Ts...>& t1, const std::tuple<Us...>& t2)
-> typename std::enable_if<sizeof...(Ts) == sizeof...(Us), bool>::type
{
return t1 == t2;
}
template <typename... Ts, typename... Us>
auto compare(const std::tuple<Ts...>& t1, const std::tuple<Us...>& t2)
-> typename std::enable_if<sizeof...(Ts) != sizeof...(Us), bool>::type
{
return false;
}
DEMO
This way, the code comparing two tuples, t1 == t2
, is instantiated only when the lengths of tuples match each other. In your scenario, a compiler is unable to compile your code, since there is no predefined operator==
for such a case.