Boost logo

Boost :

From: Alexander Nasonov (alnsn_at_[hidden])
Date: 2006-04-08 17:42:40

Thanks for the review.

Paul A Bristow wrote:
> Definitions given may be adequate, but is MUST have some user-friendly
> guidance as to when it would be useful. Even the summary would be better
> than nothing!
> [ skiped ]
> Practical exampleS of use are ESSENTIAL.

Hopefully, I've found one practical example.

Proposed text:

It is well known that conversion between numeric types has a lot of
nuances. Luckily, Boost Numeric Conversion Library deals with most
of the troubles.
There is one inconvenience, though. Types being converted should conform
to Numeric Type concept. Enumeration types usually don't and you will
have to convert an enum to an appropriate integral type first.
The integral_promotion metafunction is capable of such convertion.
As the name suggests, it applies an integral promotion to a type (para
4.5 of the standard). Types that can't be promoted are returned as-is.
For example, to convert a value of some type T to double, you can write:

   template<class T>
   inline double to_double(T const& value)
       typedef typename boost::integral_promotion<T>::type promoted;
       return boost::numeric::converter<double,promoted>::convert(value);

An additional advantage of applying integral_promotion is reduced number
of instantiations of boost::numeric::converter. Types such as bool,
char, wchatr_t, signed char, unsigned char, short, unsigned short and
potentially big set of enum types are all promoted to a limited set of 4
integral types: int, unsigned int, long and unsigned long.

Alexander Nasonov
Project Manager

Boost list run by bdawes at, gregod at, cpdaniel at, john at