On Wed, 18 Jun 2003 22:27:27 +0100, "Paul A Bristow" <[EMAIL PROTECTED]> wrote:
>| -----Original Message----- >| From: [EMAIL PROTECTED] >| [mailto:[EMAIL PROTECTED] On Behalf Of Gennaro Prota >| [...] >| >| In Daniel's solution static_cast<type>(x) simply "selects" >| the corresponding specialization of x_value. So >| >| static_cast<float>(pi) >| >| is fundamentally different from, say, >| >| double pi = ...; >| static_cast<float>(pi) > >Perhaps naively, I find this surprising - but I am not a language guru. > >Can you/anyone confirm that this is required by the Standard > - and is in fact what happens when compilers process this? Yes :-) Note that all "conversions" from a constant<T, F> pass through template< typename U > operator U() const { return F< U >()(); } Now, F<U>()() means (ignoring some technical differences irrelevant here): F<U> object; // construct an x_value<U> object return object(); // invoke operator() on it and return Now, if you use the binary operators, like in: pi * f; with f being a float then the selected specialization is float; i.e. the constant "takes the type" of its adjacent operand (left operand if it exists, right operand otherwise). This is, of course, different from what normally happens when you do double pi = ...; pi * f; // floating point promotion on f and is IMHO a caveat. But, still, there are no truncations. Only selection of the target specialization. If no target specialization exists, e.g. static_cast<int>(pi) you have a compile-time error. > >If it walks like a duck and quacks like a duck ... This walks quite differently. And doesn't quack :-) Genny. _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost