Why are numeric_limit<T>::min/max not a constants? [duplicate]
Possible Duplicate:
Why is std::numeric_limits<T>::max() a function?
I was wondering if someone could explain the reasoning behind why std::numeric_limit<T>::min
and max
are functions and not constants?
Furthermore, I'd like to know what techniques can be used to make use of the min/max values as part of template parameters, eg:
template<unsigned long long max>
class foo
{
public:
void boo() { std::cout << max << std::endl; 开发者_如何转开发}
};
.
.
.
foo<std::numeric_limits<int>::max()> f;
f.boo();
Fall back on good old C!
foo< INT_MAX > f;
or even
const int my_int_max = INTMAX;
foo< my_int_max > f;
Works for me on g++ (Debian 4.4.5-8) 4.4.5
精彩评论