variadic-templates

Point of declaration for variadic template

丶灬走出姿态 提交于 2019-12-24 10:47:29
问题 At what point is a variadic template considered "declared"? This compiles under clang++ 3.4, but not under g++ 4.8.2. template <typename T> const T &sum(const T &v) { return v; } template <typename T, typename ... Ts> auto sum(const T &v, const Ts & ... params) -> decltype(v + sum(params...)); template <typename T, typename ... Ts> auto sum(const T &v, const Ts & ... params) -> decltype(v + sum(params...)) { return v + sum(params...); } int main() { sum(1, 2, 3); } Apparently g++ won't match

Recursively folding a parameter pack to resolve placeholder types

不打扰是莪最后的温柔 提交于 2019-12-24 10:37:49
问题 Notice: Followup to this question After asking this question about parameter pack folding into pairs, I noticed that I need to retain the complete type of the previously folded type as the left pair type. For example: Fold<char, int, long, double> f; must evaluate to std::tuple< std::pair<char , int>, std::pair<std::pair<char, int> /* <-- the previous resulting type */ , long>, std::pair<std::pair<std::pair<char, int>, long> /* the previous type again */ , double> > f; Context to this problem

Class member function template partial specialization with variadic parameters [closed]

限于喜欢 提交于 2019-12-24 10:27:37
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed last year . I'm using Visual Studio 2017 CE version 15.6.2 with compiler language options set to: ISO C++ Latest Draft Standard (/std:c++latest) I'm working with a majority of the functions from <random> and I have 2 classes that are non template classes, RandomEngine and RandomDistribution . These classes can not be

Creating a variant type of all possible map of key-value types at compile time, where the key and value types are specified from a tuple of types

佐手、 提交于 2019-12-24 10:16:38
问题 Currently, I have a variant of map types, where I hard-code all variations of key-value pairs, as such: // for example, if we support std::string and int types as key-value pair using MapCombinator = std::variant< std::map<std::string, std::string>, std::map<std::string, int>, std::map<int, std::string>, std::map<int, int>>; In the real case, I need to support key-value pairs of all fundamental types, in addition to std::string . This is why, I would like to only specify a tuple of types,

Multi patterend varadic templates in C++

会有一股神秘感。 提交于 2019-12-24 07:18:18
问题 I don't think this is possible based on what I've read however I'm hoping someone here may know of some solution that would get this to work. I have a vector (maths) class for C++ template <typename T, size_t N> class vec; And want to create a varadic friend function apply to apply a function to these vectors element-wise i.e. template <typename F, typename ...Args> friend vec<typename std::result_of<pow(Args&&...)>::type, N> apply(F&& f, const vec<Args, N>&... args); which is valid (untested

g++ and clang++ are both bugged with template function parameter pack expansion?

只谈情不闲聊 提交于 2019-12-24 05:32:35
问题 This is a follows up of another question where an answer point my attention to Templates [temp.param] 17.1.17 (last C++17 draft, but I suppose also preceding standardizations) where is stated that A template parameter pack that is a pack expansion shall not expand a parameter pack declared in the same template-parameter-list. with an example of this limitation template <class... T, T... Values> // error: Values expands template type parameter struct static_array; // pack T within the same

Filling a std::tuple

馋奶兔 提交于 2019-12-24 04:01:11
问题 I have a overloaded function which looks like: template<typename T> T getColumn(size_t i); template<> std::string getColumn<std::string>(size_t i) { if(i == 0) return "first"; else return "other"; } template<> int getColumn<int>(size_t i) { return i*10; } // ... Now I want to implement the function template<typename... Values> std::tuple<Values...> getColumns(); Which creates a tuple (for the return value) and calls getColumn for every element of the tuple (saving the return value in that

SFINAE enable_if for variadic perfect forwarding template on reference/pointer const-ness

ぃ、小莉子 提交于 2019-12-24 03:52:07
问题 I want to create a variadic perfect-forwarding make_shared<T> wrapper, but one which is SFINAEd on whether the constructor of T takes any non-const reference/pointer arguments. The idea is to have two wrappers, called construct and construct_nonconst , where when constructing a Foo(int& r) or Foo(int* r) , one is obliged to use the latter. The purpose of this is so that when developers write classes whose constructors require non-const parameters, they can do so, but it clearly shows up at

Implementing a function that perfect-forwards to std::thread

丶灬走出姿态 提交于 2019-12-24 02:33:44
问题 I am trying to write a wrapper around std::thread : #include <thread> #include <iostream> struct A {}; template <typename F, typename... Args> void lifted_lambda_1(void *m, F &&entrypoint, Args&&... args) { std::cout << "I will do something with the void * " << m << std::endl; entrypoint(std::forward<Args>(args)...); } template <typename F, typename... Args> void make_thread(void *p, F &&f, Args && ... args) { std::thread(lifted_lambda_1<typename std::decay<F>::type, Args...>, p, std::forward

Implementing a function that perfect-forwards to std::thread

孤者浪人 提交于 2019-12-24 02:33:25
问题 I am trying to write a wrapper around std::thread : #include <thread> #include <iostream> struct A {}; template <typename F, typename... Args> void lifted_lambda_1(void *m, F &&entrypoint, Args&&... args) { std::cout << "I will do something with the void * " << m << std::endl; entrypoint(std::forward<Args>(args)...); } template <typename F, typename... Args> void make_thread(void *p, F &&f, Args && ... args) { std::thread(lifted_lambda_1<typename std::decay<F>::type, Args...>, p, std::forward