Boost logo

Boost :

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


On Mon, Aug 19, 2013 at 1:34 PM, paul Fultz <pfultz2_at_[hidden]> wrote:

> Besides being slightly more verbose, this only works in C++11.
>

Your example is also C++11, since it uses variadic macros.

>
> >
> > 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.

I understand that, but there is already a way to group them at the
usage-site: you use and_. The macro can be changed to just automatically
wrap everything in and_ and it will get the functionality you are looking
for, I just don't think it's necessary, and as I'm sure Mathias would point
out, it adds an extra instantiation if there is only one condition (as is
frequently the case).

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);
>

Again, you can already do all of this via and_ and not_. I'm probably the
last person to be afraid of preprocessor metaprogramming, but making a
little preprocessor EDSL just for "and" and "not" seems like overkill to
me, especially for something like enable_if. Your macro also is more
complicated than that, since you now need to account for commas in
individual conditions as well.

> > 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.

I'm not going to open up this can of worms in this thread, but I am not a
fan of that proposal in the least.

-- 
-Matt Calabrese

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