Category : variadic-templates

I have a class A with multiple overloads of a method open (all with variadic templates): class A { template<typename… Args> bool open(int, Args…); template<typename… Args> bool open(int, string, Args…); template<typename… Args> bool open(int, string, char, Args…); } Then I have a class B, which has a member A, and must support all the overloads ..

Read more

Given a variadic class template, how can I call a variadic function template with the template parameters of that class? Example: template <typename T0,typename… Ts> void test_variadic() { std::cout<<typeid(T0).name()<<std::endl; if constexpr (sizeof…(Ts) > 0) test_variadic<Ts…>(); } template<typename T> // T is variadic class template void f0() { // test_variadic<T…>(); // Call ‘test_variadic’ with underlying template ..

Read more

I need to convert elements of a std::vector to types based on a template parameter and call a function with these parameters. In pseudocode: template <typename T…> void foo(std::vector<std::string> v) { if (v.size() != sizeof…(T)) throw std::runtime_error("Bad"); bar(convert<T0>(v[0]), convert<T1>(v[1]), …, convert<Tn>(v[n])); } My problem is how to obtain the element indices from the parameter pack, ..

Read more

So I wonder given a variadic template function like following: template<typename…Fs> parse(int x, Fs…funcs); Where we ensure (through C++20 concept) that is convertible to std::function<double(int)>. Could we use unfold it into another functions argument, like passing to following one: template<typename…Ts> test(Ts…args); Where again we ensure all Ts is and must be able to convertdouble. What ..

Read more

Currently, I have an implementation like this in order to transform all values of a tuple using a function bar() that takes in each element of the tuple. template<typename … Args> void foo(const std::tuple<Args…>& a) { std::tuple<Args…> transformedTuple = std::make_tuple(bar(std::get<Args>(a))…); } The problem with this is that this will no longer work if Args contains ..

Read more

Context: Trying to create a class to unpack a tuple (used to store variadic template arguments). Inspired by this answer https://stackoverflow.com/a/24804339/11510510 I have something that does the job. (I’m restricted to c++11 if not I would be using std::apply from C++17) Problem: It only compiles when the object is created by using the specific type ..

Read more