cppx-core
is_of_derived_class_.hpp
Go to the documentation of this file.
1 #pragma once // Source encoding: UTF-8 with BOM (π is a lowercase Greek "pi").
3 #include <cppx-core/language/tmp/basic-Enable_if_.hpp> // cppx::Enable_if_
4 #include <cppx-core/language/tmp/basic-type-traits.hpp> // cppx::is_base_and_derived_
5 #include <cppx-core/language/types/Truth.hpp> // cppx::Truth
6 
7 namespace cppx
8 {
9  // `true` if a pure downcast via `dynamic_cast` succeeds.
10  // `false` if the `dynamic cast` fails or gives a cross cast.
11  //
12  // Essentially whether a `static_cast<Derived*>( &o )` would do the Right Thing™.
13 
14  template<
15  class Derived, class Type,
16  class = Enable_if_<is_base_and_derived_<Type, Derived>>
17  >
18  inline auto is_of_derived_class_( const Type& o )
19  -> Truth
20  {
21  const auto p_derived = dynamic_cast<P_<const Derived>>( &o );
22  return static_cast<P_<const Type>>( p_derived ) == &o;
23  }
24 } // namespace cppx
auto is_of_derived_class_(const Type &o) -> Truth
Some_type * P_
Creates a raw pointer type.
A drop-in replacement for bool without implicit conversion from/to types other than bool.
Definition: Truth.hpp:34
is_base_and_derived_, is_same_type_, is_a_, is_const_, is_class_, is_fixed_point_,...
Enable_if_ is just more readable than enable_if_t.
Truth is a drop-in replacement for bool without implicit conversion from/to types other than bool.
Simple type builders Type_, P_, R_, Raw_array_ and Raw_array_of_.