Topic: Recomended template recursion limit is too small?
Author: Valentin Bonnard <bonnardv@pratique.fr>
Date: 1998/10/28 Raw View
Vlad Harchev <vladhar@imimail.ssau.ru> writes:
> CD2 recomends 17 (in some annex) as the value of template recursion
> limit. IMO the suggested value should be much bigger
> (about 1000).
These limits are just hints, not minimum nor maximum (the
implementation can support even less).
But I would agree with you.
FWIW, the EDG compiler has a limit which can be set as high as
you want (with a command line switch).
--
Valentin Bonnard mailto:bonnardv@pratique.fr
info about C++/a propos du C++: http://pages.pratique.fr/~bonnardv/
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: Jason Merrill <jason@cygnus.com>
Date: 1998/10/29 Raw View
>>>>> Valentin Bonnard <bonnardv@pratique.fr> writes:
> Vlad Harchev <vladhar@imimail.ssau.ru> writes:
>> CD2 recomends 17 (in some annex) as the value of template recursion
>> limit. IMO the suggested value should be much bigger
>> (about 1000).
> FWIW, the EDG compiler has a limit which can be set as high as
> you want (with a command line switch).
As does g++.
Jason
---
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: "Vlad Harchev" <vladhar@imimail.ssau.ru>
Date: 1998/10/22 Raw View
CD2 recomends 17 (in some annex) as the value of template recursion
limit. IMO the suggested value should be much bigger
(about 1000). I think that the present value is too small because it
prevents some template-oriented tricks mostly oriented for numeric theory.
Here is one of them:
The GCD (greatest common divisor) algorithm can be implemented as template
with 2 non-type template parameters. According to D. Knuth the number of
divisions for this algorithms is something like this:
N = 0.86 log2(n) + C.
where 'n' is the number of bits in either of values. For 32-it numbers
the N will exceed 17. We should consider the growing of the
word sizes in the future.
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: Barry Margolin <barmar@bbnplanet.com>
Date: 1998/10/22 Raw View
In article <362fb0c8.0@monster.ssau.ru>,
Vlad Harchev <vladhar@imimail.ssau.ru> wrote:
> The GCD (greatest common divisor) algorithm can be implemented as template
>with 2 non-type template parameters. According to D. Knuth the number of
>divisions for this algorithms is something like this:
> N = 0.86 log2(n) + C.
> where 'n' is the number of bits in either of values. For 32-it numbers
>the N will exceed 17. We should consider the growing of the
>word sizes in the future.
How often do you use GCD when both parameters are known at compile time? A
template can't be expanded unless the parameters are constant expressions.
How big is C? Even for 128-bit numbers, log2(n) is only 8, so N will only
exceed 17 if C > 10.
--
Barry Margolin, barmar@bbnplanet.com
GTE Internetworking, Powered by BBN, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: sbnaran@localhost.localdomain (Siemel Naran)
Date: 1998/10/23 Raw View
On 22 Oct 1998 16:06:24 GMT, Vlad Harchev <vladhar@imimail.ssau.ru> wrote:
> The GCD (greatest common divisor) algorithm can be implemented as template
>with 2 non-type template parameters. According to D. Knuth the number of
>divisions for this algorithms is something like this:
> N = 0.86 log2(n) + C.
Why not implement gcd as an inline func? A good optimizing compiler
should evaluate gcd(constant,constant) at compile time anyway, so
there is no run time overhead. To help the compiler do this, make
the func gcd(int,int) inline. However, this compile time constant
is not an integral constant, and cannot be used as the argument of
a builtin array or a template. Most importantly, we can now find
the gcd of numbers known only at run time.
> where 'n' is the number of bits in either of values. For 32-it numbers
>the N will exceed 17. We should consider the growing of the
>word sizes in the future.
Still a good idea in general. How about this? Introduce the concept
of an empty struct: if the struct has no member data and no member
functions, it is an empty struct. Now, the concept of a very-empty
struct: it is empty and has no typedefs, no non-const static data, and
no static functions. This struct then has only static const data and
enums. For very-empty template structs, template recursion should be
infinite. This idea just forces the struct to be evaluated like an
inline function at compile time.
--
----------------------------------
Siemel B. Naran (sbnaran@uiuc.edu)
----------------------------------
---
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: Pete Becker <petebecker@acm.org>
Date: 1998/10/23 Raw View
Vlad Harchev wrote:
>
> CD2 recomends 17 (in some annex) as the value of template recursion
> limit. IMO the suggested value should be much bigger
> (about 1000). I think that the present value is too small because it
> prevents some template-oriented tricks mostly oriented for numeric theory.
> Here is one of them:
> The GCD (greatest common divisor) algorithm can be implemented as template
> with 2 non-type template parameters. According to D. Knuth the number of
> divisions for this algorithms is something like this:
> N = 0.86 log2(n) + C.
> where 'n' is the number of bits in either of values. For 32-it numbers
> the N will exceed 17. We should consider the growing of the
> word sizes in the future.
I agree that the current limit interferes with or prevents this sort of
thing. Why is that bad? <g>
--
Pete Becker
Dinkumware, Ltd.
http://www.dinkumware.com
---
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: ncm@nospam.cantrip.org (Nathan Myers)
Date: 1998/10/23 Raw View
Vlad Harchev<vladhar@imimail.ssau.ru> wrote:
>
> CD2 recomends 17 (in some annex) as the value of template recursion
>limit. IMO the suggested value should be much bigger ...
I agree. People interested in modern template techniques should
encourage their National Body representatives to the ISO to
enter a Defect Report about this. If more than one national body
demands it there is a better chance of fixing it.
Until it is fixed, you must use a compiler that exceeds the minimum
requirement.
--
Nathan Myers
ncm@nospam.cantrip.org http://www.cantrip.org/
---
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: "Vlad Harchev" <vladhar@imimail.ssau.ru>
Date: 1998/10/23 Raw View
Barry Margolin writes ..
>In article <362fb0c8.0@monster.ssau.ru>,
>Vlad Harchev <vladhar@imimail.ssau.ru> wrote:
>> The GCD (greatest common divisor) algorithm can be implemented as
template
>>with 2 non-type template parameters. According to D. Knuth the number of
>>divisions for this algorithms is something like this:
>> N = 0.86 log2(n) + C.
>> where 'n' is the number of bits in either of values. For 32-it numbers
>>the N will exceed 17. We should consider the growing of the
>>word sizes in the future.
>How often do you use GCD when both parameters are known at compile time? A
>template can't be expanded unless the parameters are constant expressions.
>How big is C? Even for 128-bit numbers, log2(n) is only 8, so N will only
>exceed 17 if C > 10.
I'm sorry, the formula i've presented is wrong. I've checked it in Knuth,
here is the correct version:
N = 0.5843*n+0.06
where n is the max width of the number in bits. For n=32 N=18.7. The N given
by the formula is the average number of divisions required.
I think modern compilers/computers are powerful enough to handle 1000
specializations of a single template, so raising the limit
still prevent the infinite recursion but allow some tricks.
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: stephen.clamage@sun.com (Steve Clamage)
Date: 1998/10/23 Raw View
ncm@nospam.cantrip.org (Nathan Myers) writes:
>Vlad Harchev<vladhar@imimail.ssau.ru> wrote:
>>
>> CD2 recomends 17 (in some annex) as the value of template recursion
>>limit. IMO the suggested value should be much bigger ...
>I agree. People interested in modern template techniques should
>encourage their National Body representatives to the ISO to
>enter a Defect Report about this. If more than one national body
>demands it there is a better chance of fixing it.
>Until it is fixed, you must use a compiler that exceeds the minimum
>requirement.
But the annex (Annex B) is "informative" only, and says:
"The bracketed number following each quantity is recommended as
the minimum for that quantity. However, these quantities are only
guidelines and do not determine compliance."
What difference will it make to put a higher number in the
annex? Implementations will have limits (or absence of limits)
according to what their customers want and what the implementors
can provide, regardless of what the annex says.
The main reason that the various limits are only guidelines is
that it isn't possible to specify one set of limits that makes
sense across the range of systems that C++ is intended to
support, from wristwatches to data warehouses.
If your favorite compiler can't handle the size of your program,
lobby the vendor to increase its capacity, based on usability
arguments. Complaining that the implementation doesn't comply
with Annex B is not a good argument.
--
Steve Clamage, stephen.clamage@sun.com
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]