I have got a template method with two specialized versions for type bool and vector<string>.
Base version:
template <class T>
const T InternGetValue(const std::string& pfad) const
{
...
}
Specialized versions:
template <>
const bool InternGetValue(const std::string& pfad) const
{
...
}
template <>
const std::vector<std::string> InternGetValue< std::vector<std::string>>(const std::string& pfad) const
{
...
}
Now I would like to implement one specialization that will accept all types of vector<aritmethic_data_type> like vector<double> vector<int> or vector<float>.
I could achieve this by writing overloads for the above types, but I'm interested in reaching my goal with another specialization.
This is what I tried so far (leads to error 'illegal use of explicit template arguments'):
template <class T>
const std::vector<T> InternGetValue< std::vector<T>>(const std::string& pfad, typename boost::enable_if<boost::is_arithmetic<T>>::type* dummy = 0) const
{
}
I think std::enable_if and std::is_integral together can solve this problem:
template<typename T>
std::vector<typename std::enable_if<std::is_integral<T>::value, T>::type>
f(const std::string& d);
If std:: doesn't have them, then use boost:: if you can. It has them.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With