variadic-functions

How to use va_start()?

陌路散爱 提交于 2021-01-27 14:20:58
问题 In a function with variable arguments, we initialize an object of type va_list ,'ap' with the function va_start() as: void va_start(va_list ap, parmN); I don't understand 1.what type of objects can be passed as parMN(last known parameter). I've done with examples of passing integers, strings with format specifiers, structures etc. 2. How the parMN describes the following optional parameters. 回答1: The C standard says that va_start() is actually a macro, not a function, so it can do things a

Multiple parameter packs in a single function?

时光毁灭记忆、已成空白 提交于 2021-01-27 07:31:55
问题 I'm trying to create a function that takes two parameter packs of objects. There are two templated base classes and I'd like to pass instances of derived classes to this function. Consider this example. template <int N> struct First {}; template <int N> struct Second {}; // there are a few of these struct FirstImpl : First<5> {}; struct SecondImpl : Second<7> {}; template <int... firstInts, int... secondInts> void function(float f, First<firstInts> &... first, Second<secondInts> &... second)

Multiple parameter packs in a single function?

て烟熏妆下的殇ゞ 提交于 2021-01-27 07:31:43
问题 I'm trying to create a function that takes two parameter packs of objects. There are two templated base classes and I'd like to pass instances of derived classes to this function. Consider this example. template <int N> struct First {}; template <int N> struct Second {}; // there are a few of these struct FirstImpl : First<5> {}; struct SecondImpl : Second<7> {}; template <int... firstInts, int... secondInts> void function(float f, First<firstInts> &... first, Second<secondInts> &... second)

Access to variadic function' arguments without va_list in C

若如初见. 提交于 2021-01-27 04:42:13
问题 Is it possible to iterate through variadic function' arguments using pointer (void pointer?) to last named argument? (I know that's not the right way to work with variadic arguments, but I'm still interested if that would work) Setting pointer to the end of the string doesn't work, because after I start moving the pointer, it points to other strings used in the program. #include <stdio.h> #include <string.h> #include <stdlib.h> void form_date(MON* datePtr, int dayMonth, int dayYear, int month

use of &rest and &key at the same time in Common Lisp

半世苍凉 提交于 2021-01-26 17:28:03
问题 I want to use both &rest and &key at the same time. However, the attempted code below: (defun test (&rest args &key (name "who")) nil) (test 1 2 3 4 5 :name "hoge") causes an error: *** - TEST: keyword arguments in (1 2 3 4 5 :NAME "hoge") should occur pairwise and when I gives only keyword parameter like (test :name "hoge") , it works. Is it possible to use both &rest and &key? 回答1: It's generally not a good idea to mix rest parameters with keyword parameters within a function definition in

use of &rest and &key at the same time in Common Lisp

浪子不回头ぞ 提交于 2021-01-26 17:22:54
问题 I want to use both &rest and &key at the same time. However, the attempted code below: (defun test (&rest args &key (name "who")) nil) (test 1 2 3 4 5 :name "hoge") causes an error: *** - TEST: keyword arguments in (1 2 3 4 5 :NAME "hoge") should occur pairwise and when I gives only keyword parameter like (test :name "hoge") , it works. Is it possible to use both &rest and &key? 回答1: It's generally not a good idea to mix rest parameters with keyword parameters within a function definition in

use of &rest and &key at the same time in Common Lisp

断了今生、忘了曾经 提交于 2021-01-26 17:22:21
问题 I want to use both &rest and &key at the same time. However, the attempted code below: (defun test (&rest args &key (name "who")) nil) (test 1 2 3 4 5 :name "hoge") causes an error: *** - TEST: keyword arguments in (1 2 3 4 5 :NAME "hoge") should occur pairwise and when I gives only keyword parameter like (test :name "hoge") , it works. Is it possible to use both &rest and &key? 回答1: It's generally not a good idea to mix rest parameters with keyword parameters within a function definition in

use of &rest and &key at the same time in Common Lisp

与世无争的帅哥 提交于 2021-01-26 17:18:42
问题 I want to use both &rest and &key at the same time. However, the attempted code below: (defun test (&rest args &key (name "who")) nil) (test 1 2 3 4 5 :name "hoge") causes an error: *** - TEST: keyword arguments in (1 2 3 4 5 :NAME "hoge") should occur pairwise and when I gives only keyword parameter like (test :name "hoge") , it works. Is it possible to use both &rest and &key? 回答1: It's generally not a good idea to mix rest parameters with keyword parameters within a function definition in

Variadic Zip Function in Swift

半腔热情 提交于 2021-01-19 09:01:38
问题 Variadic Zip Function Swift 4.1, Xcode 9.4 I have been using Apple's native zip(_:_:) recently and I ran into a situation whereby I needed to zip more than two sequences. So I looked for and found the declaration of zip(_:_:) on Swift's GitHub page. I took that information and was able to overload zip(_:_:) to accept four parameters, zip(_:_:_:_:) . I am aware that I can painstakingly overload zip to support whatever number of arguments I chose one at a time, but this is inflexible, time

Passing any class member function with any number of arguments to a function outside the class

只愿长相守 提交于 2021-01-07 01:30:47
问题 Remy posted a great solution to pass any function with any number of arguments to std::thread , here. I was wondering how it could be used for class member functions. #include <iostream> #include <thread> #include <mutex> #define __PRETTY_FUNCTION__ __FUNCSIG__ std::mutex my_mutex; template<class Function, class... Args> void runFunctionInThread(Function f, Args&&... args) { // Beside starting a thread, this function performs other // task using the function and its arguments. std::thread t(f