jeudi 31 octobre 2019

Make Templates for basic data types only

How can we make a template accept only basic data types.

template <typename T> 
void GetMaxValue( T& x ) 
{ 
//... Finds max Value
} 

In the above function GetMaxValue we are able to pass any value without any an error.

But the std Function std::numeric_limits<T>::max() has handled it. For example:

auto max = std::numeric_limits< std::map<int,int> >::max();

will Give an error error C2440: '<function-style-cast>' : cannot convert from 'int' to 'std::map<_Kty,_Ty>'

Aucun commentaire:

Enregistrer un commentaire