Questions tagged [variadic]

In computer science, an operator or function is variadic if it can take a varying number of arguments; that is, if its arity is not fixed.

Filter by
Sorted by
Tagged with
4 votes
1 answer
63 views

Template to unpack arguments to a std::function

I am writing some C++ code to interact with an external scripting language. I want to be able to register arbitrary C++ callable code as functions to be called from the script. The scripting library ...
  • 159
1 vote
2 answers
50 views

C++ variardic universal template for unknown types, used to handle multiple network protocols

I am creating a template function with variardic arguments, to handle a specific classes that have some interface, method, member or whatever is specialized in a specialization area. However I came to ...
2 votes
1 answer
224 views

splitting a tuple into N-element tuples

This nice hack should allow you to split a tuple into N-element tuples, thereby effectively splitting a tuple into pairs, triples, ... For example, this allows you to split an input parameter pack, ...
  • 1,414
5 votes
3 answers
110 views

C function that emulates string concatenation operator '+' in Python or Go

I'm working on a project of mine which required multiple calls to strncat(), and it came to me that it'd have been much easier if C also had something like ...
1 vote
0 answers
69 views

A Function Applier for Applying Various Algorithms on Nested Container Things in C++

This is a follow-up question for A recursive_replace_if Template Function Implementation in C++, A recursive_copy_if Template Function Implementation in C++, A recursive_count_if Function with Unwrap ...
  • 3,646
6 votes
1 answer
305 views

Using templates to wrap variardic JNI method calls into type-safe C++ functors

I am working on a project which uses JNI. More than once I fell over the absence of type safety working with the variardic function calls. So I came up with this module. It wraps the variardic JNI ...
  • 171
5 votes
1 answer
173 views

Meta functions for sequences of exponents of 2

I have implemented some meta functions to create sequence for exponents of 2. I would love to know if there is any way to make the code more optimized. Note: ...
  • 369
1 vote
1 answer
118 views

Using vswprintf( ... ) to create wchar_t* with variable argument list

I am using c++17 and wide characters. I have created a function to create a wchar_t* using a variable number of parameters ... #include <stdarg.h> // the ...
  • 153
5 votes
1 answer
383 views

`zip` operator to iterate on multiple container in a sign

I worked out a zip operator similar to Python's, because I didn't find one in std. It allows to use range-based ...
  • 153
1 vote
0 answers
65 views

Simplifying a packaged task for a threadpool implementation

I wrote a thread pool where the user can submit jobs through ThreadTask objects. These objects bundle the job priority, the task as a function, and some arbitrary ...
7 votes
3 answers
700 views

Coalescing lvalue references to std-optionals

I want to coalesce (lvalue references to) optionals of the same type, in C++17: ...
  • 1,945
9 votes
2 answers
7k views

`printf` improvement with C++ variadic templates

I am currently working through learning C++'s variadic templates and I wanted to create an example use of them that is less trivial than the one in my book. I decided to create a modification of ...
  • 421
5 votes
3 answers
684 views

Encapsulating snprintf to avoid repetition of sizeof

Correct usage of snprintf involves very long and repetitive lines: ...
  • 1,908
6 votes
1 answer
2k views

Max function with variable number of arguments

I find it irritating that in standard C++ I can't do std::max(a, b) = x when it's possible and that it can't handle more than 2 arguments. For the second concern I ...
3 votes
1 answer
149 views

Creating a cache-friendly component system

I am fairly new to c++ and am attempting to write a simple 2D game engine. I am currently working on my object model: a pure component system, similar to that described in the Data Locality chapter in ...
3 votes
0 answers
118 views

Racket macro for variadic FFI

I'm working on FFI wrapper for SDL2 library in Racket. The library includes several variadic functions (e.g. SDL_SetError, SDL_LogMessage etc); Racket FFI does not have straight way for importing ...
2 votes
1 answer
281 views

Replacing MIN and MAX macros with type-safe, recursive templates of variable arity

I'm currently reading Mastering Perl for Bioinformatics; I'm using the book for learning bioinformatics while implementing the code in C++. I came across a situation where I needed to use the minimum ...
18 votes
3 answers
3k views

Min function accepting varying number of arguments in C++17

Come across this problem once again in the book The Modern C++ Challenge. 18. Minimum function with any number of arguments Write a function template that can take any number of arguments and returns ...
  • 786
4 votes
1 answer
263 views

Variadic Datablocks

I would like to have my variadic template class reviewed. First some explanation what it should do: I'm writing an application where I read in blocks of data. I know before i read in the data which ...
  • 3,016
5 votes
2 answers
379 views

C++ wrapper class to mimic a C array's brace initialization

I have an inheritance class that mimics the behavior of C style array's brace initialization by using a class template that has a variadic constructor but the template itself is not a variadic ...
1 vote
1 answer
368 views

Variadic Functions in NASM Win64 Assembly

Simple variadic function implementation in NASM Assembly. When implemented like I have below: sum.asm ...
  • 2,937
4 votes
2 answers
159 views

Templated string formatting

This function formats a string by replacing every occurrence of '{n}' with the corresponding argument that was passed to the function where n is an index that ...
8 votes
3 answers
2k views

The perfect function alias

For many years, I have waited for function aliases in C++. They still aren't here. I've been using macros to generate wrapper functions. This is my best attempt at the perfect function alias: ...
6 votes
2 answers
425 views

Small Formatting Library

I am learning C++ and currently playing with variadic template functions and formatting string, So here is my small attempt to write a formatting function and provide a simple iostream-like interface ...
2 votes
1 answer
288 views

