691 questions
0
votes
0
answers
58
views
Customized printf printing garbage values [closed]
I have written customized printf called 'cprintf' which is a variadic function .
int cprintf (const char* format, ...) {
int i;
va_list args;
int msg_len;
tlv_struct_t *tlv;
bool patt_rc = false;
...
4
votes
2
answers
94
views
Variadic arguments vs. upcasting arguments
The overloaded variadic version of a function is supposed to have the lowest priority, when the compiler chooses a template specialization. However, this is not the case when a function argument has ...
-1
votes
3
answers
89
views
How to properly forward non template, variadic arguments in C/C++ under MSVC
I am trying to forward non-template variadic arguments between two functions. None of those functions is mine so I can't change their signatures. I used va_args for that purpose but (unluckily) my ...
0
votes
3
answers
128
views
How do I pass different data types in a variadic function, with parameter folds?
Edit: Reformatting the entire question
Making a Linked List lib, and I wanted to pass through multiple values in order to make the appending of items easier, so I created some Variadic Functions, ...
2
votes
2
answers
93
views
C++17: explicit first template parameter before variadic template
I am trying to write a generic class for a symmetric bloc matrix of arbitrary dimension. Only the upper triangular part is given:
A B C
D E
F
so the number of blocks is n*(n+1)/2 where n is the ...
0
votes
1
answer
98
views
Type Parameter Packs: how to return a tuple instead of an array?
To begin with I have this code, which works totally fine:
protocol ComponentAccessible {}
extension ComponentAccessible {
func components<each T>(_ keyPaths: repeat KeyPath<Self, each T&...
0
votes
2
answers
74
views
Convert `(String, Int)...` variadic parameter function to Dictionary for ExpressibleByDictionaryLiteral
I have objects that are currently initialized via one-parameter init functions that take an Array or Dictionary.
I've realized that I can use ExpressibleByArrayLiteral and ...
3
votes
1
answer
77
views
Confusion about type deduction in variadic templates
I have a class with multiple constructors, one being variadic and one taking an additional callable before the variadic arguments. However, the objects I create result in overload resolutions I dont ...
1
vote
4
answers
251
views
Variadic function pointer in C
I want to implement a function that take a function and its arguments then call it.
I have search a lot and could not implement it with variadic function.
I want a clean way to record stdio after ...
1
vote
1
answer
349
views
Variadic Generics vs. Value and Type Parameter Packs in Swift
There are two evolution proposals:
Variadic Generics and Value and Type Parameter Packs.
So... what is the difference? They feel conceptually very similar.
The second one, with super heavy syntax, is ...
0
votes
2
answers
203
views
"some" keyword with variadic parameter in Swift
protocol myProtocol {}
func doSomething(with params: (some myProtocol)...) {
// Implementation goes here
}
extension Int: myProtocol {}
doSomething(with: 1, 2, 3)
Compilation error at the func ...
1
vote
1
answer
533
views
Achieve the opposite of __VA_OPT__ in variadic preprocessor function-like macros
How can I achieve the opposite effect of VA_OPT(), expanding only, if there are no variadic arguments in VA_ARGS. Something like VA_NOT_OPT().
Example:
#define MY_MACRO(...) __VA_NOT_OPT__(default) ...
0
votes
4
answers
137
views
How does one parse argument values from a function with a varying arguments signature?
I have a function called "Time", it accepts from 0 to 6 arguments.
function Time(year,month,day,hour,minutes,options) {
}
Parameters month, day, hour and minutes cannot be defined if the ...
0
votes
0
answers
51
views
equivalent implementation of C++20 variadic capture
Out of pure curiosity, while watching C++ weekly ep 171 I was wondering how variadic capture could be implemented, so I merely "asked" cppinsight. Here is the input snippet:
#include <...
0
votes
3
answers
130
views
C++17: pass multiple callable objects together with their parameters
I would like to write a function (C++17 if that matters) that accepts multiple callable objects together with their arguments and executes them in a loop. I would also like to avoid any intermediate ...
0
votes
1
answer
50
views
Passing variadic arguments to a method once object is constructed
I'm trying to build a template class that once constructed with its variadic arguments has its member functions use these arguments without the user having to manually insert them back. This code (...
2
votes
1
answer
157
views
Variadic zip over iterables in TypeScript
I'm trying to write a variadic zip over iterables while also preserving type. For example,
function* naturals(max=10) { for (let i=0; i<max; i++) yield i }
const x = [1, 2, 3]
const y = ["a&...
0
votes
2
answers
527
views
Metal Shader function with variadic arguments, called from SwiftUI?
My app requires to render a field strength in a SwiftUI View, i.e. to assign a color with a coordinate dependent opacity to each point of the View.
This can be done using Canvas, as described here, ...
2
votes
0
answers
264
views
Composition For WithOptions Pattern in Golang
In golang there's a pretty cool pattern for variadic options as
CallSomeStaff(mandatoryArg, WithSomeVariadicOption(val1), WithOtherVariadicOption(val2))
But what is the best/intended practice (or at ...
0
votes
0
answers
141
views
How can I write a Publishers.CombineLatest that uses variadic generics in Swift 5.9?
Now that Swift 5.9 includes support for variadic generics, I was hoping to get a Publishers.CombineLatest implementation using it, but there isn't one.
I figure we can make our own, but I don't even ...
0
votes
1
answer
193
views
suppress warning "left operand of comma operator has no effect" [duplicate]
In the following code, a array with repeated elements is created using a fold expression:
#include <array>
#include <utility>
template <std::size_t N>
class A {
int m_x;
public:...
1
vote
1
answer
166
views
C++ return type depending on the number of function arguments
I have the following struct:
#define vec std::vector
struct A
{
std::mt19937 rng;
std::uniform_real_distribution<double> U;
A(){}
A(int sed)
{
rng.seed(sed);
U = std::...
3
votes
1
answer
144
views
vsprintf() does not print warning when having more arguments then specified in format
I was trying the create an error check while creating logs, with a simple logging mechanism. I observed that it is possible use vfprintf(), that it does not print any warning at compile time, that too ...
1
vote
2
answers
62
views
Initializing variadic-template-constructed tuple of types with constructor requiring an argument
I apologize already having asked a similar question here when I should have modified the question I asked first.
I have the class Level which constructor requires an argument.
Using variadic templates ...
0
votes
1
answer
606
views
Wrapping a Call to Spdlog Inside a Variadic Macro
I am using the spdlog library in a C++20 project using modules.
I've encapsulated spdlog inside my singleton logger class because I don't want spdlog exposed to clients in case I swap it out for a ...
3
votes
1
answer
2k
views
Golang Generic+Variadic Function
In Golang having a number of functions of some generic type
type Transformer[A, B any] func(A)(B, error)
How to define a Generic Variadic high order function that could compose such functions in ...
6
votes
1
answer
157
views
Unpacking Variadic Parameter Pack of Enums
Update: Edited to fix compilation in working example.
I want to do something like the following so the function can take in both a list of the enum class instances or a struct that holds them, but the ...
1
vote
1
answer
102
views
I want to make a variadic template constructor that only accepts type T and one that only accepts non type T (c++)
I do not know how to do it and everything I try just doesn't work and I just can't know why.
Here's what I am trying:
template <typename T, typename... Args >
concept IsSameType = std::...
0
votes
1
answer
98
views
Variadic Generics in Delphi?
Context
Trying to have a generic "Observer" pattern in Delphi, I managed to make something working:
TObserver = class
protected
FSubject: TSubject;
public
constructor Create(); ...
1
vote
0
answers
36
views
Create a map of member functions with variadic arguments [duplicate]
I have a class with (private) functions and different arguments. I want to put these into a map and then call them with a single function that accepts variadic arguments. I am fine to have a ...
0
votes
1
answer
119
views
Variadic function is behaving strangely [closed]
I am trying to understand what is wrong with my variadic function.
For some reason it breaks all the variadic arguments, except the second and the third.
The function looks correct according to the ...
0
votes
0
answers
74
views
Inheriting variadic constructor marked __attribute__((format(printf, ...)))
The following code compiles in clang but not in gcc:
#include <cstdarg>
#include <iostream>
struct Base {
Base(const char* fmt, ...) __attribute__((format(printf, 2, 3))) {
va_list ...
2
votes
2
answers
815
views
How to write a variadic Rust macro that forwards to the vec! macro?
In Rust 2021, I have a struct type called Intersection, and I wish to store it in a variable length list, so probably a Vec<Intersection>. I can easily construct a new container with:
#[derive(...
4
votes
1
answer
918
views
Cartesian product of n ranges
I am rewriting a python program into rust and I am struggling to translate this line:
itertools.product(range(0,8), repeat=n)
What I am trying to achieve is something like this: https://pastebin.com/...
0
votes
1
answer
43
views
Generic Variadic Types in Python3+ class definition
I haven't used Python in a while. I'm implementing a simple stack:
class Stack:
def __init__(self):
self.stack = []
def push(self, val) -> None:
self.stack.append(val)
...
0
votes
1
answer
201
views
How must a function pointer be defined, which points to a function with variadic arguments
The goal is to have logging, both under Arduino / espressif platform and native. C++ 11 is used.
For example:
logx("Text val1: %d, val2: %u", a, 123);
------> 20:24:27.237 > [ 26][D]...
0
votes
5
answers
438
views
Null-terminating a list of arguments for a C variadic function
I'm messing around with variadic functions in C to learn how they work, and am trying to build a simple 'print lines' function without requiring manual counting of the lines. I'm doing this by ...
4
votes
2
answers
148
views
C++ Paramater pack expansion over chained function calls
It is common for libraries to have types which return instances of themselves from member functions to encourage chaining calls. For example, nlohmann json:
auto my_data = my_json_object["first ...
0
votes
0
answers
71
views
How to iterate over a template-less variadic in C++
I was under the impression that I don't need a template in order to use variadics in C++. So in the following class, I have a method that accepts a variadic as its second variable. Now my question is: ...
0
votes
1
answer
310
views
Error with variadic templates function: candidate expects 0 arguments, 3 provided
I'm trying to write a static variadic templates constructor for my class. But I'm not so experienced in variadic templates and get an error.
I wrote the following code:
template <typename T> ...
2
votes
4
answers
102
views
Trying to replicate printf behaviour about variadic paramenters
I'm trying to replicate some printf functionality for education purposes, but I've encountered some printf behavior that I'm unable to understand. I'll try explaining with a simple example:
have this ...
0
votes
1
answer
226
views
How to prefix __VA_ARGS__ elements in a macro
Is it possible to prefix each element of variadic parameters with something else?
#define INPUTS(...) ???
Function(INPUTS(a, b, c))
should become
Function(IN a, IN b, IN c)
1
vote
2
answers
256
views
Suppressing warnings for a printf-like function in C++
I have a legacy logging printf-like function in C:
namespace legacy
{
void DoLog(const char* format,...);
}
If is only visible if a corresponding macro is defined (this is legacy too):
#ifdef LOG
...
2
votes
1
answer
58
views
Trying to construct a vector from initializer list using std::make_unique()
I struggle to understand the code below. Why can v2 be constructed from an initializer list, but v3 fails?
#include <vector>
#include <memory>
int main()
{
auto v1 = std::make_unique<...
2
votes
1
answer
708
views
Tuple, array or vector of vectors as argument of a function
I want to be able to provide vectors as arguments from an array of vectors to a macro iproduct!, which accepts varying numbers of arguments (all arguments must be Iterator element type).
Most ...
3
votes
1
answer
192
views
Using a custom type with va_arg
mystruct_t v = va_arg(a_list, mystruct_t);
Is this okay (using a custom data type that's >= the size of an int) as far as C specs go?
1
vote
1
answer
71
views
Is there a standard for saving caller saved registers from within variadic functions?
I'm exploring variadic functions, particularly the assembly it gets compiled to. Let's imagine we have a variadic function which calls a function from within it. With reference to the example file ...
1
vote
1
answer
79
views
Specify Order of Variadic Generic Arguments for Variable Parameters in TypeScript
I'm trying to do something that feels absurd, but I've gotten so close I feel it must be possible, I just can't quite get it.
I'm trying to create a generic function type such that assigning the ...
2
votes
2
answers
79
views
calling class function based on variadic function arguments resulting an error
Facing some compilation errors when using the below example with a variable number of arguments & need some help to find some solution or some better approach.
I am trying to initialize the class ...
2
votes
1
answer
154
views
Why does passing a dictionary as part of *args give us only the keys?
The setup
Let's say I have a function:
def variadic(*args, **kwargs):
print("Positional:", args)
print("Keyword:", kwargs)
Just for experiment's sake, I call it with the ...