Boost logo

Boost :

Subject: Re: [boost] [review][mp11] Formal review of Mp11
From: Peter Dimov (lists_at_[hidden])
Date: 2017-07-15 12:47:57


Vinnie Falco wrote:

> * The documentation states: "mp_if_c<true, T, E…> is an alias for T.
> mp_if_c<false, T, E> is an alias for E. Otherwise, the result is a
> substitution failure."
>
> Should that read "mp_if_c<false, T, E...>"? If not, why?

No.

The idea here is that mp_if_c can be used in two ways. One is mp_if_c<Cond,
T, E>, which gives either T or E depending on Cond. The other is
mp_if_c<Cond, T>, which is the same as std::enable_if_t<Cond, T> - gives T
when Cond, otherwise a substitution failure.

So

mp_if_c<true, T> is T
mp_if_c<true, T, E> is T
mp_if_c<false, T, E> is E

Aliases can't be specialized, so it's not possible to implement just the
above, which is why it takes a parameter pack for E... and does

mp_if_c<true, T, E...> is T
mp_if_c<false, T, E> is E

which for the three cases we're interested in gives the results we need.


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