Boost logo

Boost :

From: Aleksey Gurtovoy (alexy_at_[hidden])
Date: 2001-01-14 21:45:58


Jeremy Siek wrote:
> However, I'd like to see something much simpler
> than what is in the Algebra library... something along the lines of
>
> is_associative<Domain, Op>::type (true_type or false_type)
> ::value (true or false)
>
> Then use this in a static assert in the appropriate concept checking
> classes.
>
> It would be nice if we could have a fairly portable system, works
> with VC++, Borland, etc. That means no partial spec. :(

How about the following form:

algebraic_traits<Domain>::is_associative<Op>::value

There are several ways to make the following code compile under MSVC:

template<typename Domain>
struct algebraic_traits {
  template<typename Op> struct is_associative {
    BOOST_COMPILE_TIME_CONSTANT(bool, value = false);
  };
};

// some non-portable tricks ...

struct plus_operator;
struct my_domain;
BOOST_STATIC_ASSERT(algebraic_traits<my_domain>::is_associative<plus_operator>
::value);

...and others compilers should be happy with a plain (full) explicit
specialization:

template<> template<>
struct algebraic_traits<my_domain>::is_associative<plus_operator> {
 BOOST_COMPILE_TIME_CONSTANT(bool, value = true);
};

--Aleksey


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