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.

668 questions
4
votes
1 answer

Pass nested types to a parent class without repeating yourself (DRY) in C++20

As shown in the example below, I need my Component struct to be able to access all the "fields" structs defined in a child struct. But I have some constraints: The fields must be declared as nested types of the inheriting struct. I cannot use any…
Renondedju
  • 43
  • 7
4
votes
4 answers

How to get all parameters passed into a function, with their values?

I have a function adebo.deepSearch = function(z, pi_0 = 0.3, families=list(), ... ) { } I want to capture all of the parameter names and values passed in by way of a function called grabFunctionParameters; e.g., adebo.deepSearch =…
mshaffer
  • 959
  • 1
  • 9
  • 19
4
votes
1 answer

Swift Protocol with Variadic property

I'm trying to create Swift Protocol with Variadic property. According to the docs, it's possible to do it in a function: func arithmeticMean(_ numbers: Double...) -> Double { var total: Double = 0 for number in numbers { total +=…
Roi Mulia
  • 5,626
  • 11
  • 54
  • 105
4
votes
1 answer

template function pointers and lambdas

Hi I'm trying to sort out an issue with the following code: template using Func = void (*)(Args... args); template void do_test(Func f, Args&... args) { for (int i = 0; i != 100; i++) …
Joel Holdsworth
  • 363
  • 1
  • 2
  • 7
4
votes
2 answers

swift combine declarative syntax

The declarative syntax of Swift Combine looks odd to me and it appears that there is a lot going on that is not visible. For example the following code sample builds and runs in an Xcode playground: [1, 2, 3] .publisher .map({ (val) in …
bhartsb
  • 1,316
  • 14
  • 39
4
votes
1 answer

FFI in Chez Scheme for C functions with variadic arguments (varargs)

I want to write a FFI for printf function of C in Chez Scheme using foreign-procedure. But I cannot figure out what I should put as the signature, since the last argument in printf function is a variadic argument. Here's my code: (import…
Reza Hajianpour
  • 707
  • 1
  • 10
  • 21
4
votes
0 answers

How to retrieve the type of a variadic template argument?

I cant find a way to define a type like this: template using hasSomeFunc = decltype(std::declval().SomeFunc(std::declval>(),…
Iñigo
  • 97
  • 6
4
votes
3 answers

C++ template: cannot match the last template in variadic class template

I'm learning C++11 variadic template and created a template struct to calculate the max number of a given list and tried: #include #include template struct max: std::integral_constantb?…
bigtit
  • 93
  • 5
4
votes
1 answer

How do I pass each element of a slice as a separate argument to a variadic C function?

I'm building a Redis Module in Rust. I've found some good examples, but I'm stuck when dealing with interfacing a C function that is supposed to accept variadic arguments. The Redis Module C SDK has a function called RedisModule_Call which accepts…
stockholmux
  • 1,169
  • 11
  • 24
4
votes
2 answers

Passing arguments to another variadic function

Is there any way at all for this code to compile and work as intended without resorting to va_list stuff ? #include void fct(void) { std::cout << std::endl; } void fct(int index, int indexes...) { std::cout << index << ' '; …
Pippin
  • 323
  • 1
  • 9
4
votes
4 answers

How to pass not variadic values to fmt::format?

I'm playing with the great fmt C++ library to format strings more gracefully. And I'd like to pass a non-variable arguments list to fmt::format. It could be a std::vector, or std::string, or whatever, but it will always match the format string. So…
Kyone
  • 513
  • 5
  • 17
4
votes
2 answers

Can using an array as the last named argument to a variadic function result in a buffer underrun?

I found this paragraph in the man page for stdarg.h: Because the address of this parameter is used in the va_start() macro, it should not be declared as a register variable, or as a function or an array type. So, register variable I understand,…
Shoblade X
  • 363
  • 2
  • 9
4
votes
2 answers

What is the appropriate way to retrieve the value of a C++ variadic template constant argument at position N?

I would like to know what is the correct way to retrieve the value of a variadic template constant argument at position N (N is known at compile time). For instance, let's say you have a template that receives a variadic number of function pointers…
pmjobin
  • 813
  • 1
  • 7
  • 15
4
votes
1 answer

How to make template deduce return type of function with variadic arguments

Someone on stack overflow wrote an interesting way to capture a lambda or functor into your own class. I was trying to simplify it, and I think I got close but was having some trouble. Their example was: // OT => Object Type // RT => Return Type //…
Zebrafish
  • 11,682
  • 3
  • 43
  • 119
4
votes
2 answers

Creating POD with variable number of elems

I would like to have a type, that would be in effect POD but I would like to be able to specify how and which types are in it, for example: template struct POD { //here I would like to create depending on Args appropriate types as a…
There is nothing we can do
  • 23,727
  • 30
  • 106
  • 194