Boost logo

Boost :

Subject: Re: [boost] Is there BOOST_ENABLE_IF macro now?
From: Matt Calabrese (rivorus_at_[hidden])
Date: 2013-08-18 19:54:46


On Sun, Aug 18, 2013 at 4:16 PM, paul Fultz <pfultz2_at_[hidden]> wrote:

> > 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-td3442723.html
> >
> >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<class T, class U>
> ZEN_FUNCTION_REQUIRES(is_arithmetic<T>, is_arithmetic<U>)
> (T) max(T x, U y)
> {
> return x > y : x ? y;
> }
>
>
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 ) { /**/ }

If you want to group requirements into a simple name, you can also use a
typedef.

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.

-- 
-Matt Calabrese

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