user8953650
user8953650

Reputation: 1020

template class default float parameter

I'm trying to define a class template that depends from a <typename T, const double and std::size_t>. I know that before C++ 14 was impossible declare a default parameter for double type in template but I read somewhere that now it's possible but I don't know how. I tried to indexing the research here and in goolge but I didn't found what I wish accomplish that is:

template <typename Type, double threshold = 0.5 , std::size_t Sz = 64>
class DynBmatrix 
{
   constexpr DynBmatrix(std::vector<std::vector<Type>> ) noexcept ;
}

template<typename T, double TH,std::size_t S>
class DynBmatrix<T,TH,S>
{
    if (something > TH) 
    ...
}

and in the main instance the template as simply

DynBmatrix<int> dbm{} ;

EDIT : solved as folow : thanks @Marco

constexpr double th = 0.5 ;

template <typename Type, const double* TH = &th , std::size_t Sz = 64>

Upvotes: 2

Views: 57

Answers (1)

Marco Ghiani
Marco Ghiani

Reputation: 219

using : const double* TH instead of double TH and define outside the class the constexpr double th = 0.5 ; then you got the same behaviour

Upvotes: 1

Related Questions