Boost logo

Glas :

[glas] mixed value_type operations

From: Karl Meerbergen (Karl.Meerbergen_at_[hidden])
Date: 2005-10-26 09:46:38


Hello,

There are situations where the value_type's of operations are mixed, e.g. v+w,
v+=w.

We must define concepts that deal with different value types. The current glas
code already partly supports this but the concepts are not very clear about
it.

One options is the definition of a convertible concept (see attached file) and
define mixed operations from there.

Another consequence is that "+" no longer defines an AdditiveGroup, but rather
is a function between two objects that may have a different type. If both
types are the same, we may have an AdditiveGroup.

So we can introduce a concept HasAdditionAndSubtraction where e.g.
X x;
Y y;
x+=y;
x-=y;
are permetted for all y that are convertible to X. In practice it means that
operator+=() is templated.

class X{
  ...
  template <class Y>
  X& operator+=( Y const& y ) {
    ...
  }
  ...
};

Comments?

Karl