Parameter packages cannot be easily saved , so I donβt think you can do what you want. However, since you seem to need this function to inherit from a set of bases, you can use metaprogramming of several templates to create a base type linearly inherited from all the bases in your set. Prior to this, you can easily filter duplicates from the options package.
Here is an implementation of this approach using Boost.MPL :
#include <boost/mpl/fold.hpp> #include <boost/mpl/inherit.hpp> #include <boost/mpl/inherit_linearly.hpp> #include <boost/mpl/insert.hpp> #include <boost/mpl/placeholders.hpp> #include <boost/mpl/set.hpp> #include <boost/mpl/vector.hpp> namespace mpl = boost::mpl; template < typename ...Args > struct inherit_uniquely { // filter out duplicates typedef typename mpl::fold< mpl::vector< Args... >, mpl::set0<>, mpl::insert< mpl::_1, mpl::_2 > >::type unique_bases; // create base type typedef typename mpl::inherit_linearly< unique_bases, mpl::inherit< mpl::_1, mpl::_2 > >::type type; }; template < typename ...Bases > struct Derived : inherit_uniquely< Bases... >::type {}; struct X { int x;}; struct Y { int y;}; struct Z { int z;}; int main() { Derived< X, Y, Z > d; dx = 1; dy = 2; dz = 3; X & d_as_x = d; Y & d_as_y = d; Z & d_as_z = d; }
source share