numeric_limits<>::max()

R

Rolf Magnus

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.
 
N

Naive Group User

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.

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 ?
 
V

Victor Bazarov

Rolf said:
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
 
B

Bo Persson

Victor said:
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.

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
 
J

James Kanze

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.
 
M

Michael Tsang

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Rolf said:
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.

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-----
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,262
Messages
2,571,056
Members
48,769
Latest member
Clifft

Latest Threads

Top