Boost logo

Boost Users :

Subject: Re: [Boost-users] Determine at compile time whether type has subtraction semantics?
From: John Reid (j.reid_at_[hidden])
Date: 2011-02-21 07:38:29


On 19/02/11 06:51, Frédéric Bron wrote:
>> Is it possible to determine at compile-time if a type has subtraction
>> semantics? E.g. in struct A<T> I would like to decide at compile-time not to
>> execute&A::subtract in the register_fns method. Then the subtract method is
>> not instantiated and there is no error.
>
> You can look at the code that will be reviewed soon for an extension
> of type traits.
>
> #include<boost/type_traits/has_operator_minus.hpp>
>
> boost::has_operator_minus<T, T, T>::value is what you want:
> is true if x-y returns something convertible to T
> is false if operator-(T, T) does not exist.
>
> http://www.boostpro.com/vault/index.php?action=downloadfile&filename=type_traits.tar.bz2&directory=Extension&

This looks good but it isn't compiling for me right now. Just compiling
this include:

#include <boost/type_traits/has_operator_minus.hpp>

gives me this error:

In file included from
/home/john/Dev/ThirdParty/boost/sandbox/type_traits/boost/type_traits/has_operator_minus.hpp:55,
from src/sandbox.cpp:2:
/home/john/Dev/ThirdParty/boost/sandbox/type_traits/boost/type_traits/detail/has_binary_operator.hpp:165:
error: expected constructor, destructor, or type conversion before ‘(
         ’ token

svn revision 69069, gcc 4.4.3


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net