Why has numeric_limits a standard implementation?

S

Stuart Redmann

Hello newsgroup,

just out of curiosity I had a look at the implementation of <limits> (in
hope of not being OT, I use MS VC 6.0). For those who don't have it, I
feel free to cite it here:

(the following lines are from VC98/include/limits)
template<class _Ty> class numeric_limits : public _Num_base {
public:
static _Ty (__cdecl min)() _THROW0()
{return (_Ty(0)); }
static _Ty (__cdecl max)() _THROW0()
{return (_Ty(0)); }
static _Ty __cdecl epsilon() _THROW0()
{return (_Ty(0)); }
static _Ty __cdecl round_error() _THROW0()
{return (_Ty(0)); }
static _Ty __cdecl denorm_min() _THROW0()
{return (_Ty(0)); }
static _Ty __cdecl infinity() _THROW0()
{return (_Ty(0)); }
static _Ty __cdecl quiet_NaN() _THROW0()
{return (_Ty(0)); }
static _Ty __cdecl signaling_NaN() _THROW0()
{return (_Ty(0)); }
};

As you can see, this template class gives us a kind of standard
implementation of the methods. Note also, that this standard
implementation is pretty useless.

My question is: Is there a good reason why numeric_limits should be
implemented this way? Wouldn't it be more reasonable to leave these
methods out of the template definition? As I see it, only
specializations of this template are actually used, so even deriving the
template numeric_limits from _Num_base is quite useless (the
specializations of this template aren't forced to derive from _Num_base
this way, are they?)

Thanks,
Stuart
 
P

P.J. Plauger

Stuart Redmann said:
Hello newsgroup,
just out of curiosity I had a look at the implementation of <limits> (in
hope of not being OT, I use MS VC 6.0). For those who don't have it, I
feel free to cite it here:

(the following lines are from VC98/include/limits)
template<class _Ty> class numeric_limits : public _Num_base {
public:
static _Ty (__cdecl min)() _THROW0()
{return (_Ty(0)); }
static _Ty (__cdecl max)() _THROW0()
{return (_Ty(0)); }
static _Ty __cdecl epsilon() _THROW0()
{return (_Ty(0)); }
static _Ty __cdecl round_error() _THROW0()
{return (_Ty(0)); }
static _Ty __cdecl denorm_min() _THROW0()
{return (_Ty(0)); }
static _Ty __cdecl infinity() _THROW0()
{return (_Ty(0)); }
static _Ty __cdecl quiet_NaN() _THROW0()
{return (_Ty(0)); }
static _Ty __cdecl signaling_NaN() _THROW0()
{return (_Ty(0)); }
};

As you can see, this template class gives us a kind of standard
implementation of the methods. Note also, that this standard
implementation is pretty useless.

My question is: Is there a good reason why numeric_limits should be
implemented this way? Wouldn't it be more reasonable to leave these
methods out of the template definition? As I see it, only specializations
of this template are actually used, so even deriving the template
numeric_limits from _Num_base is quite useless (the specializations of
this template aren't forced to derive from _Num_base this way, are they?)

It's that way because the C++ Standard says it's supposed to be that way.

P.J. Plauger
Dinkumware, Ltd.
http://www.dinkumware.com
 

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

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,260
Latest member
kentcasinohelpWilhemina

Latest Threads

Top