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?
views:
229answers:
2sizeof...
is just sugar, I think.
sizeof
is indeed core to the language as is ...
, and although a countof
function could exist we already have sizeof
and ...
reserved so we might as well make it convenient to get the count that way.
Contrarily, if sizeof
and ...
weren't reserved, the idea of adding such a thing would have probably failed because new keywords tend to be frowned upon. (The less the better.)
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.)