std::tuple<...>::operator!= returns true if at least one member of the two compared tuples is different.
I will need a function that will return true if all the members of the two compared tuples are different:
template <class... Args> bool areAllMembersDifferent( const std::tuple<Args...>& left, const std::tuple<Args...>& right ) { bool allDiff = true;
Inspired by what I found on the Internet, I wrote this (adapted a function that printed the contents of a tuple):
template <std::size_t N, std::size_t, class = make_index_sequence<N>> struct CheckTupleLoop; template <std::size_t N, std::size_t J, std::size_t... Is> struct CheckTupleLoop<N, J, index_sequence<Is...>> { template <class Tup> int operator()(bool& allDiff, const Tup &left,const Tup &right) { if ( std::get<J>(left) == std::get<J>(right) ) allDiff = false; return 0; } }; template <class... Args> bool areAllMembersDifferent( const std::tuple<Args...>& left, const std::tuple<Args...>& right ) { bool allDiff = true; CheckTupleLoop<sizeof...(Args)>{}(allDiff,left,right); return allDiff; }
But this is obviously not true, since the compiler tells me Error C2955 'CheckTupleLoop': use of class template requires template argument list
Any implementation of bool areAllMembersDifferent in C ++ 11 would be acceptable (using or not my first attempt).
c ++ c ++ 11 tuples stdtuple
jpo38
source share