variadic-functions

BWDB SQLite wrapper for iOS ARC issues

こ雲淡風輕ζ 提交于 2019-12-18 09:45:45
问题 I am trying to use Bill Weinman's BWDB wrapper, which can be downloaded here: http://bw.org/iosdata/ I can't convert it to ARC properly, can someone more experienced then i to look at it? Main issue is va_list in insertRow & updateRow methods, idk what to do with it. The rest of the errors are easy to get rid of. Thanks in advance for any help/advice! Header file // BWDB.h // Created by Bill Weinman on 2010-09-25. // Copyright 2010 The BearHeart Group, LLC. All rights reserved. #import

How to easily create fully “variadic” functions with C++ 98 standard?

我怕爱的太早我们不能终老 提交于 2019-12-18 09:37:28
问题 The library https://github.com/c42f/tinyformat/blob/2f9335afd9941688e42d60cae5166b9f0600b2d1/tinyformat.h#L1104-L1116, uses this awesome trick to do "variadic" templates on C++ 98: inline void printfln(const char* fmt) { format(std::cout, fmt); std::cout << '\n'; } template<TINYFORMAT_ARGTYPES(n)> \ void printfln(const char* fmt, TINYFORMAT_VARARGS(n)) \ { \ format(std::cout, fmt, TINYFORMAT_PASSARGS(n)); \ std::cout << '\n'; \ } I am trying to improve it by eliminating the requirement to

Is it possible to have a variadic function in C with no non-variadic parameter?

你说的曾经没有我的故事 提交于 2019-12-18 05:38:18
问题 I have the following function: void doStuff(int unusedParameter, ...) { va_list params; va_start(params, unusedParameter); /* ... */ va_end(params); } As part of a refactor, I'd like to remove the unused parameter without otherwise changing the implementation of the function. As far as I can tell, it's impossible to use va_start when you don't have a last non-variadic parameter to refer to. Is there any way around this? Background: It is in fact a C++ program, so I could use some operator

Delphi “array of const” to “varargs”

对着背影说爱祢 提交于 2019-12-18 04:11:01
问题 Please help! I need this conversion to write wrapper for some C headers for Delphi. As an example: function pushfstring(fmt: PAnsiChar): PAnsiChar; cdecl; varargs; external; ... function PushString(fmt: AnsiString; const args: array of const): AnsiString; begin Result := AnsiString(pushfstring(PAnsiString(fmt), args)); // it's incorrect :/ end; How can I convert "array of const" to "varargs"? edit : function PushString is actually inside the record (I gave a simplified example), and I do not

How to write a variadic template recursive function?

自闭症网瘾萝莉.ら 提交于 2019-12-18 03:55:21
问题 I'm trying to write a variadic template constexpr function which calculates sum of the template parameters given. Here's my code: template<int First, int... Rest> constexpr int f() { return First + f<Rest...>(); } template<int First> constexpr int f() { return First; } int main() { f<1, 2, 3>(); return 0; } Unfortunately, it does not compile reporting an error message error C2668: 'f': ambiguous call to overloaded function while trying to resolve f<3,>() call. I also tried to change my

Create a Map in Golang from database Rows

╄→尐↘猪︶ㄣ 提交于 2019-12-17 22:47:32
问题 Basically after doing a query I'd like to take the resulting rows and produce a []map[string]interface{} , but I do not see how to do this with the API since the Rows.Scan() function needs a specific number of parameters matching the requested number of columns (and possibly the types as well) to correctly obtain the data. Again, I'd like to generalize this call and take any query and turn it into a []map[string]interface{} , where the map contains column names mapped to the values for that

How can a function with 'varargs' retrieve the contents of the stack?

房东的猫 提交于 2019-12-17 21:56:46
问题 Normally, in Delphi one would declare a function with a variable number of arguments using the 'array of const' method. However, for compatibility with code written in C, there's an much-unknown 'varargs' directive that can be added to a function declaration (I learned this while reading Rudy's excellent 'Pitfalls of convering' document). As an example, one could have a function in C, declared like this : void printf(const char *fmt, ...) In Delphi, this would become : procedure printf(const

A function with variable number of arguments with known types, the c++11 way

北战南征 提交于 2019-12-17 18:35:29
问题 I already know the stdarg.h way to have a function with variable arguments in c++ as discussed here for example. I also know c++11 standard has variadic templates as explained here. But in both of aforementioned schemes we don't know (and we can't force) argument types in compile time afaik. What I'm looking for is to pass variable arguments of known types to a function. I think this can be done because I read about it here: Variadic templates, which can also be used to create functions that

Why do argument lists in certain Cocoa methods end with a nil?

混江龙づ霸主 提交于 2019-12-17 16:58:29
问题 Why do argument list in some methods end with nil ? I have noticed this particularly in the collection classes, for example NSSet : mySet = [NSSet setWithObjects:someData, aValue, aString, nil]; and NSArray : NSArray *objects = [NSArray arrayWithObjects:@"value1", @"value2", @"value3", nil]; 回答1: It has to do with how variable argument lists work ( va_list , seen as ... in the parameters). When the code is trying to extract all of the values in the list, it needs to know when to stop (because

How to forward functions with variadic parameters?

白昼怎懂夜的黑 提交于 2019-12-17 13:44:13
问题 In Swift, how do you convert an Array to a Tuple? The issue came up because I am trying to call a function that takes a variable number of arguments inside a function that takes a variable number of arguments. // Function 1 func sumOf(numbers: Int...) -> Int { var sum = 0 for number in numbers { sum += number } return sum } // Example Usage sumOf(2, 5, 1) // Function 2 func averageOf(numbers: Int...) -> Int { return sumOf(numbers) / numbers.count } This averageOf implementation seemed