variadic-templates

Is it possible to “store” a template parameter pack without expanding it?

≡放荡痞女 提交于 2019-12-28 01:42:39
问题 I was experimenting with C++0x variadic templates when I stumbled upon this issue: template < typename ...Args > struct identities { typedef Args type; //compile error: "parameter packs not expanded with '...' }; //The following code just shows an example of potential use, but has no relation //with what I am actually trying to achieve. template < typename T > struct convert_in_tuple { typedef std::tuple< typename T::type... > type; }; typedef convert_in_tuple< identities< int, float > >:

Is it legit to specialize variadic template class inside other template class

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-25 07:26:02
问题 Consider a code: #include <iostream> template <class T> struct outer { template <class... Args> struct inner { static constexpr bool value = false; }; template <class... Other> struct inner<T, Other...> { static constexpr bool value = true; }; }; int main() { std::cout << outer<int>::inner<int, void>::value << std::endl; }; It does compile in both g++ and clang++ but I am not convinced it is legal. As far as I know one cannot for example specialize template method for template class if not

Specializing and or Overloading member function templates with variadic parameters

淺唱寂寞╮ 提交于 2019-12-25 01:48:54
问题 Trying to resolve overload resolution for class member: static function template overload - partial specialization. I currently have a class declared / defined as such: Note: my use of Param a , Param b , Param c etc. are not related to the actual declarations / definitions directly. These can be any arbitrary type that is passed into the functions for example: it could be int a , enum b , char c . I'm just using this to only show the pattern of the declarations, however all of the different

Extending Multi patterned variadic templates in C++

拈花ヽ惹草 提交于 2019-12-24 23:06:39
问题 This question is a follow on from my previous question Multi patterned varadic templates in C++ to which I received the solution: #include <array> #include <iostream> #include <type_traits> template <typename T, std::size_t N> class Vec; template <std::size_t, typename ...> struct dimVec; // ground case for no Vecs: unimplemented for SFINAE failure ! template <> struct dimVec<0U>; // ground case with one or more Vecs: size fixed template <std::size_t N> struct dimVec<N> : public std::integral

C++ template - variadic templates & pass by const reference

允我心安 提交于 2019-12-24 17:25:31
问题 I have a ThreadPool class with an enqueue function: class ThreadPool { public: //(Code removed here) template <typename ... Args, typename Fun> JobId enqueue(Fun func, Args ... args); //(Code removed here) } And I use it on these non static member function loadStuff on class Object : class Object { //(Code removed here) void init(const PrepareData & prepareData); virtual bool loadStuff(const PrepareData & prepareData); //(Code removed here) } by calling in QObject::init : void QObject::init

Visual Studio 2017 - could not deduce template argument (with variadic templates)

纵然是瞬间 提交于 2019-12-24 17:22:50
问题 The following code compiles and works fine in gcc and clang, but fails to compile in Visual Studio 2017.7 (x86-64): #include <vector> #include <iostream> #include <type_traits> template <template <typename...> class> struct isVector : public std::false_type { }; template <> struct isVector<std::vector> : public std::true_type { }; // Other isVector specializations (for QVector<T>, etc...) // ... // A function accepting vector<vector<double>> template < template<typename ...> class V1,

Transform a variadic pack of types into values?

痴心易碎 提交于 2019-12-24 15:41:18
问题 I have some function template<typename T> constexpr Foo make_foo<T>(); which essentially maps types to instances of Foo with no side-effects. Now, I want to write the function magic , template<typename Types...> vector<Foo> magic(); which does the same as make_foo, but for variadic parameter packs; and in a way which it would then be easy for me to, say, stream all these Foo's to std::cout, or to iterate over them in a loop etc. I realize this question is not entirely well-defined, since I'm

Check that signature of two functions or member function pointer equal

三世轮回 提交于 2019-12-24 14:03:12
问题 I write some code for check that signature of free function is equal to signature of member function, etc. It compare extracted return type and function arguments: #include <tuple> #include <type_traits> template<class Signature> struct signature_trait; template<class R, class... Args> struct signature_trait<R(Args...)> { using return_type = R; using arg_types = std::tuple<Args...>; }; template<class R, class... Args> struct signature_trait<R(*)(Args...)> { using return_type = R; using arg

Variadic template trouble matching const and non-const std::string

白昼怎懂夜的黑 提交于 2019-12-24 13:04:43
问题 I'm having trouble constructing a variadic template where the expansion functions properly match both a non-const and const std::string . I have a generic matching function which is called instead in some cases. I've reduced the code to the below example. Things which aren't a string should end up at the generic function. Things which are a string should end up at the second function which additionally outputs "STRING". #include <iostream> #include <string> template<typename X, typename T>

Visual Studio 2012 Update 3 - initializer list & variadic templates

一世执手 提交于 2019-12-24 12:13:42
问题 Recently I have installed Visual Studio 2012. After the installation I updated my IDE with update 3 to guarantee functionality of my programs on Windows XP. Everything is working well, but I still can not use initializer list and variadic templates! Do I need any extra updates to get this working with Visual Studio 2012? 回答1: VS2012 does not support variadic templates and initializer lists, even with the latest updates. VS2013 RC, however, supports both. For a full overview of what C++11