-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdrafts
67 lines (60 loc) · 1.64 KB
/
drafts
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
67
---
title: C++ Without Macros
date: 2019-10-04
category: code
---
## Why Avoid Macros
Macros pollute the global namespace, look deceptively like function
calls, break static analysis and syntax highlighting, aren't typed,
don't parse commas properly, make error messages and stack traces
harder to read, aren't deterministic, have overcomplicated expansion
rules, don't provide unique identifiers, are limited to a single line
and don't expand to atomic expressions or statements that respect
operator precedence or the need for a semicolon.
Work-arounds for these limitations lead to ugly code which can, in most cases, better be expressed using other C++ constructs.
## Attributes
## Constants
## C Idioms
## Inline Functions
## Templates
## Counters
## Constexpr
## Source Location
- std::source_location
## Localisation
## Debugging
## Generating Names
## Enum Helpers
## Class Helpers
- CRTP
## Custom Blocks
- my_catch
- foreach
## Metaprogramming
- Boost PP
## X Macros
## Self Inclusion
## Using Undeclared Types And Variables
## Short-Circuiting
## Header Guards
## RTTI
## Array Size
## Offset Of
## Class Boilerplate
- getters/setters
- constructors/assignment
- arithmetic/comparision
## Error Handling
## Includes
## Anonymous Objects
- finally
- lock guard
## Includes
## Reflection
## Serialisation And Deserialisation
## Unavoidable Macros
- https://docs.microsoft.com/en-us/cpp/preprocessor/predefined-macros
- https://gcc.gnu.org/onlinedocs/cpp/Predefined-Macros.html#Predefined-Macros
- https://en.cppreference.com/w/cpp/preprocessor/replace#Predefined_macros
## Minimal Macros
- only put the essence of the macro in the macro, use standard C++ for the rest