variadic-functions

Parsing commands using map<const string, function<? (?)>> commands;

瘦欲@ 提交于 2019-12-11 20:22:37
问题 Problem statement: Given the interactive input, call the appropriate methods on appropriate objects (Bank, BankRegister, BasicAccount, etc...). input (each command on a separate line): create_bank <bank_name>\n create_customer <bank_number> <customer_name>\n create_account <bank_number> <customer_number>\n deposit <amount> <account_number>/<bank_number>\n etc... Proposed solution: #include <functional> bool create_bank(const string& arguments){ const string& bankName = arguments; //no need to

variadic scanf in C

旧城冷巷雨未停 提交于 2019-12-11 19:20:06
问题 I was curious if it's possible to implement a sort of variadic version of scanf in C. What I mean is if the input is push (1 2 3) , scanf would be able to parse that into %s %d %d %d with something like scanf("%s (%d)", string, some_list) . It would take all instances of %d and append them (in order) to the list... Am I talking sense? EDIT: For the specified input, string == "push" and some_list == [1, 2, 3] . 回答1: Isn't vscanf, vssscanf, vsfcanf is what you are looking for? They are

Wrapping a Vararg Method in ActionScript

雨燕双飞 提交于 2019-12-11 15:54:23
问题 I have a vararg method that I'd like to act as a proxy for another vararg method, but I'm not sure how to do it. Here's the basic code: class MyClass { public function a(...args:*):* { // other code b(args); // other code } public function b(...args:*):* { // do stuff with args } } I'm porting the code from Java, where the type system knows that the arguments are actually supposed to be Strings, not arrays, so it can figure out to invoke b() by directly passing the arguments, and everything

Canonicalise args and kwargs to kwarg-canonical form

自作多情 提交于 2019-12-11 15:28:14
问题 I've asked a similar question here for posarg-canonical form. Any possible args should be converted to keyword-form, with the defaults being omitted based on the result of the is operator, the id or similar. For example: def myfunc(a, b=None, **kwargs): pass def canonicalize(func, *args, **kwargs): something = inspect.signature(func) # Do something with args/kwargs here return new_args, new_kwargs Example output: >>> canonicalize(myfunc, 1, 2, g=3) (1,), {'b': 2, 'g': 3} >>> canonicalize

Pass C# object[] to Matlab Dll method

倾然丶 夕夏残阳落幕 提交于 2019-12-11 13:45:23
问题 I am trying to pass a C# object array to a Matlab method using parameter array params keyword. My Matlab method is complied to a .net assembly Dll. Here is my simple c# method: public void Method1(params object[] objArg) { _mMExt.mMethod1((MWArray[])objArg); } I am using varargin as input for my Matlab function mMethod1: function mMethod1(varargin) nVarargs = length(varargin); end The issue is when I am converting object[] to MWArray[] by doing this: (MWArray[])objArg It seems that I can use

g++ and clang++ different behaviour with variadic container

别来无恙 提交于 2019-12-11 12:19:50
问题 In order to practice with C++11, I'm playing with variadic templates. In particular, I'm playing with a sort of recursive variadic container class ( onion ) and a function that returns the number of template types ( func() ). I came across a case that the clang++ (3.5.0) can't compile while the g++ (4.9.2) compiles and runs with no problems. I have simplified it as follows #include <iostream> template <typename F, typename ... O> struct onion; template <typename F, typename S, typename ... O>

Dynamic function calls at runtime (va_list)

故事扮演 提交于 2019-12-11 11:24:54
问题 There is a way in C to obtain a dynamic length argument list with va_list, as described here: http://www.cprogramming.com/tutorial/c/lesson17.html That quite simple, but most times in C++ not needed. I am currently building a top level wrapper class for encapsulating some Zend functionality. Anyway, I do need to make a call to such a dynamic function like printf from a normal function dynamically. I mean the reverse way of the example described above, here is waht I got so war, maybe this

A class to manage multidimensional array! How can I do to manage different data types in the cells?

我的梦境 提交于 2019-12-11 10:12:25
问题 I state that I am a C programmer more than a C++ programmer (with C++ I'm a beginner: p) I've written a C++ class to manage multidimensional arrays (n-dimensional matrices). This class has methods to create the matrix and to set and to get value in/from the matrix (also to set the position inside it). I've two issues: With the idea that I want a syntax similar to m(x,y,z, ..., n) to set/get values some methods use the ellipsis E.G.: getValue(int dim0,...); But I think it's dangerous; although

c++ variable argument list

泄露秘密 提交于 2019-12-11 08:17:20
问题 I'm searching for answers but i can't find any relevant information on this. Let's take the example: class MyClass { //member functions and variables }; void foo(int pivot,...) { va_list arguments; va_start(arguments,pivot); //va_arg(arguments,???) va_end(arguments); } void bar() { MyClass a; MyClass * b = &a; const MyClass & c = a; foo(0,a,b,c); } How are the arguments a , b and c passed? By value , or by reference and how to ask for them using va_arg? What about the constructors/destructor

va_arg 64bit issue

放肆的年华 提交于 2019-12-11 08:09:33
问题 I've such C code. On 64-bit linux system the result is: 4294967264 instead of -32. Both clang and gcc produce binary with same incorrect results. The problem in the line: *v = va_arg(args, long); #include <stdio.h> #include <string.h> #include <stdarg.h> void setter(long *v, ...) { va_list args; va_start(args, v); *v = va_arg(args, long); va_end(args); } int main() { long v = 0; setter((long *) &v, -32); printf("%ld\n", v); return 0; } 回答1: You actually need to pass a long to your function.