6 #ifndef RANGES_V3_UTILITY_POLYMORPHIC_CAST_HPP
7 #define RANGES_V3_UTILITY_POLYMORPHIC_CAST_HPP
10 #include <type_traits>
14 #include <range/v3/detail/config.hpp>
16 #include <range/v3/detail/prologue.hpp>
20 template<
typename Target,
typename Source>
21 auto polymorphic_downcast(Source * x) noexcept
23 decltype((
static_cast<Target
>(x),
dynamic_cast<Target
>(x)))>
25 auto result =
static_cast<Target
>(x);
26 RANGES_ASSERT(
dynamic_cast<Target
>(x) == result);
29 template<
typename Target,
typename Source>
30 auto polymorphic_downcast(Source && x) noexcept
32 decltype((
static_cast<Target
>(std::declval<Source>()),
33 dynamic_cast<Target
>(std::declval<Source>())))>
35 auto && result =
static_cast<Target
>(
static_cast<Source &&
>(x));
37 auto && dresult =
dynamic_cast<Target
>(
static_cast<Source &&
>(x));
38 RANGES_ASSERT(std::addressof(dresult) == std::addressof(result));
40 return static_cast<Target
>(result);
44 #include <range/v3/detail/epilogue.hpp>
_t< detail::_if_< list< Args... > >> if_
Select one type or another depending on a compile-time Boolean.
Definition: meta.hpp:1247