]> git.ozlabs.org Git - ccan/blob - ccan/cppmagic/cppmagic.h
cppmagic: New module
[ccan] / ccan / cppmagic / cppmagic.h
1 /* MIT (BSD) license - see LICENSE file for details */
2 #ifndef CCAN_CPPMAGIC_H
3 #define CCAN_CPPMAGIC_H
4
5 /**
6  * CPPMAGIC_NOTHING - expands to nothing
7  */
8 #define CPPMAGIC_NOTHING()
9
10 /**
11  * CPPMAGIC_STRINGIFY - convert arguments to a string literal
12  */
13 #define _CPPMAGIC_STRINGIFY(...)        #__VA_ARGS__
14 #define CPPMAGIC_STRINGIFY(...)         _CPPMAGIC_STRINGIFY(__VA_ARGS__)
15
16 /**
17  * CPPMAGIC_GLUE2 - glue arguments together
18  *
19  * CPPMAGIC_GLUE2(@a_, @b_)
20  *      expands to the expansion of @a_ followed immediately
21  *      (combining tokens) by the expansion of @b_
22  */
23 #define _CPPMAGIC_GLUE2(a_, b_)         a_##b_
24 #define CPPMAGIC_GLUE2(a_, b_)          _CPPMAGIC_GLUE2(a_, b_)
25
26 /**
27  * CPPMAGIC_1ST - return 1st argument
28  *
29  * CPPMAGIC_1ST(@a_, ...)
30  *      expands to the expansion of @a_
31  */
32 #define CPPMAGIC_1ST(a_, ...)           a_
33
34 /**
35  * CPPMAGIC_2ND - return 2nd argument
36  *
37  * CPPMAGIC_2ST(@a_, @b_, ...)
38  *      expands to the expansion of @b_
39  */
40 #define CPPMAGIC_2ND(a_, b_, ...)       b_
41
42 #endif /* CCAN_CPPMAGIC_H */