yohhoyの日記

技術的メモをしていきたい日記

Visual Studio 11 BetaのVariadic Templatesエセ対応

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

結論:言語機能としてはサポート一切なし。ただしC++標準ライブラリの一部をマクロでエミュレーション。MSVC12(?)に期待。

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.

http://blogs.msdn.com/b/vcblog/archive/2012/02/29/10272778.aspx

詳細は下記 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.

http://blogs.msdn.com/b/vcblog/archive/2011/09/12/10209291.aspx

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)版のため、ライセンスの扱いに注意。

*1:これを"対応"と言っていいものか…