#include <cstdint> //or <stdint.h>
#include <limits>
std::numeric_limits<std::int32_t>::max();
Note that <cstdint>
is a C++11 header and <stdint.h>
is a C header, included for compatibility with C standard library.
Following code works, since C++11.
#include <iostream>
#include <limits>
#include <cstdint>
struct X
{
static const std::int32_t i = std::numeric_limits<std::int32_t>::max();
};
int main()
{
switch(std::numeric_limits<std::int32_t>::max()) {
case std::numeric_limits<std::int32_t>::max():
std::cout << "this code works thanks to constexpr
";
break;
}
return EXIT_SUCCESS;
}
http://coliru.stacked-crooked.com/a/4a33984ede3f2f7e
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…