C++20: concept definition parameters seems inverted

Hi,

This next concept:

1
2
template <class T, class U>
concept SubClass = std::is_base_of<U, T>::value;


used in this context:

1
2
template<SubClass<ABase> X>
void f(X);  // X is constrained by SubClass<X, ABase> 



seems inverted to me: the first template argument to SubClass should correspond to the template parameter T in which case X is constrained by SubClass<ABase,X>.
in other words by std::is_base_of<X, ABase>::value
yet the 1ste argument to is_base_of is supposed to be the base class, the second the derived class

see my point?

Last edited on
Looks like that "SubClass" was someone's version of the standard library concept std::derived_from https://en.cppreference.com/w/cpp/concepts/derived_from

in any case, it works here as intended.

The syntax template<SubClass<ABase> X> is short for template<class X> requires SubClass<X, ABase>
you can find that on cppreference https://en.cppreference.com/w/cpp/language/template_parameters#Type_template_parameter - it even has an example
template<C3<int> T> struct s4; // constraint-expression is C3<T, int>
Last edited on
Topic archived. No new replies allowed.