variadic

How to expand macro and delete comma

倖福魔咒の 提交于 2020-01-23 02:04:20
问题 For example I want to write my own printf() alternative, but I have to perform calculations on the variable arguments: #define log(fmt_string, ...) my_log(fmt_string, pack_args(__VA_ARGS__), __VA_ARGS__) where pack_args(...) - is a macro too. How should I change this code to handle the only fmt_string presence scenario? log("Some message here"); 回答1: In P99 I have two macros #define P00_ARG( \ _1, _2, _3, _4, _5, _6, _7, _8, \ _9, _10, _11, _12, _13, _14, _15, _16, \ ... etc ... \ _153, _154,

How to expand macro and delete comma

99封情书 提交于 2020-01-23 02:04:05
问题 For example I want to write my own printf() alternative, but I have to perform calculations on the variable arguments: #define log(fmt_string, ...) my_log(fmt_string, pack_args(__VA_ARGS__), __VA_ARGS__) where pack_args(...) - is a macro too. How should I change this code to handle the only fmt_string presence scenario? log("Some message here"); 回答1: In P99 I have two macros #define P00_ARG( \ _1, _2, _3, _4, _5, _6, _7, _8, \ _9, _10, _11, _12, _13, _14, _15, _16, \ ... etc ... \ _153, _154,

Instantiate Foo() class on main click group command by running subcomand with Foo() arguments

不打扰是莪最后的温柔 提交于 2020-01-16 05:11:07
问题 I want to run a click subcommand with variadic arguments that are going to be used to instantiate a class Foo(*args) on main() group command in order to create an instance of Foo() to be used by its subcommands so that it aligns with the way click works: $ python foo.py subcommand arg1 arg2 ... argN This question is based on my initial question and @StephenRauch answer. import click class Foo(object): def __init__(self, *args): self.args = args def log(self): print('self.args:', self.args)

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

cpp: catch exception with ellipsis and see the information

若如初见. 提交于 2020-01-10 04:20:07
问题 I know that you can catch "all exceptions" and print the exception by try { //some code... }catch(const std::exception& e) { cout << e.what(); } but this is just for exceptions derived from std::exception. I was wondering if there is a way to get some information from an ellipsis catch try { //some code... }catch(...) { // ?? } If the mechanism is the same as ellipsis for functions then I should be able to do something like casting the argument of the va_list and trying to call the what()

Is there a way to use C++ preprocessor stringification on variadic macro arguments?

喜欢而已 提交于 2020-01-09 07:35:49
问题 My guess is the answer to this question is no, but it would be awesome if there was a way. To clarify, assume I have the following macro: #define MY_VARIADIC_MACRO(X...) // Does some stuff here in the macro definition What I would like to do is somehow perform stringification on all the variables of X before passing it to a variadic function; the keyword here is before. I realize there's no way to really access the individual arguments from within the macro definition, but is there a way to

Is there a way to use C++ preprocessor stringification on variadic macro arguments?

六月ゝ 毕业季﹏ 提交于 2020-01-09 07:35:30
问题 My guess is the answer to this question is no, but it would be awesome if there was a way. To clarify, assume I have the following macro: #define MY_VARIADIC_MACRO(X...) // Does some stuff here in the macro definition What I would like to do is somehow perform stringification on all the variables of X before passing it to a variadic function; the keyword here is before. I realize there's no way to really access the individual arguments from within the macro definition, but is there a way to

Callback with variadic template to ambiguous overloads

这一生的挚爱 提交于 2020-01-06 08:58:07
问题 In C++0X, I want to write generic caller/callback functions using variadic templates. First hurdle: The callees are member functions. So far so good. Second hurdle: There are many overloaded member functions of the same name. How would I solve this? My primary reference is this fine article, but I can't quite make it work. OK, let's dive in: Class Foo { void bar(int ID, int, int) { ... } void bar(int ID) { ... } void bar(int ID, double, float, void(Baz::*)()) const { /* jikes */ } template

C++ and preprocessor macros: variadic type

只谈情不闲聊 提交于 2020-01-04 08:22:53
问题 Take for example the following macro: #define _CREATE_VAR(X1) double X1{smc::define_variable (data, X1, #X1)}; #define _CREATE_VAR2(X1,X2) double X1{smc::define_variable (data, X1, #X1)}; / double X2{smc::define_variable (data, X2, #X2)}; / #define _CREATE_VAR3(X1,X2,X3) double X1{smc::define_variable (data, X1, #X1)}; / double X2{smc::define_variable (data, X2, #X2)}; / double X3{smc::define_variable (data, X3, #X3)}; / #define _CREATE_VAR4(X1,X2,X3,X4) double X1{smc::define_variable (data,

C++ and preprocessor macros: variadic type

♀尐吖头ヾ 提交于 2020-01-04 08:20:03
问题 Take for example the following macro: #define _CREATE_VAR(X1) double X1{smc::define_variable (data, X1, #X1)}; #define _CREATE_VAR2(X1,X2) double X1{smc::define_variable (data, X1, #X1)}; / double X2{smc::define_variable (data, X2, #X2)}; / #define _CREATE_VAR3(X1,X2,X3) double X1{smc::define_variable (data, X1, #X1)}; / double X2{smc::define_variable (data, X2, #X2)}; / double X3{smc::define_variable (data, X3, #X3)}; / #define _CREATE_VAR4(X1,X2,X3,X4) double X1{smc::define_variable (data,