Search code examples
c++templatesrangemax

Template way of finding maximum allowable value


Possible Duplicate:
C++ variable types limits

I have a defined type that may not stay at what it is. I want to make use of the maximum value for that type as an undefined value but don't want to use something like, INT_MAX because I might later change the type to a long or something else entirely. I've seen a template way of doing this but now cannot find it. How in a tempated safe way can i find the maximum allowable value for a type?


Solution

  • Use:

    std::numeric_limits<T>::max()
    

    It's in the header <limits>. See here:

    https://cplusplus.com/reference/limits/numeric_limits/