I wanna alias type according to passed template argument.
Depending on Passed Template argument int value, return Type is decided.
but there is many types what I want.
I wanna do this with clean code.
I know I can do this with std::conditional_t
, but it's really messy. I need aliasing many types from int value
template <int value>
std::conditional_t<value== 1, Type1, std::conditional_t<value== 2, Type2, std::conditional_t<value== 3, Type3, Type4>>> Function()
{
}
but I wanna more clean ways.
Actually if I just put type at return type, I can do this, but I wanna use template value argument.
I don't know what should I use for this.
switch(value)
{
case 1:
using type = typename Type1;
break;
case 2:
using type = typename Type2
break;
}
I know this code is ill-formed, but this concept is what I want.
question from:
https://stackoverflow.com/questions/65644740/is-there-proper-way-to-alias-type-depending-on-passed-template-value-argument-at 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…