-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpreprocessor_comparison.h
66 lines (53 loc) · 2.02 KB
/
preprocessor_comparison.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*
* CREATED BY SHPEGUN60
*
* CHAR LITERALS EQUALUATION MACROCES
*/
#ifndef __PREPROCESSOR_COMPARISON_H__
#define __PREPROCESSOR_COMPARISON_H__ 1
/* -- Headers -- */
#include "preprocessor_detection.h"
#include "preprocessor_logical.h"
#include "preprocessor_if.h"
#include "preprocessor_symbol.h"
#ifdef __cplusplus
extern "C" {
#endif
/* -- Macros -- */
/************************************************************************************************************************************************************
*
* USE:
* #define foo(x) x
* #define bar(x) x
*
* PREPROCESSOR_PRIMITIVE_COMPARE(foo, bar) // Expands to 1
* PREPROCESSOR_PRIMITIVE_COMPARE(foo, foo) // Expands to 0
*
* PREPROCESSOR_NOT_EQUAL(foo, bar) // Expands to 1
* PREPROCESSOR_NOT_EQUAL(foo, foo) // Expands to 0
* PREPROCESSOR_NOT_EQUAL(foo, unfoo) // Expands to 1
*
* PREPROCESSOR_EQUAL(foo, bar) // Expands to 0
* PREPROCESSOR_EQUAL(foo, foo) // Expands to 1
* PREPROCESSOR_EQUAL(foo, unfoo) // Expands to 0 (unfoo is not defined)
*
***********************************************************************************************************************************************************
*/
#define PREPROCESSOR_IS_COMPARABLE(x) _PREPROCESSOR_IS_COMPARABLE(x) // expand x
#define _PREPROCESSOR_IS_COMPARABLE(x) PREPROCESSOR_IS_PAREN(x(()))
#define PREPROCESSOR_PRIMITIVE_COMPARE(x, y) _PREPROCESSOR_PRIMITIVE_COMPARE(x, y) // expand x, y
#define _PREPROCESSOR_PRIMITIVE_COMPARE(x, y) PREPROCESSOR_IS_PAREN \
( \
x(y)(()) \
)
#define PREPROCESSOR_NOT_EQUAL(x, y) _PREPROCESSOR_NOT_EQUAL(x, y) // expand x, y
#define _PREPROCESSOR_NOT_EQUAL(x, y) \
PREPROCESSOR_IF_ELSE(PREPROCESSOR_BITAND(PREPROCESSOR_IS_COMPARABLE(x))(PREPROCESSOR_IS_COMPARABLE(y))) ( \
PREPROCESSOR_PRIMITIVE_COMPARE, \
1 PREPROCESSOR_EAT \
)(x, y)
#define PREPROCESSOR_EQUAL(x, y) PREPROCESSOR_NOT(PREPROCESSOR_NOT_EQUAL(x, y))
#ifdef __cplusplus
}
#endif
#endif /* __PREPROCESSOR_COMPARISON_H__ */