c++ - Can I make macro like `MACRO(x, Type1 t1, Type2 t2)` -
i want make code smaller. think macros make code smaller.
want make macro contains objects declarations.
there switch cases
case sign_up: { std::string username; std::string password getargs(args, username, password); sv.signup(username, password); } break; case sign_in: { std::string username; std::string password getargs(args, username, password); sv.signin(username, password); } break; case something: { std::string s; int i; getargs(args, s, i); sv.something(s, i); } break;
i want make macro make code like
case sign_up: get_args(args, std::string username, std::string password); sv.signup(username, password); break; case sign_in: get_args(args, std::string username, std::string password); sv.signin(username, password); break; case something: get_args(args, std::string s, int i); sv.something(s, i); break;
is possible?
you can use following macro:
#define get_args(args, firsttype, firstname, secondtype, secondname) \ firsttype firstname;\ secondtype secondname;\ getargs(args, firstname, secondname);
not asked - little bit more writing required:
get_args(args, std::string, name, std::string, password);
as can see have use more commas comparing you've asked for. me doesn't make difference, though.
Comments
Post a Comment