Skip to content

Instantly share code, notes, and snippets.

@devboy
Created July 9, 2013 22:23
Show Gist options
  • Select an option

  • Save devboy/5961848 to your computer and use it in GitHub Desktop.

Select an option

Save devboy/5961848 to your computer and use it in GitHub Desktop.
lambda macro
#define _lambda_param(index, ARG) id ARG,
#define _lambda_last_param(arg) id arg
#define _lambda_1_(statement) ^id(){ return statement; }
#define _lambda_2_(arg, statement) ^id(id arg){ return statement; }
#define _lambda_gt2_(...) ^id( metamacro_foreach( \
_lambda_param,,metamacro_take(metamacro_dec(metamacro_dec(metamacro_argcount(__VA_ARGS__))), __VA_ARGS__)) \
_lambda_last_param(metamacro_at(metamacro_dec(metamacro_dec(metamacro_argcount(__VA_ARGS__))), __VA_ARGS__)) \
){ return metamacro_at(metamacro_dec(metamacro_argcount(__VA_ARGS__)), __VA_ARGS__); }
#define lambda(...) \
metamacro_if_eq(1, metamacro_argcount(__VA_ARGS__))(_lambda_1_(__VA_ARGS__))\
(metamacro_if_eq(2, metamacro_argcount(__VA_ARGS__))(_lambda_2_(__VA_ARGS__))(_lambda_gt2_(__VA_ARGS__)))
@devboy
Copy link
Copy Markdown
Author

devboy commented Jul 9, 2013

Needs libextc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment