Created
July 9, 2013 22:23
-
-
Save devboy/5961848 to your computer and use it in GitHub Desktop.
lambda macro
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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__))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Needs libextc