Boost logo

Boost :

From: Aleksey Gurtovoy (alexy_at_[hidden])
Date: 2000-09-16 04:50:57


Daryle Walker (<darylew_at_[hidden]>) wrote:
> To solve my boost/operators.hpp problem with template chaining getting too
> long for my compiler to support, I want to group operator templates
> together, then chain those groups together. I tried stuff like:

[snip]

Actually defining a grouped operator template is not any harder than
defining "an ordinary" operator like 'left_shiftable'. You must just follow
the same pattern:

1) define 'grouped_operator##2' and 'grouped_operator##1' versions of a
template:

template <class T, class U, class B = ::boost::detail::empty_base>
struct additive_operators2
    : addable2<T, U
    , subtractable2<T, U, B
> > {};

template <class T, class B = ::boost::detail::empty_base>
struct additive_operators1
    : addable1<T
    , subtractable1<T, B
> > {};

2) let the compiler know that they are 'operator template classes', not
something else, i.e. add the following line:

BOOST_OPERATOR_TEMPLATE(additive_operators)

3) that's all! :) just do the same for all grouped operator templates, and
your 'operators1/2' will just work :).

BTW, I am not very comfortable about templates that provide implicit
conversion to 'bool' and 'void*' too. IMO they are implemented in a very
innatural way - e.g. they require T to be DefaultConstructible (for no
reason), and they create this temporary T() object every time they are
called, and their overall semantics seems quite strange to me, and, at last,
they just don't fit into overall concept of the 'operators' framework -
there are no generally accepted and useful ways to implement these operators
in terms of another ones, so let's just leave them out.

--Aleksey


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