$include_dir="/home/hyper-archives/boost/include"; include("$include_dir/msg-header.inc") ?>
Subject: Re: [boost] review request: addition to type_traits library of has_operator_xxx
From: Edward Diener (eldiener_at_[hidden])
Date: 2010-11-16 19:29:20
On 11/16/2010 6:49 PM, Frédéric Bron wrote:
> I would like to propose to your review the following addition to the
> type_traits library, available at the following addresses:
>      https://svn.boost.org/trac/boost/browser/sandbox/type_traits
>      http://dl.free.fr/lRm4VL6WP/type_traits.tar.bz2
>
> The purpose of the addition is to add type traits to detect if unary
> and binary operators can be applied to given types.
> For example, is "x<y" or "!x" or "x+y" meaningful?
> If required, the return type of such an expression is checked to know
> if it is convertible to a given type.
> Default behaviour is to not check the return type.
>
> The following traits are added:
>
> // binary operators:
> template<  typename LHS, typename RHS=LHS, typename RET=void>
>      == has_operator_equal_to
>      != has_operator_not_equal_to
>      >   has_operator_greater
>      >= has_operator_greater_equal
>      <   has_operator_less
>      <= has_operator_less_equal
>      +  has_operator_plus
>      -  has_operator_minus
>      *  has_operator_multiplies
>      /  has_operator_divides
>      %  has_operator_modulus
>      &&  has_operator_logical_and
>      || has_operator_logical_or
>      &   has_operator_bit_and
>      |  has_operator_bit_or
>      ^  has_operator_bit_xor
>
> // unary operators:
> template<  typename RHS, typename RET=void>
>      +  has_operator_unary_plus
>      -  has_operator_unary_minus
>      !  has_operator_logical_not
>
> This new version reflects the discussions we had on the list:
> http://thread.gmane.org/gmane.comp.lib.boost.devel/194625
> In particular about the check or not of the return type.
> All operators are now included and not only comparison binary operators.
>
> Example:
>
>      has_operator_less<LHS, RHS, RET>::value_type is the type bool.
>      has_operator_less<int>  inherits from true_type.
>      has_operator_less<int, int, std::string>  inherits from false_type.
>      has_operator_unary_minus<int, long>  inherits from true_type.
>      has_operator_unary_minus<double, int>  inherits from true_type.
>      has_operator_unary_minus<int, std::string>  inherits from false_type.
>
> Documentation is accessible at libs/type_traits/doc/html/index.html in
> the archive.
Bravo !
I would very much like to see this happen also, as I can use this 
functionality in another library I would like to put in the sandbox.
Without trying to make more work along your lines, would it be easy 
enough for you to add the left shift ( << ) and right shift ( >> ) 
binary operators, and/or the incrementable ( ++x and x++ ) and 
decrementable ( --x and x-- ) unary operators, or are any of these 
especially different or much more difficult cases ?