template template class specialization

89 views Asked by At

I am just learning about Template Template class specialisation. Not a big problem to explain in detail. From my understanding std::uniform_int_distribution is a template whereas std::uniform_int_distribution<Type> is the full specialisation of uniform_int_distribution giving a type. I pass this in the specialisation class template as follows below


Main class

template <template <class> class Distribution,
    class Type,
    class Engine = std::mt19937>
class random_gen
{
    ....
}

specialization of class

template <class Type, class Engine>
class random_gen<std::uniform_real_distribution<Type>, Type, Engine>
{
    ...
}

the error that occurs is:

type/value mismatch at argument 1 in template parameter list for 'template<template<class> class Distribution, class Type, class Engine> class random_gen'
1

There are 1 answers

0
Barry On BEST ANSWER

The specialization still needs to be a template template argument. You passed in a full type. You want:

template <class Type, class Engine>
class random_gen<std::uniform_real_distribution, Type, Engine>
{
    ...
};

Just std::uniform_real_distribution, not std::uniform_distribution<Type>.