Whats wrong with this expression?
template<class T, class FieldT>
using addRefU = typename std::conditional<
// ok when true. When false result has no reference at all
false,
typename std::add_rvalue_reference< FieldT >::type,
typename std::conditional<
true,
typename std::add_rvalue_reference< FieldT >::type,
typename std::add_lvalue_reference< FieldT >::type
>
>::type;
int main()
{
std::cout << std::is_rvalue_reference<
addRefU<A, B>
>::value << std::endl;
std::cout << std::is_lvalue_reference<
addRefU<A, B>
>::value << std::endl;
}
http://coliru.stacked-crooked.com/a/21593805f2c6e634
As a result, it does not have reference at all. Are nested std::conditional's not allowed?
You forgot a ::type
on the nested conditional
:
template<class T, class FieldT>
using addRefU = typename std::conditional<
// ok when true. When false result has no reference at all
false,
typename std::add_rvalue_reference< FieldT >::type,
typename std::conditional<
true,
typename std::add_rvalue_reference< FieldT >::type,
typename std::add_lvalue_reference< FieldT >::type
>::type
>::type;
int main()
{
std::cout << std::is_rvalue_reference<
addRefU<A, B>
>::value << std::endl;
std::cout << std::is_lvalue_reference<
addRefU<A, B>
>::value << std::endl;
}
Live on Coliru
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With