Function downcast

Summary

#include <include/type_safe/downcast.hpp>

(1) template <typename Derived, typename Base>
    Derived downcast(Base &obj) noexcept

(2) template <typename Derived, typename Base>
    Derived & downcast(derived_type< Derived >, Base &obj) noexcept

(3) template <typename Derived, typename Base>
    const Derived & downcast(derived_type< Derived >, const Base &obj) noexcept

Function overload

Synopsis

#include <include/type_safe/downcast.hpp>

template <typename Derived, typename Base>
Derived downcast(Base &obj) noexcept

Description

Casts an object of base class type to the derived class type.

Returns
The object converted as if static_cast<Derived>(obj). \requires Base must be a base class of Derived, and the dynamic type of obj must be Derived.

Mentioned in

Source

Lines 66-71 in include/type_safe/downcast.hpp.

template <typename Derived, typename Base>
Derived downcast(Base& obj) noexcept
{
    detail::validate_downcast<Derived>(obj);
    return static_cast<Derived>(obj);
}

Synopsis

#include <include/type_safe/downcast.hpp>

template <typename Derived, typename Base>
Derived & downcast(derived_type< Derived >, Base &obj) noexcept

Description

Casts an object of base class type to the derived class type.

Returns
The object converted as if static_cast<derived_ref>(obj), where derived_ref is the type of Derived with matching qualifiers. \requires Base must be a base class of Derived, and the dynamic type of obj must be Derived. \group downcast_tag

Mentioned in

Source

Lines 79-84 in include/type_safe/downcast.hpp.

template <typename Derived, typename Base>
Derived& downcast(derived_type<Derived>, Base& obj) noexcept
{
    detail::validate_downcast<Derived>(obj);
    return static_cast<Derived&>(obj);
}

Synopsis

#include <include/type_safe/downcast.hpp>

template <typename Derived, typename Base>
const Derived & downcast(derived_type< Derived >, const Base &obj) noexcept

Description

\group downcast_tag

Mentioned in

Source

Lines 87-92 in include/type_safe/downcast.hpp.

template <typename Derived, typename Base>
const Derived& downcast(derived_type<Derived>, const Base& obj) noexcept
{
    detail::validate_downcast<Derived>(obj);
    return static_cast<const Derived&>(obj);
}





Add Discussion as Guest

Log in