Boost logo

Boost :

From: Max Motovilov (max_at_[hidden])
Date: 2004-02-25 19:49:40

"Brian McNamara" <lorgon_at_[hidden]> wrote in message
> See, e.g.
> operator-tag representations as well as the logic that "when combining
> float and double, promote both to double" already exist somewhere in
> Boost (ask Joel or Jaakko, I dunno the details), so reuse those.

With Brian's suggestion in mind, the first part is gone, and the relevant
code for the second part becomes:


using namespace boost::lambda; // Just to make the following easier to

template< template< typename _ > class DAT > struct promote_sum
    typedef void tag;

template< typename P, typename E=void > struct do_not
    enum { value = false };

template< typename P > struct do_not< P, typename P::tag >
    enum { value = true };

template< typename T1, typename T2, template< typename _ > class DAT >
typename boost::disable_if_c<
    do_not< promote_sum< DAT > >::value,
    DAT< typename plain_return_type_2<
        arithmetic_action<plus_action>, T1,T2
>::type >
>::type operator+( const DAT<T1>& a, const DAT<T2>& b )
    typedef DAT< typename plain_return_type_2<
        arithmetic_action<plus_action>, T1,T2
>::type > T;

    return T( a ) + T( b );


The usage is not changed. The code still compiles by MSVC++ 7.1 though takes
markedly longer :( (must be due a lot of declarations included from
<boost/lambda/lambda.hpp>). So we reuse the mechanism, but cause a
heavyweight dependency....

Since the BLL's tagging facility for aritmetic operators is so extensive,
perhaps a better idea would be to parameterize promote***<> instead of using
separate versions (promote_sum<>) for each operator? I.e.

template <> struct promote_type< plus_action, MyDAT > {};


Boost list run by bdawes at, gregod at, cpdaniel at, john at