13

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?

Community
  • 1
  • 1
Andrew Redd
  • 4,632
  • 8
  • 40
  • 64

1 Answers1

34

Use:

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

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

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

Steve Jessop
  • 273,490
  • 39
  • 460
  • 699
Stuart Golodetz
  • 20,238
  • 4
  • 51
  • 80