Extract from typelist by runtime value

I combined the ideas from this answer and a comment to this question to create a new instance of a type extracted from a type list. The index of the desired type within the type list is provided at ...
  • 123
3 votes
1 answer
594 views

Variadic strcat for c++17

On some video from CPPcon, some one said that there should be variadic overload for operator+ as it can solve allocation when there are multiple ...
12 votes
3 answers
8k views

Apply a function to each element of a tuple ("map" a tuple)

C++ doesn't (yet) have a 'map' higher-order function, certainly not one which applies to a compile-time sequence of values like a tuple. We have std::transform, and ...
  • 1,945
6 votes
2 answers
680 views

Custom variadic min/max/sum functions

I have decided to write my own min max sum functions. I really don't like the ones provided ...
3 votes
1 answer
1k views

Alternative to integer_sequence trick

I hate working with std::integer_sequence. Each time I want to write a function foo I have to write an another function ...
  • 201
5 votes
1 answer
1k views

Generic message system using variadic templates

in my spare time I´m creating a hobby game engine as decided to write some of my systems on my own. As the time passes I´ve decided to start publishing it as a independent libraries for use (so ...
  • 153
8 votes
3 answers
430 views

Generators and Distributions 2.0

In my original question: Generically encapsulating random generators and distributions into a class template I was given some excellent suggestions from two very informative users. I will give a basic ...
4 votes
3 answers
334 views

Generically encapsulating random generators and distributions into a class template

I previously had a set of classes in one of my older libraries for working with the random number generators and distributions that was written when Visual Studio 2008 - 2010 were commonplace and ...
7 votes
1 answer
114 views

Extending functions to tuples

Intro: Imagine you have defined addition on types A and B with function A add(A,A) and ...
  • 201
3 votes
0 answers
82 views

Determining if two packs are permutations of each other during compile-time

Often we need to find out if two tuples, or two packs in general, are the same as each other up to permutation. If there are no repeat types, then implementing ...
  • 1,179
1 vote
0 answers
176 views

Variadic templates to generate SQL string

We have this old MFC code here which uses CString and format specifiers to generate an SQL statement and then execute that SQL. Something like this: ...
4 votes
1 answer
77 views

Class to unit-test functions, with rudimentary support for testing multi-parameter functions

Recently I read about test-driven-design and decided to try to create a simple unit testing class to begin using this approach. I have not been programming in Python for very long so forgive my ...
  • 143
8 votes
3 answers
3k views

Partial application in C++

Here is my code: ...
0 votes
2 answers
2k views

Variadic template class that stores a vector of each type given [closed]

I'm exploring the possibility to generalise a class of mine that stores some entities. I like it to be able to keep entities of several type, given as template arguments. To explore the possibilities ...
  • 147
4 votes
2 answers
77 views

Header-only variadic console output and runtime input validation in C++ using templates

Template IO Module This is a single-file, header-only input validation with two variadic output functions. One output function simply inserts a new line char after every output and the other one ...
9 votes
1 answer
158 views

Rotate a given number of variables in-place

A very simple but useful algorithm: rotate the values of a given number of variables in-place to the left so that the first variable gets the value of the second, the second gets the value of the ...
  • 19.9k
4 votes
1 answer
686 views

Implementing printf to a string by calling vsnprintf twice

I'm experimenting with writing a dynamic string library in C, and I decided to write an implementation of sprintf. In my code, I call vsnprintf with a buffer of 0 ...
  • 41
4 votes
1 answer
113 views

Sleeping and invoking a task in Python 2.X and Python 3.X

I'm writing a program that needs to be compatible for both Python 2.X and Python 3.X. My problem is that, because of the differences between these two versions, I'm duplicating code. ...
  • 379
10 votes
1 answer
619 views

Variadic templated method to extract values from a table

Is this the correct, most sane way to do variadic templates in C++? All that this function does is to see if gate has a key, if it has, it adds it to a vector of values, if not, it default constructs ...
1 vote
0 answers
677 views

A homemade variadic map

A bit of background: some time ago I wrote a piece of code that can be used for memoization with functions taking one parameter. Now I want to extend this to deal with functions with arbitrary number ...
1 vote
1 answer
1k views

Function with default parameters in any order

Intent Increase code usability/readability of functions with many default parameters while maintaining as much compile time safety as possible. Motivation It is very common to create functions that ...
6 votes
2 answers
1k views

Typesafe scanf-like function with variadic templates

I'm hoping to get some feedback on a function with variadic templates that parses a format string and fills in some parameters whose order and types are based on the characters in the format string. ...
  • 161
4 votes
4 answers
3k views

A variadic C function for concatenating multiple strings

I have this function that takes a number \$N\$, and \$N\$ C strings, concatenates and returns the result: ...
  • 26.4k
3 votes
2 answers
1k views

Simple JavaScript precondition checking implementation

I am writing a JavaScript application and would like to validate function arguments in many places. Most of these checks will be for correct argument types, or numeric values within specific ranges. ...
  • 289
5 votes
1 answer
2k views

Concatenate two containers, e.g. vector or strings

I'd like to create a function that can concatenate vectors or strings. It must Keep correct order Be optimal This is the solution I came up with: ...
  • 53
11 votes
2 answers
1k views

Call a lua function - the C++ way

I'm not that good when it comes to templates, especially when it comes to variadic templates. I want to show you some code where I use both - templates and variadic templates - to call a lua function. ...
  • 614