2016-11-10 16 views
0

是否有更簡潔的方式來編寫以下內容?用相同的條件編寫一系列std :: conditional

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; 
... 

當條件是相同的,並且type_Axtype_Bxtype_Cx爲不同的線路是不同的。

+3

看起來像一個宏的好候選 – NathanOliver

+0

我可以定義一個只適用於類範圍的宏嗎? –

+1

不,宏不遵守範圍。 – Borgleader

回答

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

using C1 = select<A1, B1>; // or typedef if you really like that syntax 
// etc.