Visual Studio 11 BetaのVariadic Templatesエセ対応

Visual Studio 11(MSVC11) Betaの可変長引数テンプレート(Variadic Templates)対応*1についてメモ。


MSVC11 C++ライブラリの既定では最大5引数までサポート。マクロ_VARIADIC_MAXを指定することで最大10引数まで伸ばせる。

Simulated variadic templates now accept a maximum of 5 arguments by default, down from 10. To increase this limit, at the cost of compiler speed, define _VARIADIC_MAX project-wide between 5 and 10 inclusive.


詳細は下記 Visual C++ Team Blog - C++11 Features in Visual C++ 11 に詳しい。(下線部は強調)

Faux variadics: We've developed a new scheme for simulating variadic templates. Previously in VC9 SP1 and VC10, we repeatedly included subheaders with macros defined differently each time, in order to stamp out overloads for 0, 1, 2, 3, etc. arguments. (snip) In VC11, the subheaders are gone. Now we define variadic templates themselves as macros (with lots of backslash-continuations), then expand them with master macros.(snip)In VC9 SP1 and VC10, infinity was 10 (i.e. "variadic" templates supported 0 to 10 arguments inclusive). In the VC11 Developer Preview, infinity is 5 by default.


2012-11-29追記:Announcing November CTP of the C++ compiler, now with more C++11 - Visual C++ Team Blogにて、"November 2012 Compiler CTP"でC++コンパイラのみ可変長引数テンプレートに対応した旨がアナウンスされた。このCTPはC++標準ライブラリの更新を含まない。あくまでCTP(Customer Technology Preview)版のため、ライセンスの扱いに注意。