| Home | Libraries | People | FAQ | More

## Macro BOOST_TYPE_INDEX_REGISTER_RUNTIME_CLASS

BOOST_TYPE_INDEX_REGISTER_RUNTIME_CLASS — Macro used to make a class compatible with boost::typeindex::runtime_cast.

## Synopsis

    // In header: <boost/type_index/runtime_cast/register_runtime_class.hpp>

    BOOST_TYPE_INDEX_REGISTER_RUNTIME_CLASS(base_class_seq)

## Description

BOOST_TYPE_INDEX_REGISTER_RUNTIME_CLASS generates a virtual function in the current class that, when combined with the supplied base class information, allows boost::typeindex::runtime_cast to accurately convert between dynamic types of instances of the current class.

BOOST_TYPE_INDEX_REGISTER_RUNTIME_CLASS also adds support for boost::typeindex::type_id_runtime by including BOOST_TYPE_INDEX_REGISTER_CLASS. It is typical that these features are used together, but in the event that BOOST_TYPE_INDEX_REGISTER_CLASS is undesirable in the current class, BOOST_TYPE_INDEX_IMPLEMENT_RUNTIME_CAST is provided.

Example:

    struct base1 {
        BOOST_TYPE_INDEX_REGISTER_RUNTIME_CLASS(BOOST_TYPE_INDEX_NO_BASE_CLASS)
        virtual ~base1();
    };

    struct base2 {
        BOOST_TYPE_INDEX_REGISTER_RUNTIME_CLASS(BOOST_TYPE_INDEX_NO_BASE_CLASS)
        virtual ~base2();
    };

    struct derived1 : base1 {
        BOOST_TYPE_INDEX_REGISTER_RUNTIME_CLASS((base1))
    };

    struct derived2 : base1, base2 {
        BOOST_TYPE_INDEX_REGISTER_RUNTIME_CLASS((base1)(base2))
    };

    ...

    base1* pb1 = get_object();
    if(derived2* pb2 = boost::typeindex::runtime_cast<derived2*>(pb1)) {
        assert(boost::typeindex::type_id_runtime(*pb1)) == boost::typeindex::type_id<derived2>());
    }

Parameters:

`base_class_seq` | A Boost.Preprocessor sequence of the current class' direct bases, or BOOST_TYPE_INDEX_NO_BASE_CLASS if this class has no direct base classes.