generic member function pointer as a template parameter

You could try something like this: template <typename T, typename R, typename …Args> R proxycall(T & obj, R (T::*mf)(Args…), Args &&… args) { return (obj.*mf)(std::forward<Args>(args)…); } Usage: proxycall(obj, &hello::f); Alternatively, to make the PTMF into a template argument, try specialization: template <typename T, T> struct proxy; template <typename T, typename R, typename …Args, R (T::*mf)(Args…)> … Read more

How to make a variadic is_same?

Nice and concise with C++17: template <class T, class… Ts> struct is_any : std::disjunction<std::is_same<T, Ts>…> {}; And the dual: template <class T, class… Ts> struct are_same : std::conjunction<std::is_same<T, Ts>…> {}; A variation that uses fold expressions: template <class T, class… Ts> struct is_any : std::bool_constant<(std::is_same_v<T, Ts> || …)> {}; template <class T, class… Ts> struct … Read more

details of std::make_index_sequence and std::index_sequence

I see sample code around there, but I really want a dumbed down step by step explanation of how an index_sequence is coded and the meta programming principal in question for each stage. What you ask isn’t exactly trivial to explain… Well… std::index_sequence itself is very simple: is defined as follows template<std::size_t… Ints> using index_sequence … Read more

How can I have multiple parameter packs in a variadic template?

Here is another way to have several parameters packs using template template parameters: #include <iostream> template <typename… Types> struct foo {}; template < typename… Types1, template <typename…> class T , typename… Types2, template <typename…> class V , typename U > void bar(const T<Types1…>&, const V<Types2…>&, const U& u) { std::cout << sizeof…(Types1) << std::endl; std::cout … Read more

Check traits for all variadic template arguments

Define all_true as template <bool…> struct bool_pack; template <bool… v> using all_true = std::is_same<bool_pack<true, v…>, bool_pack<v…, true>>; And rewrite your constructor to // Check convertibility to B&; also, use the fact that getA() is non-const template<typename… Args, typename = std::enable_if_t<all_true<std::is_convertible<Args&, B&>{}…>> C(Args&… args) : member{args.getA()…} {} Alternatively, under C++17, template<typename… Args, typename = std::enable_if_t<(std::is_convertible_v<Args&, B&> … Read more

What is the easiest way to print a variadic parameter pack using std::ostream?

Without recursive calls and commas where you wanted. In c++11 / c++14 through parameter pack expansion: template <typename Arg, typename… Args> void doPrint(std::ostream& out, Arg&& arg, Args&&… args) { out << std::forward<Arg>(arg); using expander = int[]; (void)expander{0, (void(out << ‘,’ << std::forward<Args>(args)), 0)…}; } DEMO In c++17 using fold expressions: template <typename Arg, typename… Args> … Read more