mercredi 25 novembre 2015

Accessing the highest and lowest values that can be represented in numeric type T, a template parameter

This should work, I think

template<typename T>
class MyClass {
    // ...
    static constexpr T minT = std::numeric_limits<T>::has_infinity
                            ? -std::numeric_limits<T>::infinity() 
                            : std::numeric_limits<T>::lowest();
    static constexpr T maxT = std::numeric_limits<T>::has_infinity 
                            ? std::numeric_limits<T>::infinity() 
                            : std::numeric_limits<T>::max();
}

but I was wondering whether I am missing a simpler way.

Aucun commentaire:

Enregistrer un commentaire