I played with the parameters of the variation template 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 surprise, the following “normal” version, which has only one “Argument Type”, does not 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 an error, as in the comment.
Does anyone know why this is causing the error and how to make it work? Also, am I right in thinking that the above code is a form of "partial template specialization"?
source
share