Tech Off Post

Single Post Permalink

View Thread: C++0x (vs2010) question, please tell me what i'm doing wrong
  • User profile image

    I posted this link on last Advanced STL show:

    here an except of the code (how to register a function to call)

    template <typename TEvent, typename TListener >
    void _registerListener (const TListener& function) {
    static_assert(!std::is_array<TEvent>::value, "You cannot register an array as an event type");
    static_assert(std::is_convertible<TListener,std::function<void(TEvent&)>>::value, "Unvalid callback for this event type");
    _listeners.insert(std::make_pair(&typeid(std::decay<TEvent>::type), [=](void* ev) { function(*static_cast<TEvent*>(ev)); }));

    is_convertible and decay seens what you are looking for deal with functors, function and lambdas. There are other interesting stuff on the blog. (I think I see an example with std::bind for additional "magic"call somewhere, I'll try re-digg it)