Boost logo

Boost :

From: helmut.zeisel_at_[hidden]
Date: 2001-08-21 13:55:40


Long time ago I asked whether operator.hpp could
support the other version of non-commutative operators like

friend T operator-(const U& x, const T& y)
{
  T x1(x);
  return x1 -= y;
}

--- In boost_at_y..., "David Abrahams" <david.abrahams_at_r...> wrote:
>
> ----- Original Message -----
> From: <helmut.zeisel_at_a...>
>
> > I would appreciate an additional related
> > family of operator templates.
>
> Why don't you submit a proposed patch (including one for the
documentation)?

Below are the additional operators struct
I use in my current implementation of big_int
(already using the additions of Daryle Walker
from May 2001 to operators.hpp).

subtractable2_left, dividable2_left and
ordered_field_operators
could also be used to simply interfaces such as rational.hpp.

For the structs you accept for operators.hpp,
I will add the necessary documentation.
If you prefer different names for some structs,
it will probably be no problem for me.

Helmut

template <class T,class B=::boost::detail::empty_base>
struct ring_operators1
    : additive1<T
    , multipliable1<T, B
> > {};

template <class T,class B=::boost::detail::empty_base>
struct field_operators1
    : additive1<T
    , multiplicative1<T, B
> > {};

template <class T,class B=::boost::detail::empty_base>
struct ordered_field_operators1
    : field_operators1<T
    , totally_ordered1<T, B
> > {};

template <class T,class B=::boost::detail::empty_base>
struct euclidian_ring_operators1
    : ring_operators1<T
    , dividable1<T
    , modable1<T,B
> > > {};

template <class T,class B=::boost::detail::empty_base>
struct integer_operators1
    : totally_ordered1<T
    , euclidian_ring_operators1<T
    , unit_steppable<T,B
> > > {};

template <class T,class B=::boost::detail::empty_base>
struct bitwise_integer_operators1
    : integer_operators1<T
    , bitwise1<T,B
> > {};

//
// "left" means that the argument of other class U
// is applied from left.
//
template <class T, class U, class B = ::boost::detail::empty_base>
struct subtractable2_left : B
{
  friend T operator-(const U& x, const T& y)
  { T result(x); return result -= y; }
};

template <class T, class U, class B = ::boost::detail::empty_base>
struct dividable2_left : B
{
  friend T operator/(const U& x, const T& y)
  { T result(x); return result /= y; }
};

template <class T, class U, class B = ::boost::detail::empty_base>
struct modable2_left : B
{
  friend T operator%(const U& x, const T& y)
  { T result(x); return result %= y; }
};

template <class T, class U, class B = ::boost::detail::empty_base>
struct ring_operators2
    : additive2<T,U
    , subtractable2_left<T,U
    , multipliable2<T,U,B
> > > {};

template <class T, class U, class B = ::boost::detail::empty_base>
struct field_operators2
    : ring_operators2<T,U
    , dividable2<T,U
    , dividable2_left<T,U,B
> > > {};

template <class T, class U, class B = ::boost::detail::empty_base>
struct ordered_field_operators2
    : field_operators2<T,U
    , totally_ordered2<T,U,B
> > {};

template <class T, class U, class B = ::boost::detail::empty_base>
struct euclidian_ring_operators2
    : ring_operators2<T,U
    , dividable2<T,U
    , dividable2_left<T,U
    , modable2<T,U
    , modable2_left<T,U,B
> > > > > {};

template <class T, class U, class B = ::boost::detail::empty_base>
struct integer_operators2
    : totally_ordered2<T,U
    , euclidian_ring_operators2<T,U,B
> > {};

template <class T, class U, class B = ::boost::detail::empty_base>
struct bitwise_integer_operators2
    : integer_operators2<T,U
    , bitwise2<T,U,B
> > {};


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