Search code examples
c++language-designc++11

Why is there a sizeof... operator in C++0x?


I saw that @GMan implemented a version of sizeof... for variadic templates which (as far as I can tell) is equivalent to the built in sizeof.... Doesn't this go against the second design principle: prefer libraries to language extensions?


Solution

  • From Variadic Templates (Revision 3) (N2080=06-0150), page 6:

    Although not strictly necessary (we can implement count without this feature), checking the length of a parameter pack is a common operation that deserves a simple syntax. Moreover, this operation may become necessary for type-checking reasons when variadic templates are combined with concepts; see Section 3.3.

    (Section 3.3 talks about concepts which is irrelevant now.)