/
P1748-fill-delay-cpp-section-in-P1389.bs
94 lines (77 loc) · 2.49 KB
/
P1748-fill-delay-cpp-section-in-P1389.bs
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<pre class='metadata'>
Title: Fill in [delay.cpp] TODO in P1389
Status: P
Audience: SG20
Editor: Yehezkel Bernat, YehezkelShB@gmail.com
Shortname: P1748
Abstract: P1748 adds wording to replace the TODO of [delay.cpp] section in P1389
Group: WG21
Date: 2019-10-07
Markup Shorthands: markdown yes
Revision: 1
Default Highlight: CPP
ED: https://yehezkelshb.github.io/cpp_proposals/sg20/P1748-fill-delay-cpp-section-in-P1389.html
!Source: <a href="https://github.com/YehezkelShB/cpp_proposals/blob/master/sg20/P1748-fill-delay-cpp-section-in-P1389.bs">GitHub</a>
</pre>
<style>
.ins, ins, ins *, span.ins, span.ins * {
background-color: rgb(200, 250, 200);
color: rgb(0, 136, 0);
text-decoration: none;
}
.del, del, del *, span.del, span.del * {
background-color: rgb(250, 200, 200);
color: rgb(255, 0, 0);
text-decoration: line-through;
text-decoration-color: rgb(255, 0, 0);
}
</style>
Revision History {#rev}
================
r0: initial revision, pre-Cologne mailing
r1:
- update "generic function" example based on feedback from sg20 in Cologne
- style update
Proposed Wording {#word}
================
Under 2.3.5 C Preprocessor [**delay.cpp**]:
<del>
Excludes `#include`, which is necessary until modules are in C++.
TODO
</del>
<ins>
Most of the traditional usages of the C Preprocessor have better and safer C++ replacements.
For example:
```cpp
// compile-time constant
#define BUFFER_SIZE 256
// better as:
auto constexpr buffer_size = 256;
// named constants
#define RED 0xFF0000
#define GREEN 0x00FF00
#define BLUE 0x0000FF
// better as:
enum class Color { red = 0xFF0000, green = 0x00FF00, blue = 0x0000FF };
// inline function
#define SUCCEEDED(res) (res == 0)
// better as:
inline constexpr bool succeeded(int const res) { return res == 0; }
// generic function
#define IS_NEGATIVE(x) ((x) < 0)
// better as:
template <typename T>
bool is_negative(T x) {
return x < T{};
}
```
All these macros have many possible pitfalls (see [gcc docs](https://gcc.gnu.org/onlinedocs/cpp/Macro-Pitfalls.html#Macro-Pitfalls)),
they hard to get right and they don't obey scope and type rules. The C++
replacements are easier to get right and fit better into the general picture.
The only preprocessor usages that are necessary right at the beginning are:
* `#include` for textual inclusion of header files (at least until modules
become the main tool for consuming external code)
* `#ifndef` for creating "include guards" to prevent multiple inclusion
</ins>
Acknowledgements {#acknowledgements}
================