r xu - 1 year ago 62

C++ Question

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`

Answer Source

```
template<class A, class B> using select = std::conditional_t<condition, A, B>;
typedef select<A1, B1> C1;
// etc.
```