Boost logo

Boost :

From: Dave Abrahams (abrahams_at_[hidden])
Date: 2000-04-30 08:54:38


on 4/30/00 3:49 AM, Aleksey Gurtovoy at alexy_at_[hidden] wrote:

> Dave Abrahams <abrahams_at_[hidden]> wrote:
>> I think one upshot of this technique, though, is that the use of partial
>> specialization for 2-type versions of some operator templates, such as
>> equality_comparable, must finally die (or at least lose backward
>> compatibility) in favor of the versions with "2" at the end of the name. I
>> don't see any way around this. If you do, please speak up!
>
> Dave, I've tried to play a little with the problem and that play turned out
> into a new version of 'boost/operators.hpp', which implements the suggested
> technique and still has backward compatibility with old code. It's not
> perfect and there are some parts of the code which probably need to be
> reworked, but in whole it may serve the needs. MW CW 5.3 and KAI C++ 3.3 for
> NT seem to be quite happy with the new version (at least they compile and
> run 'operators_test.cpp' without any error).

Wow, that's an impressive and energetic (fast) bit of coding!

You have a very tricky use of partial specialization to determine whether
you've got another operator or another type to compare with. I thought of
doing something like that... for about a second ;)

I see the following potential problems:

1. What happens when you try to use the 2-type version of addable with
another class derived from one of the operators? For example, suppose you
have a variable precision integer class that you want to be able to combine
with a rational? Don't you end up improperly detecting the 2nd type as an
operators base class instead of a 2nd operand type?

2. Lack of public derivation means that forward_iterator_helper is-not-a
std::iterator<...>

3. Seems like you'd have unpredictable effects for users that get used to
the usual case of chaining addable<T, multipliable<T, ... if the last item
in the chain is some other base class they want. For example, what does this
do?

class Y {};
class X : public addable<X, multipliable<X, Y> > { };

[and back to the first example]

class Y : public addable<Y> {};
class X : public addable<X, multipliable<X, Y> > { };

-Dave


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