Skip to content

release mode dynamic_cast in callback.hpp #3

Description

@steve-lorimer
template<typename callback_t, typename ...A>
static typename std::result_of<callback_t(A...)>::type invoke(void* target, int cid, A&& ... args)
{
    auto x = dynamic_cast<internal::callback_object<callback_t>*>(reinterpret_cast<callbacks*>(target)->m_lut[cid].get());
    assert(x);
    return x->invoke(std::forward<A>(args)...);
}

it would be better to use a boost::polymorphic_downcast, or if you don't want the dependency on boost, add a helper function:

template <class Target, class Source>
inline Target polymorphic_downcast(Source* x)
{
    assert(dynamic_cast<Target>(x) == x);
    return static_cast<Target>(x);
}

template<typename callback_t, typename ...A>
static typename std::result_of<callback_t(A...)>::type invoke(void* target, int cid, A&& ... args)
{
    auto x = polymorphic_downcast<internal::callback_object<callback_t>*>(reinterpret_cast<callbacks*>(target)->m_lut[cid].get());
    return x->invoke(std::forward<A>(args)...);
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions