forked from 0voice/cpp_new_features
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path010_concepts_derived_from.cpp
More file actions
21 lines (16 loc) · 929 Bytes
/
010_concepts_derived_from.cpp
File metadata and controls
21 lines (16 loc) · 929 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <concepts>
class A {};
class B: public A {};
class C: private A{};
int main() {
// std::derived_from == true only for public inheritance or exact same class
static_assert( std::derived_from<B, B> == true ); // same class: true
static_assert( std::derived_from<int, int> == false ); // same primitive type: false
static_assert( std::derived_from<B, A> == true ); // public inheritance: true
static_assert( std::derived_from<C, A> == false ); // private inheritance: false
// std::is_base_of == true also for private inheritance
static_assert( std::is_base_of_v<B, B> == true ); // same class: true
static_assert( std::is_base_of_v<int, int> == false ); // same primitive type: false
static_assert( std::is_base_of_v<A, B> == true ); // public inheritance: true
static_assert( std::is_base_of_v<A, C> == true ); // private inheritance: true
}