CX Framework
Cross-platform C utility framework
Loading...
Searching...
No Matches
optarg.h
Go to the documentation of this file.
1
6
7
#pragma once
8
9
#include "
args.h
"
10
29
30
#if !defined(_MSC_VER)
31
#define opt_arg(...) \
32
_opt_arg_dispatch_1(count_macro_args(dummy __VA_OPT__(, ) __VA_ARGS__), \
33
(dummy __VA_OPT__(, ) __VA_ARGS__))
34
#define _opt_arg_dispatch_1(n, args) _opt_arg_dispatch_2(n, args)
35
#define _opt_arg_dispatch_2(n, args) _opt_arg_##n args
36
#define _opt_arg_1(f1) 0
37
#define _opt_arg_2(f1, f2) f2
38
39
// legacy compatibility
40
#define opt_flags(...) \
41
_opt_arg_dispatch_1(count_macro_args(dummy __VA_OPT__(, ) __VA_ARGS__), \
42
(dummy __VA_OPT__(, ) __VA_ARGS__))
43
#else
44
// Hacky workaround for MSVC's broken preprocessor
45
#define opt_arg(...) \
46
_opt_arg_expand(_opt_arg_dispatch(_opt_arg_catch_empty##__VA_ARGS__, __VA_ARGS__))
47
#define _opt_arg_expand(x) x
48
#define _opt_arg_catch_empty dummy1, _opt_arg_catch_paren
49
#define _opt_arg_catch_paren(x) dummy3, dummy4
50
#define _opt_arg_dispatch2(_1, _2, _3, _4, MACRO, ...) MACRO
51
#define _opt_arg_dispatch(...) \
52
_opt_arg_expand(_opt_arg_dispatch2(__VA_ARGS__, \
53
_opt_arg_1a, \
54
_opt_arg_0, \
55
_opt_arg_1, \
56
ERROR)(__VA_ARGS__))
57
#define _opt_arg_0(...) 0
58
#define _opt_arg_1(dummy1, f1) f1
59
#define _opt_arg_1a(dummy1, dummy2, dummy3, f1) f1
60
61
// legacy compatibility
62
#define opt_flags(...) \
63
_opt_arg_expand(_opt_arg_dispatch(_opt_arg_catch_empty##__VA_ARGS__, __VA_ARGS__))
64
#endif
65
args.h
Macro argument counting utilities.
cx
utils
macros
optarg.h
Generated by
1.9.8