If we have a metafocus of a type template std::conditional, we can “select” types based on a logical compilation condition. For instance:
template < bool CONDITION, typename T, typename U >
struct conditional;
template < typename T, typename U >
struct conditional < true, T, U >
{
using type = T;
};
template < typename T, typename U >
struct conditional < false, T, U >
{
using type = U;
};
const bool whats_big = sizeof( int ) > sizeof( double );
using bigger_type = typename conditional<whats_big , int , double>::type;
My question is: Can I choose between a valid type and an invalid type?
Im currently implementing an event class. Events have a sender parameter and a variable number of args events:
template<typename SENDER , typename... ARGS>
class event;
Thus, functions with a type void(SENDER& , ARGS&...)can be used as event handlers. In this case, the handlers are called by passing a reference to the object that raised the event (sets the sender parameter).
On the other hand, I want the sender member functions to be event handlers, in other words, type functions void(SENDER::*)(ARGS&...).
, :
using handler_type = typename conditional<std::is_class<SENDER>::value,void(SENDER::*)(ARGS&...) , void(SENDER& , ARGS&...)>::type;
, SENDER , ( ).