I'm trying to make a function template that will accept two (or more) of the nested variadic class templates listed below, as arguments, and put them into another data structure that will accept different types (pair or tuple is what I'll most likely use). Here are the classes and subclasses, along with the usage of my function (the function is defined farther below):
template<typename... Args> struct Entity {
template<typename... InnerEntArgs> struct InnerEntity {
InnerEntity(InnerEntArgs... inner_ent_args) {
... //do stuff w/ InnerEntArgs pack
... //do stuff that makes Inner dependent on Outer's Args pack
}
};
};
struct ThingA : Entity<int, string> {
... //construct ThingA
};
struct ThingB : Entity<string, string> {
... //construct ThingB
};
auto foo = my_func(
ThingA::InnerEntity<int, int, int>(1, 2, 3)
, ThingB::InnerEntity<string, int>("bar", 1)
);
Below is the code I cobbled together for the function, and it does compile fine, but I'm not sure if it is set up correctly. Specifically, I'm a little fuzzy on how typename
and ::template
are making the compiler happy in this context, or if this function will behave the way I'm expecting:
template<
typename... ArgsA, typename... ArgsAInner
, typename... ArgsB, typename... ArgsBInner
> auto my_func(
typename Entity<ArgsA...>::template InnerEntity<ArgsAInner...> A
, typename Entity<ArgsB...>::template InnerEntity<ArgsBInner...> B
) -> tuple<decltype(A), decltype(B)> {
return make_tuple(A, B);
}
I think I have a good grasp on how the parameter packs are being deduced/inferred, and how auto
, decltype
, and the trailing return type are doing their thing, but if I'm mistaken, please let me know how.
Also, if anyone cares to demonstrate a variadic version of this function that can accept any number of the nested variadic class templates and put them into a suitable container or data structure, that'd be great, but I'm primarily concerned with fully understanding typename
and ::template
. Thanks ahead of time!
*If I've worded this title incorrectly or I'm mixing up terms, please explain. :) I'm here to learn.