I was playing with variadic template parameters using gcc 4.6.1. The following code compiles as expected:
template<typename RetType, typename... ArgTypes>
class Event;
template<typename RetType, typename... ArgTypes>
class Event<RetType(ArgTypes...)>
{
public:
typedef function<RetType(ArgTypes...)> CallbackType;
void emit(ArgTypes...args)
{
for (CallbackType callback : callbacks)
{
callback(args...);
}
}
private:
vector<CallbackType> callbacks;
};
But to my suprise the following “normal” version that has only one “Argument Type” doesn’t compile:
template<typename RetType, typename ArgType>
class Event;
template<typename RetType, typename ArgType>
class Event<RetType(ArgType)> // <- error: wrong number of template arguments (1, should be 2)
{};
g++ 4.6.1 gives error as in the comment.
Anybody knows why it causes the error and how to make it work? Also, am I right in thinking the above code is a form of “template partial specialisation”?
Expects 2 template arguments,
RetTypeandArgType, you only give it oneRetType(ArgType).Expects 1 or more template arguments,
RetTypeand optionalArgTypes.