On 4 April 2014 20:50, Zhihao Yuan <
z...@miator.net> wrote:
> On Fri, Apr 4, 2014 at 1:37 PM, Tony V E <
tvan...@gmail.com> wrote:
>> Does anyone else (besides me) need a function like
>>
>> template<bool B, typename X, typename Y>
>> std::conditional<B,X,Y>::type pick(X x, Y y);
>>
>> that returns x or y (and type X or Y) based on the compile-time bool?
>
> Nope, but if I do, I prefer to use C11 type generic expression:
>
> #define PICK(cond, tv, fv) \
> _Generic(bool_constant<bool(cond)>{}, \
> std::true_type: (tv), \
> std::false_type: (fv))
>
> That gives you more flexibility, for example, you don't need to worry
> about questions like "how to avoid the extra copy".
and rvalues already avoid copies. I don't consider that a problem.