I found myself writing code like this:
template <class T>
inline bool allequal(T a,T b,T c) {return a==b&&a==c;}
template <class T>
inline bool allequal(T a,T b,T c,T d) {return a==b&&a==c&&a==d;}
template <class T>
inline bool allequal(T a,T b,T c,T d,T e) {return a==b&&a==c&&a==d&&a==e;}
I was wondering if there is an automated way of doing that, without using vectors or variadic arguments, as speed is important in this context.
You could try this:
AFAIK there is a proposal for C++17 to include custom expansion of variadic templates with operators that could avoid this kind of recursion and this ugly (IMO) termination with
return true
for one argument.Note: this could possibly not be inlined for many arguments.