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 12:32:27


On 21/02/11 16:59, Raymond Burkholder wrote:
>> 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.
>> Is there any way to do use the type traits to conditionally compile some
>> code using some brief syntax? I.e. it would be nice if something like
>> the following worked:
>>
>
> I think you are looking for something along the lines of what is suggested
> "An Optimized Version of std::copy" in the type_traits examples.
> http://www.boost.org/doc/libs/1_45_0/libs/type_traits/doc/html/boost_typetra
> its/examples/copy.html
>
> It provides conditional compilation via a form of template
> indirection/selection.
>
>
I think that is exactly what I was trying to avoid, having to define the
function elsewhere to be specialised. I wanted to do something more
inline. I guess it is not possible but I thought I'd ask.

John.


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