Boost logo

Boost :

Subject: Re: [boost] [review][mp11] Formal review of Mp11
From: Peter Dimov (lists_at_[hidden])
Date: 2017-07-16 23:24:41


Joaquin M López Muñoz wrote:

> 1.7 mp_eval[_xx] functions should accept metafunctions in both their true
> and false branches.

I can't make this work.

#include <type_traits>
#include <tuple>

template<bool C, template<class...> class F, class... T, template<class...>
class G, class... U> using eval_if = void;

int main()
{
    using R = eval_if<true, std::tuple, int, float, std::tuple, void>;
}

prog.cc:4:55: error: template parameter pack must be the last template
parameter
template<bool C, template<class...> class F, class... T, template<class...>
class G, class... U> using eval_if = void;
                                                      ^

One might argue that it ought to work because G would obviously terminate
the first pack, but it doesn't. :-)

mp_eval_if_c<cond, mp_eval_if_c<!cond, void, F, T...>, G, U...> is not
pretty but... it works.

There's also the option of typename mp_if_c<cond, mp_defer<F, T...>,
mp_defer<G, U...>>::type.


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