variadic-templates

std::bind with variadic template and auto return type

旧时模样 提交于 2021-02-08 18:47:43
问题 Following the code in this question, I have a std::bind with a variadic template function. If I try to provide a function template with auto return, gcc rejects the program: #include <functional> template <typename... Args auto inv_impl(Args... a) { return (a + ...); } template <typename... Args> auto inv(Args... args) { auto bound = std::bind(&inv_impl<Args...>, args...); return bound; } int main() { auto b = inv(1, 2); } The compile error is: foo.cc: In instantiation of ‘auto inv(Args ...)

std::bind with variadic template and auto return type

你说的曾经没有我的故事 提交于 2021-02-08 18:40:19
问题 Following the code in this question, I have a std::bind with a variadic template function. If I try to provide a function template with auto return, gcc rejects the program: #include <functional> template <typename... Args auto inv_impl(Args... a) { return (a + ...); } template <typename... Args> auto inv(Args... args) { auto bound = std::bind(&inv_impl<Args...>, args...); return bound; } int main() { auto b = inv(1, 2); } The compile error is: foo.cc: In instantiation of ‘auto inv(Args ...)

std::bind with variadic template and auto return type

久未见 提交于 2021-02-08 18:37:58
问题 Following the code in this question, I have a std::bind with a variadic template function. If I try to provide a function template with auto return, gcc rejects the program: #include <functional> template <typename... Args auto inv_impl(Args... a) { return (a + ...); } template <typename... Args> auto inv(Args... args) { auto bound = std::bind(&inv_impl<Args...>, args...); return bound; } int main() { auto b = inv(1, 2); } The compile error is: foo.cc: In instantiation of ‘auto inv(Args ...)

std::bind with variadic template and auto return type

痞子三分冷 提交于 2021-02-08 18:36:52
问题 Following the code in this question, I have a std::bind with a variadic template function. If I try to provide a function template with auto return, gcc rejects the program: #include <functional> template <typename... Args auto inv_impl(Args... a) { return (a + ...); } template <typename... Args> auto inv(Args... args) { auto bound = std::bind(&inv_impl<Args...>, args...); return bound; } int main() { auto b = inv(1, 2); } The compile error is: foo.cc: In instantiation of ‘auto inv(Args ...)

std::bind with variadic template and auto return type

扶醉桌前 提交于 2021-02-08 18:35:47
问题 Following the code in this question, I have a std::bind with a variadic template function. If I try to provide a function template with auto return, gcc rejects the program: #include <functional> template <typename... Args auto inv_impl(Args... a) { return (a + ...); } template <typename... Args> auto inv(Args... args) { auto bound = std::bind(&inv_impl<Args...>, args...); return bound; } int main() { auto b = inv(1, 2); } The compile error is: foo.cc: In instantiation of ‘auto inv(Args ...)

Mixing pass-by-reference and pass-by-value to variadic template function valid?

此生再无相见时 提交于 2021-02-08 14:11:27
问题 I have a method which allocates memory for a object and then calls its constructor - a memory allocator. template <class T, typename... Arguments> inline T* AllocateObject(Arguments... args) { return new (InternalAllocate(sizeof(T))) T(args...); } Is it valid using this function to mix pass-by-value and pass-by-reference? For example allocating a class with a constructor with some by-value and some by-reference. It compiles, but I'm not sure if it has any nasty side-effects or not. 回答1: What

Mixing pass-by-reference and pass-by-value to variadic template function valid?

故事扮演 提交于 2021-02-08 14:05:46
问题 I have a method which allocates memory for a object and then calls its constructor - a memory allocator. template <class T, typename... Arguments> inline T* AllocateObject(Arguments... args) { return new (InternalAllocate(sizeof(T))) T(args...); } Is it valid using this function to mix pass-by-value and pass-by-reference? For example allocating a class with a constructor with some by-value and some by-reference. It compiles, but I'm not sure if it has any nasty side-effects or not. 回答1: What

initialize double nested std::array from variadic template array reference constructor

佐手、 提交于 2021-02-08 11:30:25
问题 Problem I have a Matrix class that is able to do some math. It holds its data in a double nested std::array as a variable. I have a constructor that takes an array reference as a variadic template. I did this so i could add some SFINAE more easily (omitted here). #include <array> template <std::size_t N, std::size_t M, typename T> class Matrix{ public: template <typename... TArgs> Matrix(TArgs const(&&... rows)[M]) { // ?? } // ... private: std::array<std::array<T,M>, N> data; }; Question How

Create a compile time key-to-type map which is filled by calls to a variadic function

懵懂的女人 提交于 2021-02-08 11:20:44
问题 Is it possible to create a key->type map at compile time, with each key-value being added when an instance of a variadic function is called? template <typename T, typename ... Args> void writeToQueue(Args... args) { //Do something with args. // Insert to map. something akin to: // CODEMAP[T] = Args... // T -> Args... mapped when foo<T,Args...> is called. } Or template <int code, typename ... Args> void writeToQueue(Args... args) { //Do something with args. // Insert to map. something akin to:

Does virtual inheritance force a base class to be default constructible?

邮差的信 提交于 2021-02-07 13:17:11
问题 In the following code, the compiler is requesting the base class X to be default constructible . However, if I remove the virtual keyword from the inheritance of the class Node , the access to the member m_x becomes, of course, ambiguous, but the default constructor for class X is no longer required. What is the reason for that? #include <iostream> struct Apply { template< typename T > struct Node : virtual T // this line contains the virtual inheritance { template< typename ...Args> Node(