I have a bunch of structs like this with increasing number of members, but consistent member naming:
struct one { int a; };
struct two { int a; int b; };
struct three { int a; int b; int c; };
I also have a templated function which I want to have accept one of these struct's members, splatted:
template <typename T, typename ... ARGS> // T will be one, two, or three
void func(ARGS... args); // This should take 1, 2, or 3, int arguments respectively
I want to be able to call this something like:
two foo;
func<two>(splatter(foo));
Where splatter
would somehow split foo
so that it would resolve to func<two>(foo.a, foo.b)
.
I can obviously just expand this inline, without splatter
, but the code in which I call func
is itself happily templated. I've tried using an initializer_list
but I can't figure out how to build one based on template type alone.
Unfortunately my compiler also doesn't support constexpr if
to splat a call to func
or build an initializer_list
. Are there any other options available to me?
std::tuple
as well from a paremeter pack to astd::tuple
. But to access members of astd::tuple
you need to use compile-time constants, you can't easily iterate over the "elements" of the tuple. – Bareillyfoo<D>
with an array member of sizeD
and some free functionsa(foo)
,b(foo)
? – Impetus