Questions tagged [variadic-templates]

Variadic templates are templates that take a variable number of parameters.

Some programming languages, like D and C++ since with the C++11 standard, support templates that take a variable number of parameters. Variadic templates are useful in a number of situations, for example, defining type-safe heterogeneous containers such as tuples and expanded metaprogramming library facilities.

http://en.wikipedia.org/wiki/Variadic_templates

3928 questions
3
votes
1 answer

compile error on variadic template function parameter

I'm trying to write some parameter wrapping helper code like below #include #include struct test{}; namespace ns { struct test{}; } template struct arg_wrapper; template<> struct arg_wrapper { …
summerlight
  • 882
  • 7
  • 16
3
votes
3 answers

Computing a function over variadic templates

I am trying to figure out which is the most idiomatic way implement a function over a variadic type list. For example, computing the maximum size of all the types. I understand there exist several approaches to accomplish such a task, but I would…
mavam
  • 12,242
  • 10
  • 53
  • 87
3
votes
1 answer

C++11 std::tuple to std::array conversion causes variadic template crash

The following function, toArray, might one day convert a C++11 std::tuple into a C++11 std::array: #include #include template std::array toArray(std::tuple) { return…
user2023370
  • 10,488
  • 6
  • 50
  • 83
3
votes
2 answers

How to program this with variadic templates?

I have never used variadic templates myself, but think I could need them now. Suppose I have a class class A { int Kern; template void func_a(int, double) const; template void func_b(double, double, char) const; template
Walter
  • 44,150
  • 20
  • 113
  • 196
3
votes
1 answer

Construct a variadic template of unsigned int recursively

I need a tricky thing in a C++ 2011 code. Currently, I have a metafunction of this kind : template static constexpr unsigned int myFunction() This function can generate number based on N and M. I would like to write…
Vincent
  • 57,703
  • 61
  • 205
  • 388
3
votes
2 answers

Friend function with CRTP + enable_if is not working?

The following code does not compile and I don't know why: #include // Base class definition template class CRTP, typename T> class Base { // Friend function declaration public: …
Vincent
  • 57,703
  • 61
  • 205
  • 388
3
votes
2 answers

std::tuple to member functions

I'm still trying to get the swing of metaprogramming, and I'm stumped. What's I'd like to do is create a class/struct/whatever, supply it a std::tuple and have it automatically generate member functions based on the object types in the tuple. The…
3
votes
1 answer

How do I use values from an std::tuple as function arguments?

#include class Foo { public: Foo(int i, double d, const char* str) { } }; template class ObjectMaker { public: ObjectMaker(CtorArgTypes... ctorArgs) : m_ctorArgs(ctorArgs...) { } Foo*…
Mark
  • 2,082
  • 3
  • 17
  • 30
3
votes
2 answers

Recursive metafunction using variadic templates

I am writing a meta function replace_type that is supposed to replace all matches of type X in a compound type C with Y. I am currently working on properly getting this to work with callables in C. This works: template replace_type< …
nikolas
  • 8,707
  • 9
  • 50
  • 70
2
votes
2 answers

Variadic Template lambda expansion

I'm trying to implement a delegate class following Herb Sutter's Example. There is a sections in this article that duplicates several templates; one template for the number of arguments in the list (Example 7, lines 41 - 59)1. I'm trying to replace…
Jeremy W
  • 23
  • 3
2
votes
3 answers

How do I change the number of template arguments supported by MSVC++'s std::tuple?

MSVC++ doesn't yet support variadic templates, so its standard library "fakes" these for classes like std::tuple through use of macros. I recently tried compiling one of my projects with the VC11 beta, and got this to show for…
Billy ONeal
  • 104,103
  • 58
  • 317
  • 552
2
votes
1 answer

Reference counting with a generic intrusive pointer client

Introduction Peter Weinhart describes how to design a generic intrusive_ptr base class using CRTP, which may be used as follows: class foo : intrusive_base { // foo-specific code. }; This approach imposes the constraint that all foo…
mavam
  • 12,242
  • 10
  • 53
  • 87
2
votes
1 answer

Wrap Loki::Typelist with C++11 variadic template

I am trying to avoid LOKI_TYPELIST_n macros, so I though I can write simple Loki::Typelist wrapper. template struct TYPELIST; template <> struct TYPELIST<> { typedef Loki::NullType Result; }; template
Dragomir Ivanov
  • 534
  • 8
  • 19
2
votes
2 answers

Nested template specialization depending on enclosing template parameters

template < int ...Indices> class T1 { template class T2; }; template template class T1::T2<_1, sizeof...(Indices)> {}; //^--error: non-type template argument depends on a template…
2
votes
1 answer

How can I get the first N elements of a tuple c++?

lets say I had a function like the following, how could I get the first n elements of a tuple? template void foo(Ts... ts){ std::tuple all_elements(ts...); auto first_elements = //the first N elements of the…
1 2 3
99
100