Minimal example:
template <typename TFunc>    
void func(TFunc f)
{
    //Do something like:
    double x{1}, y{2};
    bool z = f(x) < f(y);    //Do comparison somewhere
}
I would like to add a static_assert to the function that checks that f(x) returns a type where std::less computes. In other words I would like f(x) < f(y) to compile. I am currently doing something like this:
static_assert((decltype(f(0)){} < decltype(f(0)){}) == false, "Function f must return a weakly ordered type.");
But here I assume that the function returns a type that can be default initialized. Is there a better way to check this?
Aucun commentaire:
Enregistrer un commentaire