Boost logo

Boost Users :

Subject: Re: [Boost-users] Determine at compile time whether type has subtraction semantics?
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2011-02-18 12:55:16


AMDG

On 2/18/2011 9:50 AM, John Reid 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.
>
> template< typename T >
> struct A {
> void register_fns() {
> &A::subtract;
> }
>
> T subtract( T x, T y ) {
> return x - y;
> }
> };
>
> void test() {
> A< int >().register_fns(); // int: Fine
> A< std::string >().register_fns(); // string: Compile error
> }
>
> I didn't see anything in Boost.TypeTraits
>

I believe the type traits extensions in the
review queue handle this.

In Christ,
Steven Watanabe


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