Boost logo

Boost :

From: Kevlin Henney (Kevlin.Henney_at_[hidden])
Date: 1999-12-06 07:49:37


Looking at the proposed conversion functions in rational, ie as_float and
as_double, it might be an idea to generalise the concept of conversions to
other types. For instance, accommodate other built-ins (eg long double,
int, etc) as well as user defined numeric types (eg bcd).

In the absence of explicit UDC operators, the suggestion here is to
introduce a rational_cast template. It has a default implementation
(following the existing as_* implementations) and can be further
specialised as necessary:

     template<typename Target, typename Int>
     inline Target rational_cast(const rational<Int> & source)
     {
          return static_cast<Target>(source.numerator()) /
          source.denominator();
     }

Thoughts?

Kevlin


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk