
From: Matt Calabrese <rivorus@gmail.com>
How is this different from:
template< class T, class U , BOOST_ENABLE_IF( and_< is_arithmetic< T >, is_arithmetic< U > > ) > T max( T x, U y ) { /**/ }
Besides being slightly more verbose, this only works in C++11.
If you want to group requirements into a simple name, you can also use a typedef.
Grouping requirements is extremely common. Using a typedef is the equivalent of creating a function object vs using a lambda. However, many times multiple requirements are created because there are multiple parameters, or to avoid ambiguities. Requirements need to be included and excluded in order to work around ambiguities. For example, to define an equals function that work recursively over ranges, and pairs, could be declared like this: template<class T, class U> ZEN_FUNCTION_REQUIRES(exclude is_pair<T>, exclude is_pair<U>, exclude is_range<T>, exclude is_range<U>) (bool) equals(const T& x, const U& y); template<class Range1, class Range2> ZEN_FUNCTION_REQUIRES(is_range<Range1>, is_range<Range2>) (bool) equals(const Range1& r1, const Range2& r2); template<class Pair1, class Pair2> ZEN_FUNCTION_REQUIRES(is_pair<Pair1>, is_pair<Pair2>, exclude is_range<Pair1>, exclude is_range<Pair2>) (bool) equals(const Pair1& p1, const Pair2& p2); The exclusion traits are necessary, since a pair of iterators is a range as well.(Of course, a better way to avoid ambiguities is to use `zen::conditional_adaptor`).
As for the emulation stuff you are talking about, there's the "generic" directory in the sandbox, which is a library for concept emulation, though it's sort of in limbo.
I was referring to the ConceptsLite proposal. Instead of `ZEN_FUNCTION_REQUIRES` using `enable_if` underneath, it could use the requires clause instead(for compilers that support it). Somethng like this(its just a rough idea): template<class Cond> constexpr bool has_traits() { return Cond::value; } #define ZEN_ERROR_PARENTHESIS_MUST_BE_PLACED_AROUND_THE_RETURN_TYPE(...) __VA_ARGS__ #define ZEN_FUNCTION_REQUIRES(...) \ requires has_traits<ZEN_DETAIL_REQUIRES_CLAUSE(__VA_ARGS__)>() ZEN_ERROR_PARENTHESIS_MUST_BE_PLACED_AROUND_THE_RETURN_TYPE It could be defined better as well to improve overloading. Paul Fultz II