I am looking for a way to check that arguments are sorted using a c++ fold expression. The naive approach:
template <typename... Args>
bool are_strictly_increasing(Args const&... args) {
return (args < ...);
}
Does not work as it expands to ((arg0 < arg1) < arg2) < ...
which ends up comparing bool to whatever the typename Args is (that can be treacherous when using e.g. int as it compiles unless you crank up warning levels).
The trick to single out the first argument in the list works for checking all elements are equal:
template <typename Arg, typename... Args>
bool are_all_equal(Arg const& arg0, Args const&... args) {
return ((arg0 == args) && ... );
}
but it won't work here for operator< since it would only test whether all arguments are greater than the first one.