r xu r xu - 26 days ago 9
C++ Question

Writing a series of std::conditional with the same condition

Is there a more compact way to write the following?

typedef typename std::conditional< condition, type_A1, type_B1 > type_C1;
typedef typename std::conditional< condition, type_A2, type_B2 > type_C2;
typedef typename std::conditional< condition, type_A3, type_B3 > type_C3;
...


Where the condition is same, and
type_Ax
,
type_Bx
,
type_Cx
for different lines are different.

Answer
template<class A, class B> using select = std::conditional_t<condition, A, B>;

typedef select<A1, B1> C1;
// etc.