Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Template way of finding maximum allowable value [duplicate]

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?

like image 396
Andrew Redd Avatar asked Nov 10 '10 19:11

Andrew Redd


1 Answers

Use:

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

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

http://www.cplusplus.com/reference/std/limits/numeric_limits/

like image 145
Stuart Golodetz Avatar answered Sep 18 '22 07:09

Stuart Golodetz