variadic-functions

Pass tuple's content as variadic function arguments

自古美人都是妖i 提交于 2020-01-28 10:28:39
问题 I play with C++0x for some time and now I want to use variadic templates and tuple to implement class "Task". I'm going to pass Task objects into newly created threads (using pthread). Task class will contain function pointer to function which should be called inside thread and arguments for this function, simplified code: class TaskCaller { // ... virtual bool dispatch (void); }; template<typename ...T_arguments> Task : public TaskCaller { public: // ... Task (bool (*function) (T_arguments&.

Pass tuple's content as variadic function arguments

喜你入骨 提交于 2020-01-28 10:28:15
问题 I play with C++0x for some time and now I want to use variadic templates and tuple to implement class "Task". I'm going to pass Task objects into newly created threads (using pthread). Task class will contain function pointer to function which should be called inside thread and arguments for this function, simplified code: class TaskCaller { // ... virtual bool dispatch (void); }; template<typename ...T_arguments> Task : public TaskCaller { public: // ... Task (bool (*function) (T_arguments&.

Problems specializing variable template function

早过忘川 提交于 2020-01-24 09:21:26
问题 I am writing a function inListi() which takes at least one argument and compares the first argument to thes list of all subsequent arguments. returns true if first argument == an element in the list, otherwise false. So: if( inListi( 1.2, 2.3, 4.5, 1.2)) std::cout << "Returns true because last argument equals the first argument." << endl; if( inListi( "hello", "world", "HEllo")) std::cout << "This should print out because of the last argument." << endl; Problem is, it doesn't work. I have the

Is there a difference in Scala between Seq[T] and T*?

落爺英雄遲暮 提交于 2020-01-24 03:01:06
问题 My IDE's tooling shows that xs has type Int* in the following snippet: def accept(xs: Int*) = true The language reference, however, says that a repeated parameter declared as T* has type Seq[T] . Is there a difference between Int* and Seq[Int] ? 回答1: They are different, and it's somewhere between bug and regrettable feature that T* leaks into type signatures. Repeated parameter typed as T* rather than Seq[T] 回答2: Yes, they are different. See, e.g., Overriding a repeated class parameter in

Passing va_list to other functions

房东的猫 提交于 2020-01-22 14:43:50
问题 I have been trying to pass variable arguments to other function in C but it is producing inconsistent result in different runtime environment as well as in different runs in same environment: int main() { int result = myprintf("Something \n %d", 9); return result; } int myprintf(const char *format, ...){ printf("Something \n %d", 9); printf("\n"); va_list args; va_start(args, format); int result = printf(format,args); printf("\n"); va_end(args); return result; } And the result produced is:

Passing va_list to other functions

点点圈 提交于 2020-01-22 14:43:07
问题 I have been trying to pass variable arguments to other function in C but it is producing inconsistent result in different runtime environment as well as in different runs in same environment: int main() { int result = myprintf("Something \n %d", 9); return result; } int myprintf(const char *format, ...){ printf("Something \n %d", 9); printf("\n"); va_list args; va_start(args, format); int result = printf(format,args); printf("\n"); va_end(args); return result; } And the result produced is:

Passing va_list to other functions

孤者浪人 提交于 2020-01-22 14:43:07
问题 I have been trying to pass variable arguments to other function in C but it is producing inconsistent result in different runtime environment as well as in different runs in same environment: int main() { int result = myprintf("Something \n %d", 9); return result; } int myprintf(const char *format, ...){ printf("Something \n %d", 9); printf("\n"); va_list args; va_start(args, format); int result = printf(format,args); printf("\n"); va_end(args); return result; } And the result produced is:

C++ need a container to store user defined function

≡放荡痞女 提交于 2020-01-15 10:59:29
问题 I am trying to create a interface between user defined function and data. Let's say I need to create a function called MapFun() , input of MapFun() includes user defined function (UDF) handle and UDF inputs. void userFun1(Data data, int in1, int in2){ // user defined function 1; } void userFun2(Data data, int in1, int in2, std::string s){ // user defined function 2; } // ... // apply user function 1 on data MapFun(@userFun1, data, 3, 4); // apply user function 2 on data MapFun(@userFun2, data

marshaling variable arguments - __arglist or alternative

点点圈 提交于 2020-01-14 03:30:30
问题 Best way to describe the problem I'm trying to solve is to talk in code. I see a lot of __arglist questions on this forum, but not a lot of helpful answers. I know _arglist should be avoided so I'm open to alternative methods In one C++ module I have something like the following void SomeFunction(LPCWSTR pszFormat, va_args args) { // this function is not exported... // it is designed to take a format specifier and a list of variable // arguments and "printf" it into a buffer. This code //

variadic functions with different types of arguments in c

泪湿孤枕 提交于 2020-01-13 07:28:23
问题 I was wondering if it's possible in C to create a variadic function that takes different types of arguments. i.e. void fillDatabase(char* name, int age){ writeToDatabase(name, age); } int main(){ fillDatabase("Paul", 19); fillDatabase("Herbert"); } Here I am trying to fill up a database with names and ages. But it's also possible to fill it up with only a name and no age. So I am wondering if I could use the same function for that or if I have to write two different ones? Online I could only