Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

numeric_limits<>::max()

10 views
Skip to first unread message

Rolf Magnus

unread,
Dec 28, 2009, 6:16:57 AM12/28/09
to
Hello,

I'd like to know why std::numeric_limits<>::max (and some, but not all other
values in numeric_limits) was chosen to be a function instead of just being
a constant. I would have needed it in a template argument, but can't use it
there, because it's not a constant expression.

Naive Group User

unread,
Dec 28, 2009, 8:09:00 AM12/28/09
to

Dear Sir I have a question in atl.html the latest post I made, please
come answer, I need to learn the basic steps in that, I don't need
real life big hard software from corporation for me to join in some
team to create.
I think I begin to fall for web now and possibly long later in the
future.

About your question,
there is probably a '_max' variable that might have been implemented
as a private object for easier, safer and more efficient manipulation
later in the client code, so max is named to be used as a function. Do
you agree to that ?

Victor Bazarov

unread,
Dec 28, 2009, 10:59:05 AM12/28/09
to
Rolf Magnus wrote:
> I'd like to know why std::numeric_limits<>::max (and some, but not all other
> values in numeric_limits) was chosen to be a function instead of just being
> a constant.

You should post to 'comp.std.c++' then. There decisions and the
rationales behind the Standard and any of its parts are discussed. Some
folks *here* might remember how those things (functions) came to be
functions, of course, but 'c.s.c++' is more reliable.

> I would have needed it in a template argument, but can't use it
> there, because it's not a constant expression.

You may need to redesign your classes to accommodate functions there.
If you post your code and describe what you're trying to accomplish,
perhaps somebody could make a suggestion...

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask

Bo Persson

unread,
Dec 28, 2009, 12:41:38 PM12/28/09
to
Victor Bazarov wrote:
> Rolf Magnus wrote:
>> I'd like to know why std::numeric_limits<>::max (and some, but not
>> all other values in numeric_limits) was chosen to be a function
>> instead of just being a constant.
>
> You should post to 'comp.std.c++' then. There decisions and the
> rationales behind the Standard and any of its parts are discussed.
> Some folks *here* might remember how those things (functions) came
> to be functions, of course, but 'c.s.c++' is more reliable.

I believe it was because the floating point values could not be const
static members initialized in the class definition. So it was
considered more consistent to make them all functions. That way, at
least they could be inlined.

>
>> I would have needed it in a template argument, but can't use it
>> there, because it's not a constant expression.

It doesn't help you here, but in C++0x the members of numeric_limits
will be declared constexpr, to make them usable as constant
expressions, even though they remain functions. A new language
feature!


Bo Persson


James Kanze

unread,
Dec 28, 2009, 4:16:12 PM12/28/09
to
On Dec 28, 5:41 pm, "Bo Persson" <b...@gmb.dk> wrote:
> Victor Bazarov wrote:
> > Rolf Magnus wrote:
> >> I'd like to know why std::numeric_limits<>::max (and some,
> >> but not all other values in numeric_limits) was chosen to
> >> be a function instead of just being a constant.

> > You should post to 'comp.std.c++' then. There decisions and
> > the rationales behind the Standard and any of its parts are
> > discussed. Some folks *here* might remember how those
> > things (functions) came to be functions, of course, but
> > 'c.s.c++' is more reliable.

> I believe it was because the floating point values could not
> be const static members initialized in the class definition.
> So it was considered more consistent to make them all
> functions.

They have to all be functions, or none, or you can't very easily
use the value in a template.

--
James Kanze

Michael Tsang

unread,
Jan 3, 2010, 8:39:46 AM1/3/10
to
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Rolf Magnus wrote:

Compile your code as C++0x period.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)

iEYEARECAAYFAktAniIACgkQG6NzcAXitM8XBQCfTyYM4vn+1QqADazIwSPzhXjv
Ls4AnRIbzljlPu4bQOmBMrBwdIY+Bjf7
=cMaJ
-----END PGP SIGNATURE-----

0 new messages