|
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ||||||||||
Defined in header <concepts> | ||
template<class Derived,class Base> concept derived_from= | (since C++20) | |
The conceptderived_from<Derived, Base> is satisfied if and only ifBase is a class type that is eitherDerived or a public and unambiguous base ofDerived, ignoring cv-qualifiers.
Note that this behavior is different tostd::is_base_of whenBase is a private or protected base ofDerived.
#include <concepts> class A{}; class B:public A{}; class C:private A{}; // std::derived_from == true only for public inheritance or exact same classstatic_assert(std::derived_from<B, B>==true);// same class: truestatic_assert(std::derived_from<int,int>==false);// same primitive type: falsestatic_assert(std::derived_from<B, A>==true);// public inheritance: truestatic_assert(std::derived_from<C, A>==false);// private inheritance: false // std::is_base_of == true also for private inheritancestatic_assert(std::is_base_of_v<B, B>==true);// same class: truestatic_assert(std::is_base_of_v<int,int>==false);// same primitive type: falsestatic_assert(std::is_base_of_v<A, B>==true);// public inheritance: truestatic_assert(std::is_base_of_v<A, C>==true);// private inheritance: true int main(){}
derived_from [concept.derived] derived_from [concept.derived] (C++11) | checks if a type is a base of the other type (class template)[edit] |
(C++11)(C++20) | checks if a type can be converted to the other type (class template)[edit] |