using IntegerType1 = int;
typedef int IntegerType2;
int main()
{
IntegerType1 n1 = 1; // OK
IntegerType2 n2 = 2; // OK
}
私の質問は次のとおりです。
using-style と typedef-style の違いは何ですか?
すでに typedef スタイルがあるので、using スタイルを C++ 標準にする動機は何ですか?
非テンプレートでも可読性が大幅に向上することがわかりました。
typedef void (*FunctionPtr)(); // right-to-left, identifier in the middle of the definition
using FunctionPtr = void (*)(); // left-to-right, same as variables
おそらくマイナーですが、テンプレートメタプログラミングでは、この構文上の利点により、プログラムが読みやすくなり、テンプレートメタ関数を関数にリファクタリングしやすくなりconstexpr
ます。基本的に交換
using T = type_expression;
constexpr auto v = value_expression;
さらに(当局に訴える)、それはEffective C++11/14ガイドラインの草案にもあります。