Topic: numeric_limits<> considered template-unfriendly?


Author: Gabriel Dos Reis <gcc@integrable-solutions.net>
Date: Thu, 11 Aug 2005 15:07:11 CST
Raw View
rgetov@gmail.com writes:

| Hi all,
|
| As you know, std::numeric_limits<> defines functions like 'min()',
| 'max()', etc, providing information about the numeric types. Since
| these are functions, though, it is not possible to use the values that
| they return as compile-time constants; that includes other templates'
| arguments.

There is a generally proposal agreed upon that simple functions,
evaluated with constant expression shall yield constant expressions.
The numeric_limits<> embarassment is explicitly listed as part of the
motivations

   http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2003/n1521.pdf

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: rgetov@gmail.com
Date: 30 Jun 2005 22:00:01 GMT
Raw View
Hi all,

As you know, std::numeric_limits<> defines functions like 'min()',
'max()', etc, providing information about the numeric types. Since
these are functions, though, it is not possible to use the values that
they return as compile-time constants; that includes other templates'
arguments.

I know that if I am desperate I can always resort to <climits>, but the
stuff there (macros!) looks so not C++-ish and outdated.

So how about extending std::numeric_limits<> with static constants
which mirror the existing functions -at least for the cases when this
is possible?

BTW I also know that fp types cannot be used as template arguments,
which limits the justification of my proposal to certain extend. But
even this is about to change, no?

Radoslav Getov

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: oleaj@sbcglobal.net (Michael Olea)
Date: Fri, 1 Jul 2005 03:44:41 GMT
Raw View
rgetov@gmail.com wrote:

> Hi all,
>
> As you know, std::numeric_limits<> defines functions like 'min()',
> 'max()', etc, providing information about the numeric types. Since
> these are functions, though, it is not possible to use the values that
> they return as compile-time constants; that includes other templates'
> arguments.
>
> I know that if I am desperate I can always resort to <climits>, but the
> stuff there (macros!) looks so not C++-ish and outdated.
>
> So how about extending std::numeric_limits<> with static constants
> which mirror the existing functions -at least for the cases when this
> is possible?

boost has done exactly that: boost::integer_traits<>

>
> BTW I also know that fp types cannot be used as template arguments,
> which limits the justification of my proposal to certain extend. But
> even this is about to change, no?
>
> Radoslav Getov
>
> --
> [ comp.std.c++ is moderated.  To submit articles, try just posting with ]
> [ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
> [              --- Please see the FAQ before posting. ---               ]
> [ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: kanze@gabi-soft.fr
Date: Fri, 1 Jul 2005 10:47:02 CST
Raw View
rgetov@gmail.com wrote:

> As you know, std::numeric_limits<> defines functions like
> 'min()', 'max()', etc, providing information about the numeric
> types. Since these are functions, though, it is not possible
> to use the values that they return as compile-time constants;
> that includes other templates' arguments.

I believe that there is a proposal to allow "trivial" inline
functions in integral constant expressions.

> I know that if I am desperate I can always resort to
> <climits>, but the stuff there (macros!) looks so not C++-ish
> and outdated.

> So how about extending std::numeric_limits<> with static
> constants which mirror the existing functions -at least for
> the cases when this is possible?

> BTW I also know that fp types cannot be used as template
> arguments, which limits the justification of my proposal to
> certain extend.  But even this is about to change, no?

Maybe, but there is still the problem that max() and min() must
be functions, because for floating point values, the exact
values may depend on some run-time elements.  Although
numeric_limits isn't consistant about this: the same thing is
true for radix and digits.  (IBM mainframes support two floating
point formats: IBM traditional and IEEE.  I don't know whether
they do this using different sets of machine instructions, or a
bit in the process state flag.  In the latter case, radix,
digits and digits10 all depend on the state of this flag.)

--
James Kanze                                           GABI Software
Conseils en informatique orient   e objet/
                   Beratung in objektorientierter Datenverarbeitung
9 place S   mard, 78210 St.-Cyr-l'   cole, France, +33 (0)1 30 23 00 34


---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]