Loading...
Searching...
No Matches
Macros
macro_util.h File Reference

General macro utilities. More...

Go to the source code of this file.

Macros

#define BBM_PARENS   ()
 
#define BBM_PASS(...)   __VA_ARGS__
 Just pass the arguments.
 
#define BBM_CALL(macro, ...)   macro (__VA_ARGS__)
 Expand the args, then call the macro.
 
#define BBM_COMMA()   ,
 A comma.
 
#define BBM_EXPAND(...)   _BBM_EXPAND4(_BBM_EXPAND4(_BBM_EXPAND4(_BBM_EXPAND4(__VA_ARGS__))))
 Re-scan VA_ARGS 342 times. Part of BBM_FOREACH.
 
#define BBM_FOREACH_OPT(MACRO, OPT, ...)    __VA_OPT__(BBM_EXPAND(_BBM_FOREACH_OPT(MACRO, OPT, __VA_ARGS__)))
 A macro that applies a macro (MACRO) on every argument in VA_ARGS followed by an (OPT) macro (without arguments) except following the last argument in VA_ARGS.
 
#define BBM_FOR_EACH(MACRO, ...)   BBM_FOREACH_OPT(MACRO, , __VA_ARGS__)
 A macro that applies another macro (MACRO) on every argument in VA_ARGS (i.e., BBM_FOREACH_OPT with empty OPT-macro)
 
#define BBM_TO_STRING(...)   #__VA_ARGS__
 VA_ARGS => "__VA_ARGS__"
 
#define BBM_STRINGIFY(...)   BBM_TO_STRING(__VA_ARGS__)
 Expand VA_ARGS before converting to a string of comma separated elements.
 
#define BBM_STRINGIFY_EACH(...)   BBM_FOREACH_OPT(BBM_TO_STRING, BBM_COMMA, __VA_ARGS__)
 Expand VA_ARGS before converting to a comma separated series strings of elements.
 

Detailed Description

General macro utilities.

Macro Definition Documentation

◆ BBM_CALL

#define BBM_CALL (   macro,
  ... 
)    macro (__VA_ARGS__)

Expand the args, then call the macro.

◆ BBM_COMMA

#define BBM_COMMA ( )    ,

A comma.

◆ BBM_EXPAND

#define BBM_EXPAND (   ...)    _BBM_EXPAND4(_BBM_EXPAND4(_BBM_EXPAND4(_BBM_EXPAND4(__VA_ARGS__))))

Re-scan VA_ARGS 342 times. Part of BBM_FOREACH.

◆ BBM_FOR_EACH

#define BBM_FOR_EACH (   MACRO,
  ... 
)    BBM_FOREACH_OPT(MACRO, , __VA_ARGS__)

A macro that applies another macro (MACRO) on every argument in VA_ARGS (i.e., BBM_FOREACH_OPT with empty OPT-macro)

Parameters
MACRO= macro to apply to each
...= list of VA_ARGS

◆ BBM_FOREACH_OPT

#define BBM_FOREACH_OPT (   MACRO,
  OPT,
  ... 
)     __VA_OPT__(BBM_EXPAND(_BBM_FOREACH_OPT(MACRO, OPT, __VA_ARGS__)))

A macro that applies a macro (MACRO) on every argument in VA_ARGS followed by an (OPT) macro (without arguments) except following the last argument in VA_ARGS.

This code is based on https://www.scs.stanford.edu/~dm/blog/va-opt.html

Parameters
MACRO= macro to apply to each argument in VA_ARGS (takes one argument)
OPT= macro to apply between each argument in VA_ARGS (takes no arguments)
...= list of VA_ARGS

◆ BBM_PARENS

#define BBM_PARENS   ()

◆ BBM_PASS

#define BBM_PASS (   ...)    __VA_ARGS__

Just pass the arguments.

◆ BBM_STRINGIFY

#define BBM_STRINGIFY (   ...)    BBM_TO_STRING(__VA_ARGS__)

Expand VA_ARGS before converting to a string of comma separated elements.

BBM_STRINGIFY(a,b,c) => "a, b, c"

◆ BBM_STRINGIFY_EACH

#define BBM_STRINGIFY_EACH (   ...)    BBM_FOREACH_OPT(BBM_TO_STRING, BBM_COMMA, __VA_ARGS__)

Expand VA_ARGS before converting to a comma separated series strings of elements.

BBM_STRINGIFY_EACH(a,b,c) => "a", "b", "c"

◆ BBM_TO_STRING

#define BBM_TO_STRING (   ...)    #__VA_ARGS__

VA_ARGS => "__VA_ARGS__"