QLib::Event委托库下载 http://upload.programfan.com/upfile/200548160qevent.rar
QLib::Event委托库支持0-9参数的任意委托声明。
QLib::Event<void> ev0;
QLib::Event<int,int> ev1;
QLib::Event<int,int,int> ev2;
实现核心为TypeLength - 推导实际输入的参数个数。
struct NullType;
template <typename T1 = NullType, typename T2 = NullType, typename T3 = NullType, typename T4 = NullType, typename T5 = NullType, typename T6 = NullType, typename T7 = NullType, typename T8 = NullType, typename T9 = NullType>
struct Length
{
template <typename T1 = NullType>
struct Len
{
enum{value = 1};
};
template<>
struct Len<NullType>
{
enum {value = 0};
};
enum enum_len {value = Len<T1>::value + Len<T2>::value+Len<T3>::value+Len<T4>::value+Len<T5>::value+Len<T6>::value+Len<T7>::value+Len<T8>::value+Len<T9>::value};
};
利用Length::value可以得到实际输入的参数个数,例如
Length<void>::value为1;
Length<void,int,int>::value为3.