Topic: Auto-expansion of non-literal boolean arguments to template
Author: Steve Clamage <clamage@eng.sun.com>
Date: Wed, 31 Jul 2002 15:24:56 CST Raw View
On Tue, 30 Jul 2002, Ken Durden wrote:
>
> I've used boolean template arguments in the past to remove unnecessary
> conditional logic inside a large loop for efficiency reasons.
>
> ...
>
> And thus the actual conditional is removed by effectively creating two
> copies of the f function (one with action1, and one with action2).
>
> My proposal is that the compiler allow me to write the following code:
>
> int main()
> {
> bool b1;
> cin >> b1;
>
> f<b1>();
> }
>
> And use the knowledge that b1 is a non-ct-literal in order to expand
> it to the earlier form.
You would need some additional syntax to tell the compiler that no
explicit specializations exist, or if some do exist, which ones they are.
As the language stands, an explicit specialization of the template
might be provided elsewhere in the program, in which case the
compiler must not generate a conflicting one.
Do you intend this feature only for bool template arguments?
Expanding integer arguments would not be feasible. But what about
char arguments? Is 256 function versions too many? (You might generate
more than 256 functions in the scenario you present, just for type bool.)
What about enums? Expand for each enumerator? Usually there are few,
but sometimes there are hundreds or thousands.
I think you need to flesh out the details of your proposal some more.
--
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://www.jamesd.demon.co.uk/csc/faq.html ]