You can try the following:
#include <iostream>
template< typename T >
inline bool allequal( const T& v )
{
return true;
}
template< typename T, typename U, typename... Ts >
inline bool allequal( const T& v, const U& v1, const Ts&... Vs)
{
return (v == v1) && allequal( v1, Vs... );
}
int main()
{
std::cout << std::boolalpha;
std::cout << allequal(1, 1, 1, 1) << std::endl;
std::cout << allequal(1, 1, 2, 2) << std::endl;
return 0;
}
AFAIK offers a proposal for C ++ 17 to include an arbitrary extension of variational patterns with operators that could avoid this kind of recursion and this ugly (IMO) termination with a return truesingle argument.
Note: for many arguments this may not be inlined.
tsuki source
share