libcxx - variadic parameter packs not final argument in templates

In several files in libcxx the templates have argument lists where the parameter pack is not last. For example:

template <class _Alloc, class …_Up,
class = typename enable_if

…[snip]…
tuple(allocator_arg_t, const _Alloc& __a, _Up&&… __u)

or the many declarations of __invoke in <type_traits>.

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.

The reason I’m looking at this is I’m trying to compile with MSVC and it really hates certain headers. The errors are cryptic at best but seem to originate from having args after the pack.

Thanks

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