// (C) Copyright Kevlin Henney and Dave Abrahams 1999. // Distributed under the Boost // Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) #ifndef RANGES_V3_UTILITY_POLYMORPHIC_CAST_HPP #define RANGES_V3_UTILITY_POLYMORPHIC_CAST_HPP #include #include #include #include namespace ranges { template auto polymorphic_downcast(Source * x) noexcept -> meta::if_, decltype((static_cast(x), dynamic_cast(x)))> { auto result = static_cast(x); RANGES_ASSERT(dynamic_cast(x) == result); return result; } template auto polymorphic_downcast(Source && x) noexcept -> meta::if_, decltype((static_cast(std::declval()), dynamic_cast(std::declval())))> { auto && result = static_cast(static_cast(x)); #ifndef NDEBUG auto && dresult = dynamic_cast(static_cast(x)); RANGES_ASSERT(std::addressof(dresult) == std::addressof(result)); #endif return static_cast(result); } } // namespace ranges #endif // RANGES_V3_UTILITY_POLYMORPHIC_CAST_HPP