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.
3
votes
0answers
66 views
Enum to string with template metaprogramming
This allows enum values to be outputted as strings. But enum_strings is a type, not a map or a vector, so if the enum value is known during compile time, there ...
1
vote
2answers
74 views
Variadic average function in C++
The following code was inspired from a tutorial I found online:
...
4
votes
3answers
247 views
Use va_list to format a string
I wrote a function that basically works like sprintf, but instead returns the formatted string (std::string). I haven't worked ...
14
votes
2answers
135 views
Formatted print without the need to specify type matching specifiers using _Generic
This code allows printing in C with a style similar to C++ ostream. By using _Generic() (see ...
3
votes
0answers
96 views
Invoke callable object passing arguments in “groups of N” using C++17 fold expressions
Interactive Wandbox example
Inspired by this Stack Oveflow question, I've implemented a function that, when called with a desired arity, a callable object, and a variadic amount of arguments, calls ...
7
votes
3answers
2k views
Sample printf implementation
Here is my code for printf() implementation in C. Please share your thoughts for improvements.
...
1
vote
0answers
44 views
Creating class method using macro to accept Visitator for each of their fields
I had a lot of classes that used a macro with listed fields. The macro was used to serialization, more like MSGPACK_DEFINE. I need a substitution of this mechanism, ...
5
votes
1answer
161 views
Thread-Safe Variadic Printing Function
Printing to stdout is thread-safe in many systems when using printf or std::cout, but not in ...
4
votes
1answer
181 views
Optimizing variadic template pack subsequence matching algorithm
I'm building a small MPL module in one of my utility libraries for fun and learning experience.
One of the problems I'm trying to solve is getting a list of all indices where a sequence of types ...
3
votes
1answer
339 views
Selecting variable amount of vector elements in C++
Suppose we are given a C++ vector. We want to specify a variable amount of indices and select elements from a vector being indexed. I have two implementation: (A) one relies on C++11 initializer lists,...
11
votes
1answer
205 views
Macro to build type declaration
These are some macros to help build a traits class (for the parser/printer classes I am building).
Traits.h
...
4
votes
1answer
134 views
Generating all permutations of a template pack
AllPermutedPacks<Pack<Types...>>::type is to be the pack of packs consisting of all permutations of Types.... For ...
6
votes
1answer
124 views
Variadic template for concisely defining a tuple whose components are all the same type
C++11 provides a std::tuple template, but it requires the types of all the fields to be listed individually, which is inconvenient if there are many fields and they'...
4
votes
1answer
683 views
Simple mathematical operations (add, sub, mul, div) in C++11 template
I made a simple script to implement basic mathematics operations by using variadic functions. I would like to know if my implementation is correct.
The code only works for Visual C++ compiler Nov ...
7
votes
2answers
772 views
writeln() and format() with variadic templates
I wanted to get better acquainted with variadic templates, so I decide to try to implement a function like D's writeln(), just for fun.
...
5
votes
1answer
319 views
Test whether a type T is among the types of a tuple
On SO, I asked for a way to do it without variadics. I also provided a typical "normal" implementation with variadics:
...
4
votes
2answers
3k views
Bit packing and unpacking
I needed a variadic function to pack and unpack bits into integer types. This is my first attempt:
...
12
votes
3answers
5k views
Very basic tuple implementation
I've been messing with metaprogramming and variadic templates in C++, and I came up with this very primitive implementation of a tuple:
...
7
votes
1answer
314 views
Most elegant variadic functor
Question
Suppose we have two sorts of classes
an input class Input
defines a type result_type
defines ...
4
votes
1answer
963 views
Event handler using variadic templates
I am currently working on a game and found myself in need of an event handler. I wrote an event handler similar to this one some time ago, but decided to update it using variadic templates (this is ...
7
votes
1answer
4k views
A small printf-like function using variadic templates
I'm looking to get some feedback on a small printf-like function I wrote that provides simplified behavior similar to ...
1
vote
1answer
253 views
C-style va_args replacement
I inherited a lot of C code with many ellipsis (variadic) functions.
I have a lots of API with the following signature:
...
11
votes
1answer
965 views
Variadic function with restricted types
I am designing a class which (among other things) acts as a vertex in an undirected graph.
...