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

C2977: ‘std::tuple’ : too many template arguments (MSVC11)

Check out this entry in the msdn blog. VC++11 doesn’t have support for variadic templates. They have something they call faux variadics. Scroll down and you will see a paragraph on Faux variadics that talks about tuples. On that paragraph they say the default maximum number of parameters is 5. You can increase it to … Read more

How can I check type T is among parameter pack Ts…?

In your own implementation, one issue is that C++ doesn’t allow partial specialization on function templates. You can use the fold expression (which is introduced in C++17) instead of recursive function call. template<class T1, class… Ts> constexpr bool is_one_of() noexcept { return (std::is_same_v<T1, Ts> || …); } If you are using C++11 where fold expression … Read more

Is there a name for this tuple-creation idiom?

I think this is a subtle implementation of a Monad-like thing, specifically something in the same spirit of the continuation monad. Monads are a functional programming construction used to simulate state between different steps of a computation (Remember that a functional language is stateless). What a monad does is to chain different functions, creating a … Read more

Generating one class member per variadic template argument

As you have already been hinted, the best way is to use a tuple: template<typename …AcceptedTypes> // e.g. MyClass<T1, T2> class MyClass { std::tuple<std::vector<AcceptedTypes>…> vectors; }; This is the only way to multiply the “fields” because you cannot magically make it spell up the field names. Another important thing may be to get some named … 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

C++ variadic template template argument that matches any kind of parameters

Your interesting construct has two levels with variadic templates. An outer variadic template parameter list TemplateP & Sizes for a function template An inner parameter pack as the template parameters of your template template parameter TemplateT, a class template First, let’s look at the inner TemplateT class: why can the ellipsis operator not not match … Read more

Partial specialization of variadic templates

14.8.2.4, section 11 (I refer to draft N3242). In most cases, all template parameters must have values in order for deduction to succeed, but for partial ordering purposes a template parameter may remain without a value provided it is not used in the types being used for partial ordering. [ Note: A template parameter used … Read more

How do I get the argument types of a function pointer in a variadic template class?

You can write function_traits class as shown below, to discover the argument types, return type, and number of arguments: template<typename T> struct function_traits; template<typename R, typename …Args> struct function_traits<std::function<R(Args…)>> { static const size_t nargs = sizeof…(Args); typedef R result_type; template <size_t i> struct arg { typedef typename std::tuple_element<i, std::tuple<Args…>>::type type; }; }; Test code: struct … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)