variadic-templates

Using auto with variadic templates that generates a tuple

佐手、 提交于 2019-12-11 17:06:00
问题 I have been working on this for some time and I found this Q/A as a good answer into how I can store a tuple. Now I'm trying to use a function template that will generate this class and the auto key word to generate instances of this object. I'm not getting any compiler errors; yet it isn't generating any data and I can not figure out where I'm going wrong, however, my ostream<<() is generating compiler errors complaining about std::get Here is my class and a few ways of how I'm trying to use

Which compiler, if any has a bug in parameter pack expansion?

喜欢而已 提交于 2019-12-11 15:35:32
问题 When experimenting with convenient ways to access tuples as containers, I wrote a test program. on clang (3.9.1, and apple clang) it compiles as expected, producing the expected output: 1.1 foo 2 on gcc (5.4, 6.3), it fails to compile: <source>: In lambda function: <source>:14:61: error: parameter packs not expanded with '...': +[](F& f, Tuple& tuple) { f(std::get<Is>(tuple)); }... ^ <source>:14:61: note: 'Is' <source>: In function 'decltype(auto) notstd::make_callers_impl(std::index_sequence

Heterogenous storage of variadic class parameter member variables

China☆狼群 提交于 2019-12-11 14:35:02
问题 I have a variadic class template that is used to create a top-level class for a variable number of classes. Each class that is to go in the top-level class is derived from a base class, as there is common functionality for them. I don't know the best way to store the derived classes in the parent class, but still be able to access the full functionality of the derived class. If I store the variadic args in a vector, they'll all be stored as a base class and I can't access the derived

temporary objects with variadic template arguments; another g++/clang++ difference

徘徊边缘 提交于 2019-12-11 13:33:28
问题 The following code struct foo { foo () { } template <typename T0, typename ... Ts> foo (const T0 & t0, const Ts & ... ts) { foo(ts...); } }; int main() { foo f(1, 2); return 0; } compile without problems with g++ (4.9.2) and give the following errors tmp_002-11,14,gcc,clang.cpp:9:16: error: expected ')' { foo(ts...); } ^ tmp_002-11,14,gcc,clang.cpp:9:13: note: to match this '(' { foo(ts...); } ^ tmp_002-11,14,gcc,clang.cpp:9:14: error: redefinition of 'ts' { foo(ts...); } ^ tmp_002-11,14,gcc

Accessing individual types of variadic templates

自作多情 提交于 2019-12-11 13:26:47
问题 I am creating a lua binding in C++11. I want to process each type in a variadic template. I was thinking I could do something like this, except using Params... represents all of the types inside of it, and not a the next single type inside of it like variadic function parameters do. template <class T, typename ReturnType, typename... Params> struct MemberFunctionWrapper <ReturnType (T::*) (Params...)> { static int CFunctionWrapper (lua_State* luaState) { for(int i = 0; i < sizeof...(Params);

g++ and clang++ different behaviour with variadic container

别来无恙 提交于 2019-12-11 12:19:50
问题 In order to practice with C++11, I'm playing with variadic templates. In particular, I'm playing with a sort of recursive variadic container class ( onion ) and a function that returns the number of template types ( func() ). I came across a case that the clang++ (3.5.0) can't compile while the g++ (4.9.2) compiles and runs with no problems. I have simplified it as follows #include <iostream> template <typename F, typename ... O> struct onion; template <typename F, typename S, typename ... O>

C++ async with variadic template can not find correct function template specialization

时光怂恿深爱的人放手 提交于 2019-12-11 12:16:38
问题 I have a class with a member function f , I wrap it by variadic template and forward to make another member function rf (just add a specific parameter at the end of f to do a little bit different thing). Then, I make another member function async_rf by wrapping rf with async , but it doesn't work. I try to make async_rf by wrapping f with additional specific parameter, and it works. code : #include <future> // std::async, std::future #include <iostream> class test { public: void f(int tmp,

How to pass other template parameter when template class uses parameter pack?

為{幸葍}努か 提交于 2019-12-11 12:12:36
问题 I would like to create template class that implements print() method for each type passed as template parameters. Something like that: class Interface { public: virtual ~Interface() = default; virtual void print(int) = 0; virtual void print(double) = 0; }; X x<int, double, Interface>; class X has public method void print() and it works. The whole code below: #include <iostream> #include <type_traits> struct Printer { void print(int i) {std::cout << i << std::endl; } void print(double d) {std:

Passing multiple std::pair to variadic template constructor using { }, { }

本小妞迷上赌 提交于 2019-12-11 12:03:25
问题 I encountered a problem which i dont really know how to solve. I want to pass variadic ammount of pairs in constructor, using { } braces, but for some reason im gettin compialtion error. I kept class as simple as possible class MyPairs { public: MyPairs(std::pair<char, int>&& pair) { pairs[pair.first] = pair.second; } template <typename ... Args> MyPairs(std::pair<char, int>&& pair, Args&& ... args) { pairs[pair.first] = pair.second; MyPairs(std::forward<Args>(args)...); } private: std::map

C++ - How to introduce overload set from variadic number of bases.

空扰寡人 提交于 2019-12-11 11:56:51
问题 The derived class hides the name of an overload set from the base class if the derived class has the same name defined, but we can always introduce that overload set back with using-declaration: template <class BASE> class A : public BASE { public: using BASE::some_method; void some_method(); } But what if I introduce all overload sets from variadic base classes? Would I be able to write something like this? template <class... BASES> class A : public BASES... { public: using BASES::some