I'm trying to forward a series of parameters to two different mixin classes as follows:
template <typename... Checkers>
class Checker : public Checkers... {
public:
template<typename... Args>
Checker(Args&&... args) : Checkers(std::forward<Args>(args))... { }
};
template <typename... Handlers>
class Handler : public Handlers... {
public:
template <typename... Args>
Handler(Args&&... args) : Handlers(std::forward<Args>(args))... { }
};
template <typename C, typename H>
class Tester : public C, H {
public:
template <typename... ArgC, typename... ArgH>
Tester(std::tuple<ArgC...>&& argc, ArgH&&... argh) : C(argc), H(argh...) {
}
};
Checker and Handler are two different collections of Mixin classes with different requirements for each but shared requirements for all members. I realize I can't do a double variadic construction in Tester (the compiler can't deduce where to split the arguments so passes them all to Handler and none to Checker) so I pass the Checker arguments in a Tuple and the Handler arguments in a variadic list. The problem is, Checker's constructor is responsible for forwarding those parameters to its bases. Handler can do it because Handler's constructor is a variadic list, but Checker gets a tuple but you can't for-each forward a tuple's elements like forward can a variadic parameter list.
Any advice would be greatly appreciated. Thanks.
Additional
A solution would be to either a) unpack argc
into Checker
's variadic constructor or b) Make Checker
's constructor take a tuple and then somehow forward each element of that tuple to each of Checker
's mixin bases, Checkers...
. I realize std::pair
has a trick for forwarding a tuple as a fixed argument list to it's types, such as a 3-parametered std::vector
constructor using the std::piecewise_construct
type marker to inform it to do the unpack, but I don't see how this can be applied here. I looked at GCC 4.8.1's implementation of std::pair
with std::piecewise_construct
and couldn't figure it out. I read some of the older, pre-C++11 books on template metaprogramming (Modern C++ Design and C++ Template Metaprogramming, for example) but I'm at a loss here now that there's a standard and I'm trying to avoid Boost and Loki.
Additional
Must conform to at least GCC 4.7.2. The solution I found based on std::pair
requires Constructor Inheritance, which didn't become available until GCC 4.8.1 which isn't supported on my build system.
Additional
Although GCC 4.6.3 support would be nice, Delegated Constructors were added in 4.7.2 so I should have access to that language feature.