开发者

Why are numeric_limit<T>::min/max not a constants? [duplicate]

开发者 https://www.devze.com 2023-03-05 22:10 出处:网络
This question already has an answer here: Closed 11 years ago. Possible Duplicate: Why is std::numeric_limits<T>::max() a function?
This question already has an answer here: Closed 11 years ago.

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

0

精彩评论

暂无评论...
验证码 换一张
取 消