[parameter][mpl] How to do a union of ArgumentPacks?

I would like to call a function using named parameters where I construct the values from two different argument packs. How do I write a function that will generically take the union of all of the named parameters? I am using Intel C++ 11.1 with C++0X features turned on, so 'decltype' and 'auto' are kosher, but not alternative function syntax. Also, the types I might have in the args could be by value or reference or constant reference, so I can't just copy them all by value. Here is a simple example to see what I mean: BOOST_PARAMETER_NAME(name1) BOOST_PARAMETER_NAME(name2) BOOST_PARAMETER_NAME(name3) template<typename ArgPack> double f(const ArgPack& args) { return args[_name1] + args[_name2] + args[_name3]; } //Test using the argpack directly... this works fine. std::cout << f( (_name1 = 1.0, _name2 = 1.0, _name3 = 1.0) ); //Now try to combine them: template<typename ArgPack1, typename ArgPack2> double g(const ArgPack1& args1, const ArgPack2& args2) { return f( parameter_union(args1, args2) ); //HOW DO I WRITE THE parameter_union FUNCTION? } //usage std::cout << g( (_name1 = 1.0, _name2 = 1.0), (_name3 = 1.0) ); Thanks for your help, Jesse

Sorry... looks like I was getting more complicated than necessary with talks of unions, mpl, etc. and suddenly realized what the "," actually does. To answer my own question: template<typename ArgPack1, typename ArgPack2> double g(const ArgPack1& args1, const ArgPack2& args2) { return f( (args1, args2) ); //comma does the union! } //or you can get at the underlying type with decltype as usual. template<typename ArgPack1, typename ArgPack2> double g(const ArgPack1& args1, const ArgPack2& args2) { typedef typename decltype(args1, args2) union_type; union_type args = (args1, args2); return f(args); }
participants (1)
-
Jesse Perla