Boost logo

Boost :

Subject: Re: [boost] Adding helpful requires macros to the enable_if utility
From: Andrey Semashev (andrey.semashev_at_[hidden])
Date: 2014-06-27 12:35:14


On Friday 27 June 2014 09:10:33 paul Fultz wrote:
> These following set of macros, I have found very useful in C++:
>
> #define BOOST_ERROR_PARENTHESIS_MUST_BE_PLACED_AROUND_THE_RETURN_TYPE(...)
> __VA_ARGS__>::type #define BOOST_FUNCTION_REQUIRES(...) typename
> boost::enable_if_c<(__VA_ARGS__),
> BOOST_ERROR_PARENTHESIS_MUST_BE_PLACED_AROUND_THE_RETURN_TYPE
>
> #define BOOST_CLASS_REQUIRES(...) typename
> boost::enable_if_c<(__VA_ARGS__)>::type
>
> #define BOOST_REQUIRES(...) typename boost::enable_if_c<(__VA_ARGS__),
> int>::type = 0
>
> Which I use like the following
>
> For functions:
>
> template <class T>
> BOOST_FUNCTION_REQUIRES(boost::is_arithmetic<T>::value)
> (T) foo(T t) { return t; }
>
> And C++11 functions:
>
> template <class T, BOOST_REQUIRES(boost::is_arithmetic<T>())>
> T foo(T t) { return t; }
>
> Class specializations:
>
> template <class T, class Enable = void>
> class A { ... };
>
> template <class T>
> class A<T, BOOST_CLASS_REQUIRES(is_integral<T>())> { ... };
>
> template <class T>
> class A<T, BOOST_CLASS_REQUIRES(is_float<T>())> { ... };
>
>
> It would be nice if these were the added with the enable_if utility with
> boost.

Frankly, I'd prefer using enable_if directly instead of macros.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk