I'm building trait-types (similar to std::type_identity) to represent template-templates of the different flavors. Mixed-type variadic value templates are a special case, and I can only think of doing them via nested structs, as shown below.
clang accepts this, gcc does not.
template <typename ... Ts>
struct variadic_value_metatemplate_builder
{
template <template <Ts ... tt_Vs> typename TT>
struct build
{
template <Ts ... Vs>
using type = TT<Vs ...>;
};
};
gcc's error is:
<source>:8:39: error: expansion pattern 'tt_Vs' contains no parameter packs [-Wtemplate-body]
8 | using type = TT<Vs ...>;
who is right?
the wording of gcc's error seems incorrect, but I guess it's related to the requirement for Vs ...
and Ts ...
to have the same size, making Vs ...
not freely variadic. But they're all still parameter packs AFAIK.
EDIT: ASIDE: Why might this be useful?
It's actually pretty hard to create a practical use-case (for this specific flavor of template-template), but here's my quick attempt at one (highly implausible, not very good).
You're writing a testing routine for a group of templated graphics operations. Some are of the form <int DIMENSION>
, some are <int DIMENSION, bool UNDO>
, etc... You want to write a generic test routine for all forms, that takes a form parameter, a set of matching graphics operations, and a set of constexpr test values for the parameters. You can then do something like:
generic_graphics_test<metabuilder_DIMENSION_UNDO, variadic_auto_constants<2, false>, variadic_auto_constants<3, true>, [etc...]>::test<gfx_translate, gfx_scale, [etc...]>()
;
to somehow test the 2D and 3D-undoable varieties of gfx_translate
and gfx_scale
. (where test()
takes instances of build
(above) as template parameters, which here represent the (raw, unresolved) translate and scale template operations (as functors or something)).
(... this is like meta-nesting-level-4 or something :)
((I hope at least 17% of that is semicomprehensible :))
Unfortunately there isn't a generic "template-parameter-of-possibly-variadic-type-or-value" keyword yet (would be very nice, but probably really hard to write compiler code for), which would allow every possible flavor of template-template to be represented by a single trait template.
Appears to be a GCC bug reported in 2018.
Odd that it's not fixed as it's IMHO quite severe, it seems any attempt to provide variadic values for a template-struct member of a given variadic-type-template outer struct will fail. Sounds tricky to fix, though.