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

3375 questions
2
votes
1 answer

Get argument type of lambda with auto specifier

I have a meta function which gives me the type of the I-th argument of a lambda/function: #include #include namespace details { //! Spezialization for Funktion-Pointers template
2
votes
1 answer

Get tuple of inherited base classes' types

I was looking for a way to get a tuple pack of all the inherited classes, couldn't find one. Intend: I need to statically assert if a class inherits from a template base class. Template parameter is to be deduced from a specialization of a base…
Sergey Kolesnik
  • 1,161
  • 5
  • 15
2
votes
1 answer

Building a variadic template class with a set of function overloads based on the template arguments?

Motivation: I need to build a base class for a C++17 library that will have overloads for a virtual function based on types that the user identifies at compile time. Basically, when a particular overload of the function is called on the base class,…
Charles Ofria
  • 1,826
  • 12
  • 22
2
votes
2 answers

С++ variadic templates: implement variadic functor

My colleague provided me with a "small quiz", that he made his students solve once. It seems that my feeble mind is just unable to comprehend all the beauty of the modern C++ capabilities. Subj: Implementing a join function, accepting arbitrary…
MasterAler
  • 1,245
  • 2
  • 18
  • 24
2
votes
2 answers

generate lambdas body (that invokes a callable and returns) depending on template type

I have a callable object that might return bool or void. This object needs to be wrapped in a lambda. This lambda should always return bool. If the callable object returns bool then lambda return whatever is returned by the object. Otherwise (if…
Peregrin
  • 386
  • 2
  • 10
2
votes
3 answers

Deferred make_unique with variadic templates

I need a class which will work as a deferred factory, saving the parameters to create another class and invoking make_unique later in time. So far I'm not having any luck getting a variadic template version to work. Any help would be appreciated…
Lazward
  • 205
  • 2
  • 8
2
votes
2 answers

How to "iterate" over a list of templates at compile time?

This is the extraction of a follow-up question to this answer. Given the following "loop" technique #pragma once // loop.hpp #include #include template void…
2
votes
1 answer

Templated runtime-checked invoke wrapper to detect cast overflows in input arguments or return value

The problem I need a checked_cast_call generic wrapper to a function, that would runtime-check any cast involved to call the function, or to get the value. As an example, calling the following function with an input buffer larger than 2GB…
xroche
  • 209
  • 2
  • 7
2
votes
1 answer

declare function pointer in templated class from template arguments

I am trying to declare function pointer from template argument of function prototype template class DllFunction { public: ReturnType (*fptr_)(Args...); }; DllFunction f; but I get this error:…
2
votes
2 answers

How to execute all functions from crtp base classes in a variadic derived class?

I have a CRTP derived class that is a variadic template of all the CRTP base classes it could inherit. I want to execute a function from every inherited class (in this example the print function) in a method of the derived class (the printAll…
hampeluzzi
  • 103
  • 5
2
votes
1 answer

c++11 variadic template fail to compile

Just a few lines of code, I wish "count" function will give the number of parameters: #include #include using namespace std; template size_t f(T&& ... elem){ return sizeof...(elem); } int main(){ return 0; } But…
Hind Forsum
  • 8,077
  • 8
  • 40
  • 88
2
votes
1 answer

variadic templates and initializer lists type narrowing differences

So this does not make any sense. With this class: template< typename T, int nDimensions = 2 > class Vec { private: std::array< T, nDimensions > elements_; public: typedef T ValueType; Vec() : elements_() {} template Vec(U... ts)…
Steven Venham
  • 526
  • 1
  • 3
  • 16
2
votes
1 answer

GCC does not disable a function based on SFINAE rules

On compiling the following Try it out on Coliru!, I was expecting that GCC does not consider the function template std::enable_if_t CheckAndSetVal(DST&) {} for analysis because the sizeof…
lightsunray
  • 329
  • 1
  • 11
2
votes
1 answer

clang: candidate template ignored: substitution failure: typedef 'type' cannot be referenced with a class specifier

In contrast to GCC 5, Clang 6 complains about the following error: candidate template ignored: substitution failure [with U = char, Us = ]: typedef 'type' cannot be referenced with a class specifier Tuple(U&& u, Us&&... rest) :…
2
votes
2 answers

In C++, can you compare templates the way you can compare types?

I had an idea for a template comparator analogous to std::is_same. If two templates are the same, then at least their instantiations given template arguments will be the same. template class LHS, template class RHS,…
John P
  • 1,060
  • 2
  • 14
  • 33
1 2 3
99
100