Boost logo

Boost :

From: Guillaume Melquiond (gmelquio_at_[hidden])
Date: 2002-09-26 13:08:03


Hi,

Nobody has replied to my previous mail on this subject, so I'll try one
more time. As I explained before, the current definition of
'operator-(IntType, rational<IntType>)' and 'operator/(IntType,
rational<IntType>)' in rational.hpp are wrong. Indeed, they are defined as
'operator-(T, rational<IntType>)' and 'operator/(T, rational<IntType>)'.

So the code works when T==IntType (or is convertible to IntType) but in
all the other situations, the compilation will fail. In particular, such a
definition doesn't allow to create a new version of 'operator-' and
'operator/' whose right member would be of type 'rational<IntType>'.

The correct behavior should be to use operators.hpp to define these
operators. There is a comment saying that Intel CC chokes on that, but I
don't really understand it. Could someone shed some light on it?

But whatever the reason is, I don't think it is enough to permit a wrong
definition. So here comes the patch I suggest. I don't know how ICC will
behave (I'm still waiting to receive it) so you may want to make this
patch compiler-dependent before applying it.

Thanks,

Guillaume

--- rational_old.hpp 2002-09-26 18:29:10.000000000 +0200
+++ rational.hpp 2002-09-26 18:54:57.000000000 +0200
@@ -121,9 +121,11 @@
     subtractable2 < rational<IntType>, IntType,
     multipliable2 < rational<IntType>, IntType,
     dividable2 < rational<IntType>, IntType,
+ subtractable2_left < rational<IntType>, IntType,
+ dividable2_left < rational<IntType>, IntType,
     incrementable < rational<IntType>,
     decrementable < rational<IntType>
- > > > > > > > > > > > > > >
+ > > > > > > > > > > > > > > > >
 {
     typedef IntType int_type;
     typedef typename boost::call_traits<IntType>::param_type param_type;
@@ -335,26 +337,6 @@
     return operator/= (rational<IntType>(i));
 }
 
-// Intel C++ seems to choke on this unless i is a reference parameter, matching
-// the reference parameter in the operator-() generated by subtractable
-template <typename IntType, typename T>
-inline rational<IntType>
-operator- (const T& i, const rational<IntType>& r)
-{
- IntType ii = i; // Must be able to implicitly convert T -> IntType
- return rational<IntType>(ii) -= r;
-}
-
-// Intel C++ seems to choke on this unless i is a reference parameter, matching
-// the reference parameter in the operator-() generated by subtractable
-template <typename IntType, typename T>
-inline rational<IntType>
-operator/ (const T& i, const rational<IntType>& r)
-{
- IntType ii = i; // Must be able to implicitly convert T -> IntType
- return rational<IntType>(ii) /= r;
-}
-
 // Increment and decrement
 template <typename IntType>
 inline const rational<IntType>& rational<IntType>::operator++()


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