Boost logo

Boost :

From: Paul Moore (gustav_at_[hidden])
Date: 2001-01-12 18:17:57


[Sorry if this appears twice - mailer problems...]

On 11 Jan 2001, at 22:01, Stephen Silver wrote:

> This means that it's necessary instead to write
>
> r += Integer(2);
>
> This gets pretty cumbersome when you have to do it a lot. And you
> usually do have to do it a lot, because it applies to just about every
> operator that boost::rational defines. The problem can be cured by
> adding a template constructor like this:
>
> template <class T> rational(T n) : num(), den(1) { num = n; }

One issue. This clashes with the existing constructor

    rational(IntType n = 0) : num(n), den(1) {}

In principle, I can omit this and just use your version. However,
there are some issues. The first is minor - I would prefer to
explicitly code a constructor from the base integer type, for clarity.
The second is that I now have to write a constructor for 0
arguments explicitly. The third, and most major, is that the
template class uses assignment, but for construction from IntType
it would be better to use construction (no issue with an explicit
constructor, and construction may be more efficient...)

I'll go with it, but I think it's worthy of a comment - does anyone
else have an issue with this change?

[Later...]
I implemented and tested this, and it's giving odd errors in the tests - of
which

rational_example.cpp(50) : error C2678: binary '+' : no operator defined
which takes a left-hand operand of type 'class boost::rational<int>' (or
there is no acceptable conversion)

is an example.

No time to check this now, so I'll back it out until I know what's going on...

Paul.


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