Re: [Boost-users] Determine at compile time whether type has subtraction semantics?
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
On 19/02/11 06:51, Frédéric Bron wrote: 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. -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean.
On 21/02/11 16:59, Raymond Burkholder 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
On 19/02/11 06:51, Frédéric Bron wrote: 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.
participants (2)
-
John Reid
-
Raymond Burkholder