variadic-templates's questions - English 1answer

2.251 variadic-templates questions.

What is the easiest way to print a parameter pack, separated by commas, using std::ostream? Example: template<typename... Args> void doPrint(std::ostream& out, Args... args){ out <&...

I have the following structs: struct s0 { char name[64]; s0* parent; int stackLevel; s0(s0* parent_, char* nameMask_, ...){ va_list args; va_start(args, nameMask_); ...

What is the best way to generate a specialization for a (class) template which accepts variadic template arguments. In my usecase I have a class which accepts a number of integers and I want a ...

In C++ is it possible to define multiple methods based of the number of template parameters provided? Similar to how variadic functions work? With functions I can do template <class ...Args> ...

I'm working with the Node.js N-API and I'm making a little wrapper that will make exporting C++ functions easy. template<class T, class... Targs> napi_value Api::create(const char* name, T (* ...

I study the generic lambdas, and slightly modified the example, so my lambda should capture the upper lambda's variadic parameter pack. So basically what is given to upper lambda as (auto&&...)...

I have a class Door that implements a method LockCheck(), and a class Stove with a method BurnerCheck(). I want a class House that takes as a constructor argument either Door::LockCheck or Stove::...

Instead of creating vectors like this: std::vector<int> v1{1,2,3}; std::vector<double> v2{1.1,2.2,3.3}; std::vector<Object> v3{Object{},Object{},Object{}}; I'd like ...

I'm trying to use inheritance with variadic templates. First, consider the following snippet as a skeleton I'd like to build upon. #include <type_traits> #include <iostream> template <...

I'd like to write a constexpr template function that permutes elements of an array passed in as a parameter. So I've come up with something like this: template <typename T, std::size_t N, typename....

I have written a class multi_array which is sort of an extension of std::array to multiple dimensions. template <typename T, std::size_t... N> class multi_array { template <std::size_t......

I successfully implemented my own thread_pool class where I can submit lambdas that can return any value but can only take zero arguments. I would like to improve it, such that it can work like std::...

I am not able to pass an initializer list to a templated function, to then call a non templated function which would coerce the initializer list to a container. However, when skipping the intermediate ...

I go through the book C++ template unique quide and I try to understand how the deduction guides for std::array works. Regarding the definition of the standard the following is the declaration ...

I am trying to find the sum of squares using variadic templates. The input parameters are the numbers whose sum of squares need to be calculated. Ex: foo(2, 3, 4) should return a value of 27 (which is ...

I need a Register some functions with variadic templates like std::function<R(Args...)>; so i can register class member functions like this: std::function<void(std::string)> F1 = [this]...

I have a template function and I want to use it with its template parameters been auto deduced. It works well but now I need its ptr to be used in std::bind. It's something like this: class A{}; ...

The following code compiles and runs ok. void foo() { } template <typename T, typename... Args> void foo(T x, Args... args) { cout << x << endl; foo(args...); } // inside ...

I bang my head against the following code: template<class... Ts> struct typelist{}; template<class S> struct Fun; template<template<class...> class S, class... Ts> struct ...

I'm trying to set the values of objects referred to in a tuple of references, but having trouble getting the unpacking syntax right. namespace detail { template<class... Types, std::size_t... Is&...

Suppose I have some types class A {…}; class B {…}; class C {…}; ... And I have some other classes that does various things on objects of these types class process1 { public: void do_stuff(std::...

I want to write a function that accepts a variable number of string literals. If I was writing in C, I would have to write something like: void foo(const char *first, ...); and then the call would ...

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 <...

I have an annoying scenario where I need to defer the initialization of some object state and allow the user to construct one on demand. E.g. // user code context c; // ...do something... c....

Consider the following attempt to emplace an empty vector with a numeric key in a map: #include <map> #include <vector> int main () { std::map<size_t, std::vector<size_t>>...

Im currently implementing a generic event class. Event handlers have a sender parameter and a variable number of event args. So the declaration of the event class is as bellow: template<typename ...

Is there a way to decay all types in variable template argument pack into their value types? For example: template < typename... T > void foo( T... ts ) // I do not want to have references ...

So I gave this program to g++ and clang (both on Linux, x86_64): #include <iostream> using namespace std; template<char... Cs> struct A { static const string s; static A a; ~A() { ...

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 <...

I'm trying to reverse the order of a template-variadic std::size_t parameter sequence, based on an answer found in a previous thread. But for some reason it doesn't work. Here's a regular variadic ...

The title is bad but I couldn't come up with anything better. Feel free to change it. Here's a template multidimensional array class that I'm currently working on. I'm trying to optimise it as much ...

Background: I have a function that I wrote that takes some callable object and a tuple, and unpacks the tuple into the a parameter pack that can be passed to the function. You can probably imagine ...

I'm experiencing some strange occurrences regarding varidaic templates that I never saw before. In order to keep it simple i'll give a simple example of what I was trying to achieve, the real code is ...

Hi I want to use fold expressions , operator but MSVC keeps annoying me with C1026->Program is to complex. I have broken down the problem to minimal example: #include <utility> #include <...

I know I could do that with a regular variadic function, but I would like to do that with templates. My (C++17) compiler would not agree to it. #include <cstdint> unsigned int fct(unsigned int ...

I have template class which looks like this: template<typename... Args> class Foo { public: void Bar() { (std::get<Args>(m_args).Bar(), ...); } private: std::tuple<...

I'm playing with C++11's variadic templates, and here is my code: #include "iostream" void func(){ std::cout << std::endl; } template< typename ...Params> void func(int x, Params... ...

One trick often used to perform a variadic parameter expansion is using an un-sized array typedef in combination with the comma operator, like below: #include <iostream> template<typename......

How to write this function used in finding a series of elements in an array? I’ve written a function named find that is used in finding an element whether is in an array or not. Now I want to used ...

The code: #include <functional> #include <type_traits> namespace impl { // lame recursive implementation template<typename Functor, Functor F, typename T, T OneValue, T ...

I am trying to create a Recursive Function in a factory pattern that iterates through a std::tuple with a variable number of elements. I have created my ConsoleShapeFactory like this: template<...

Below is a example (not the entire class, just relevant parts) class Container { private: size_t m_next_id; std::unordered_map m_objects; public: template<typename Type, typename... ...

I have a large number of subclasses which subscribe to various events such as initialization and entity deletion. Currently I solve this by doing class A{ static void init(); void kill(ID); } class ...

Recently I do a research about modern c++. I saw a video [in 49:00] about c++11/c++14 variadic templates. If you want to calculate the sum of tuple ofdifferent types(such as int, double) with variadic ...

I was trying to write a function to forward arguments for a variadic template function, similar to std::invoke. Here is the code: #include <functional> template<class... Args> void f(...

I want my GUI application to print dynamic data on the screen (mouse coords etc.) through a user-defined format and using user-choosed variables. I need something like a class that stores this format (...

https://reviews.llvm.org/D15421 clang has __type_pack_element which allows efficient indexing of parameter packs in variadic templates. Is there a GCC equivalent? I am not interested in using ...

Say I have a class: template<typename... Types> class Example { public: using types = std::tuple<Types...>; template<size_t N> using dim_type = std::tuple_element_t<N, ...

I'm pretty new to C++ template programming. I'd like to design a function element such as e.g. element<3, 3, 3, 3, 3> will return 3 element<3, 3, 2> will fail an assertion #include <...

How can I iterate over all base classes of a variadic template class and call a function for each of them. Here is a minimal example: struct A { void foo() { std::cout << "A" << std::...

Related tags

Hot questions

Language

Popular Tags