# std::derived_from

> C++ Atlas: `cppatlas.com/w/cpp/concepts/derived_from` | Source: https://en.cppreference.com/w/cpp/concepts/derived_from | Domain: Concepts | Standards: C++11, C++20

The concept derived_from<Derived, Base> is satisfied if and only if Base is a class type that is either Derived or a public and unambiguous base of Derived, ignoring cv-qualifiers.

## Official Specification Summary (cppreference)

```cpp
// Defined in header <concepts>

template< class Derived, class Base >
concept derived_from =
    std::is_base_of_v<Base, Derived> &&
    std::is_convertible_v<const volatile Derived*, const volatile Base*>; // (since C++20)
```

The concept `derived_from<Derived, Base>` is satisfied if and only if `Base` is a class type that is either `Derived` or a public and unambiguous base of `Derived`, ignoring cv-qualifiers.

Note that this behavior is different to `std::is_base_of` when `Base` is a private or protected base of `Derived`.

### Example

```cpp
#include <concepts>

class A {};

class B : public A {};

class C : private A {};

// 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

int main() {}
```

### References

- C++23 standard (ISO/IEC 14882:2024):

  - 18.4.3 Concept `derived_from` [concept.derived]

- C++20 standard (ISO/IEC 14882:2020):

  - 18.4.3 Concept `derived_from` [concept.derived]

### See also

- [`is_base_of`](https://en.cppreference.com/w/cpp/types/is_base_of) (C++11): checks if a type is a base of the other type (class template)
- [`is_convertible`](https://en.cppreference.com/w/cpp/types/is_convertible) (C++11), [`is_nothrow_convertible`](https://en.cppreference.com/w/cpp/types/is_convertible) (C++20): checks if a type can be converted to the other type (class template)

---
Attribution: content from https://en.cppreference.com/w/cpp/concepts/derived_from (cppreference.com), licensed under CC-BY-SA 3.0 and GFDL. Modified: converted to markdown, study notes added. Offline snapshot of 9 February 2025.