Subject: Re: [boost] review request: addition to type_traits library of has_operator_xxx
From: Jeffrey Lee Hellrung, Jr. (jhellrung_at_[hidden])
Date: 2010-11-16 19:19:49
On 11/16/2010 03: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:
> 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.
I think several people who follow this list (myself included) have
implementations of such traits lying around, so it makes sense to union
the best parts of each one. I will take a look at your implementation
and see if I have any suggestions.
One thing that I've either found useful is to have an additional
template parameter in addition to the parameter types and the return
type, which is a Boost.MPL metapredicate intended to be applied to the
actual result of the operation. The trait then evaluates to true only
if the actual result type satisfies the given Boost.MPL metapredicate.
This covers the cases where you may want to know more about the result
type than whether it is convertible to some given type. For example,
for the comparison operators, you may want to check if the result type
of a particular comparison is *precisely* bool, rather than just
convertible bool (that might be a rather contrived example, and if you
don't believe this has a real use, I can (probably) come up with more
real-world examples). It should be easy to support, it won't complicate
existing use, and I believe it does provide some additional desirable
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk