Re: Compile Time String processing
On Feb 26, 9:37 am, Walter Bright <wal...@digitalmars-nospamm.com>
wrote:
Lance Diduck wrote:
What I am not clear on, if FPN's were allows as template non-type
paramters, and by extension in compile time expressions, how would
something like this work:
template <float F> struct foo {enum{val=0}; };
template <>struct foo<3.3333333333333>{enum{val=1}; };
template <>struct foo<3+1.0/3>{enum{val=2};};
typedef foo<10.0/3> bar;
It seems to me that the value of bar::val is indeterminate.
It's not any less portable than:
if (x == 3.3333333333) ...
but that's allowed.
The question is whether foo<3.3333333333> and foo<3.3333333332>
are the same type or not. When templates were being adopted
back in the 1990's, the committee didn't have any real answer to
this: is it acceptable to leave it unspecified, or must it be
implementation defined, or even must it be specified by the
standard. In the end, they decided not to allow it, rather than
risk doing the wrong thing. When defining a standard, this is
more or less what you have to do. It's easy to add a feature,
once you know what it should do, but it's almost impossible to
remove one, or even change it, if you make the wrong choice.
(The way floating point is specified in C/C++, something like
the above could even depend on the level of optimization. And
yes, this affects the if as well---I've had examples of code
compiled with g++ where the results of something like the if
changed depending on the optimization level I used.)
--
James Kanze (GABI Software) email:james.kanze@gmail.com
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
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]