X-Git-Url: https://git.ozlabs.org/?a=blobdiff_plain;f=ccan%2Fcppmagic%2Fcppmagic.h;fp=ccan%2Fcppmagic%2Fcppmagic.h;h=f29e0ec6cee39b39114f3849dadce50d00a2f6e3;hb=ff71198b4e75fcaaedad34a4e362a3982a936e3e;hp=0000000000000000000000000000000000000000;hpb=c43be6b888aa75d2a8d7fcc878534a9cad04176b;p=ccan diff --git a/ccan/cppmagic/cppmagic.h b/ccan/cppmagic/cppmagic.h new file mode 100644 index 00000000..f29e0ec6 --- /dev/null +++ b/ccan/cppmagic/cppmagic.h @@ -0,0 +1,42 @@ +/* MIT (BSD) license - see LICENSE file for details */ +#ifndef CCAN_CPPMAGIC_H +#define CCAN_CPPMAGIC_H + +/** + * CPPMAGIC_NOTHING - expands to nothing + */ +#define CPPMAGIC_NOTHING() + +/** + * CPPMAGIC_STRINGIFY - convert arguments to a string literal + */ +#define _CPPMAGIC_STRINGIFY(...) #__VA_ARGS__ +#define CPPMAGIC_STRINGIFY(...) _CPPMAGIC_STRINGIFY(__VA_ARGS__) + +/** + * CPPMAGIC_GLUE2 - glue arguments together + * + * CPPMAGIC_GLUE2(@a_, @b_) + * expands to the expansion of @a_ followed immediately + * (combining tokens) by the expansion of @b_ + */ +#define _CPPMAGIC_GLUE2(a_, b_) a_##b_ +#define CPPMAGIC_GLUE2(a_, b_) _CPPMAGIC_GLUE2(a_, b_) + +/** + * CPPMAGIC_1ST - return 1st argument + * + * CPPMAGIC_1ST(@a_, ...) + * expands to the expansion of @a_ + */ +#define CPPMAGIC_1ST(a_, ...) a_ + +/** + * CPPMAGIC_2ND - return 2nd argument + * + * CPPMAGIC_2ST(@a_, @b_, ...) + * expands to the expansion of @b_ + */ +#define CPPMAGIC_2ND(a_, b_, ...) b_ + +#endif /* CCAN_CPPMAGIC_H */