[cfe-dev] libcxx - variadic parameter packs not final argument in templates
Jonathan 'Rynn' Sauer
jonathan.sauer at gmx.de
Mon Mar 30 01:23:11 PDT 2015
Hello,
> In several files in libcxx the templates have argument lists where the parameter pack is not last. For example:
>
> I was under the impression that this wasn't valid syntax, i.e. that the parameter pack should be the final argument. Can someone enlighten me here? If I'm wrong then just point me at the correct source.
N4141 (C++14) ยง14.1p11 says:
| If a template-parameter of a primary class template or alias template is a template parameter pack, it
| shall be the last template-parameter. A template parameter pack of a function template shall not be followed
| by another template parameter unless that template parameter can be deduced from the parameter-type-list of
| the function template or has a default argument
So it's not allowed for class templates, but it is allowed for function templates in some cases. Your
example from <tuple>:
| template <class _Alloc, class ..._Up,
| class = typename enable_if
| ...[snip]...
| tuple(allocator_arg_t, const _Alloc& __a, _Up&&... __u)
As the (unnamed) parameter after the parameter pack has a default argument (enable_if), this is a valid
function template declaration.
hope that helps,
Jonathan
More information about the cfe-dev
mailing list