From: TONGARI J
Hi folks,
It's over 2 years since this post:
http://boost.2283326.n4.nabble.com/New-powerful-way-to-use-enable-if-in-C-0x...
The macro looks sweet and I wonder if we have this macro in Boost in case
that I missed it.
This is nice for C++11 and conversion operators, I was not aware of this
trick. However, it would be nice if boost provided requires macros to make it
easier to specify traits for enable_if. See here for an implementation:
https://github.com/pfultz2/Zen/blob/master/zen/requires.h
So functions can be defined like this:
template
ZEN_FUNCTION_REQUIRES(is_arithmetic<T>, is_arithmetic<U>)
(T) max(T x, U y)
{
return x > y : x ? y;
}
All the traits our inclusive by default, but the `exclude` keyword can be
used to exclude the trait, like this:
template
ZEN_FUNCTION_REQUIRES
(
is_arithmetic<T>,
is_arithmetic<U>,
exclude is_same,
exclude is_same
)
(T) max(T x, U y)
{
return x > y : x ? y;
}
It can be used in classes like this:
template
class A { ... };
Or this:
template
class A { ... };
template <class T>
class A { ... };
template <class T>
class A { ... };
This will all work on C++03 compilers as well. It could also be extended
fairly easily to support the trick from Matt Calabrese. Plus, the
`FUNCTION_REQUIRES` seems like it could be easily converted to use the
`requires` and concept overloading when it gets added to the language as well.
What do you think?
Thanks,
Paul Fultz II