variadic-templates

Deducing template arguments during partial ordering when parameters are function parameter pack

血红的双手。 提交于 2019-12-30 05:09:06
问题 N4527 14.8.2.4 [temp.deduct.partial] 3 The types used to determine the ordering depend on the context in which the partial ordering is done: (3.1) — In the context of a function call, the types used are those function parameter types for which the function call has arguments. (3.2) — In the context of a call to a conversion function, the return types of the conversion function templates are used. (3.3) — In other contexts (14.5.6.2) the function template’s function type is used. 4 Each type

Problem with calling a variadic function template when passing brace initialiser list arguments

风流意气都作罢 提交于 2019-12-30 03:56:05
问题 Consider this function template: template <class... T> void foo (std::tuple<T, char, double> ... x); This invocation works: using K = std::tuple<int, char, double>; foo ( K{1,'2',3.0}, K{4,'5',6.0}, K{7,'8',9.0} ); This one doesn't: foo ( {1,'2',3.0}, {4,'5',6.0}, {7,'8',9.0} ); (gcc and clang both complain about too many arguments for foo ) Why is the second call a problem? Can I rewrite the declaration of foo so that the second call is also accepted? Thee template parameter T is only used

How to construct a tuple from an array

我是研究僧i 提交于 2019-12-30 03:30:07
问题 I am designing a C++ library that reads a CSV file of reported data from some experiment and does some aggregation and outputs a pgfplots code. I want to make the library as generic and easy to use as possible. I also want to isolate it from the data types that are represented in the CSV file and leave the option to user to parse each column as she desires. I also want to avoid Boost Spirit Qi or other heavy duty parser. The simple solution I have is for the user to create a type for each

Variadic template aliases as template arguments

匆匆过客 提交于 2019-12-30 02:47:12
问题 First some code, then some context, then the question: template <typename T> using id = T; template <template <typename...> class F, typename... T> using apply1 = F <T...>; template <template <typename...> class F> struct apply2 { template <typename... T> using map = F <T...>; }; // ... cout << apply1 <id, int>() << endl; cout << apply2 <id>::map <int>() << endl; Both clang 3.3 and gcc 4.8.1 compile this without error, applying the identity metafunction to int , so both expressions evaluate

Structured bindings width

▼魔方 西西 提交于 2019-12-29 06:59:06
问题 Is it possible to determine how many variable names should I to specify in square brackets using structured bindings syntax to match the number of data members of a plain right hand side struct ? I want to make a part of generic library, which uses structured bindings to decompose arbitrary classes into its constituents. At the moment there is no variadic version of structured bindings (and, I think, cannot be for current syntax proposed), but my first thought is to make a set of overloadings

Eliminate duplicate entries from C++11 variadic template arguments

99封情书 提交于 2019-12-29 03:40:31
问题 I'm using variadic templates with multiple virtual inheritance in C++ to aggregate types into a single structure definition. Here is a sample set of structures: struct meas { int i; }; struct meas2 : public virtual meas { int j; }; struct meas3 : public virtual meas { int k; }; I then aggregate these using multiple virtual inheritance: template <typename... Args> struct zipper : public virtual Args... {}; I can then do: typedef zipper<meas, meas2> meas_type; meas* m = new meas_type; These can

What are the 6 dots in template parameter packs? [duplicate]

 ̄綄美尐妖づ 提交于 2019-12-29 03:15:06
问题 This question already has answers here : What is the meaning of “… …” token? i.e. double ellipsis operator on parameter pack (2 answers) Closed 5 years ago . While looking at this question I found myself in the cpp reference site where I noticed a strange and new to me syntax : template<class Ret, class... Args> struct is_function<Ret(Args......)volatile &&> : std::true_type {}; Yep, 6 dots ! Initially I thought this was a typo, but after checking the libstdc++ source again there it was eg at

How to implement an easy_bind() that automagically inserts implied placeholders?

a 夏天 提交于 2019-12-28 05:40:55
问题 I recently found this nifty snippet on the web - it allows you to bind without having to pass in explicit placeholders: template <typename ReturnType, typename... Args> std::function<ReturnType(Args...)> easy_bind(ReturnType(*MemPtr)(Args...)) { return [=]( Args... args ) -> ReturnType { return (*MemPtr)( args... ); }; } This version works great with no args: auto f1 = easy_bind( (std::string(*)(A&,A&))&Worker::MyFn ); later invoked with: std::string s = f1( *p_a1, *p_a2 ); Question Is it

Generating one class member per variadic template argument

☆樱花仙子☆ 提交于 2019-12-28 05:04:05
问题 I have a template class where each template argument stands for one type of value the internal computation can handle. Templates (instead of function overloading) are needed because the values are passed as boost::any and their types are not clear before runtime. To properly cast to the correct types, I would like to have a member list for each variadic argument type, something like this: template<typename ...AcceptedTypes> // e.g. MyClass<T1, T2> class MyClass { std::vector<T1> m

How to create the Cartesian product of a type list?

江枫思渺然 提交于 2019-12-28 01:57:06
问题 I'd like to create the cross product of a list of types using variadic templates. Here's what I have so far: #include <iostream> #include <typeinfo> #include <cxxabi.h> template<typename...> struct type_list {}; template<typename T1, typename T2> struct type_pair {}; template<typename T, typename... Rest> struct row { typedef type_list<type_pair<T,Rest>...> type; }; template<typename... T> struct cross_product { typedef type_list<typename row<T,T...>::type...> type; }; int main() { int s;