Boost logo

Boost :

From: Andy Little (andy_at_[hidden])
Date: 2005-04-09 08:10:08


"Jonathan Turkanis" <technews_at_[hidden]> wrote

> 2. What changes or additions would people like to see?

One could make some modifications to rational to make them it user friendly.

For example the following results in a compile time failure n VC7.1:

    boost::rational<int> r1;
    boost::rational<long> r2;
    r1 + r2;

Naturally if a bigint rational was to be used, I would expect

    rational<bigint>() + rational<int>() to work.

This is fairly trivial to accomplish using BOOST_TYPEOF:
    eg something like
   template <typename Lhs, typename Rhs>
    typename boost::enable_if< // only for compat with current header
        boost::mpl::not_<
            boost::is_same< Lhs, Rhs>
>,
        rational<typename BOOST_TYPEOF(Lhs() + Rhs())>
>::type
    operator + (rational<Lhs> const & lhs, rational<Rhs> const& rhs);

FWIW this applies as well to other UDTs including interval and complex.
which are currently inconsistent

eg std:::complex<double> d ;

d * 2; // fails to compile
 d *= 2; // compiles ok

regards
Andy Little


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