Commit 1b6e3c9
committed
Align cpp demos with docs 51-60 (google_benchmark through lexical_analyzer)
Each cpp mirrors only what its doc covers, with short labeled demos.
- src/benchmark_demo.cpp: BENCHMARK(fn) + BENCHMARK_MAIN, CustomArguments
with Arg ranges, BENCHMARK_F fixture with SetUp/TearDown, DoNotOptimize
+ SetItemsProcessed throughput. Verified by configuring with
ENABLE_BENCHMARKING=ON.
- src/hash.cpp: std::hash<float|int|string> primitives, custom std::hash
specialization vs KeyHasher functor on a user-defined `student`, bucket
interface (bucket_count/load_factor/max_load_factor/bucket_size).
- src/heap_and_stack_memory_layout_of_C_programs.cpp: print addresses for
.text / .rodata / .data / .bss / heap / stack and confirm the expected
ascending ordering. Replaces a 4-line empty-main stub.
- Create src/immutable_objects.cpp: ImmutablePoint with const members,
deleted operator=, and a movedBy(dx,dy) const that returns a new copy.
- src/initialization.cpp: 10 sections mapping 1:1 to the doc (default-init,
value-init, direct-init, copy-init, list-init, aggregate, zero-init,
in-class member init, narrowing, std::initializer_list ctor) plus the
declaration-order trap and a most-vexing-parse comment.
- src/iterator_loop.cpp: input/output/forward/bidirectional/random-access
iterators, iterator_traits + category tag dispatch, minimal custom
SampleBuffer iterator, range-based for variants, cbegin loop,
next/advance/distance.
- src/json_example.cpp: 11 nlohmann/json sections from literals, parse,
dump, [] vs at, iteration, STL interop, exception types, json::array,
type checks, merge_patch, file I/O to /tmp.
- src/lambda.cpp: inline + stored lambda, file-scope lambda used with
std::for_each, [=] mutable vs [&] vs mixed [=, &y], template + std::function
acceptors. Removed topics the doc doesn't cover.
- Create src/lexical_analyzer.cpp: ~80-line hand-rolled lexer that
tokenizes the doc's exact example snippet (keywords / identifiers /
literals / scope_op :: / insertion_op << / punctuation).
- CMakeLists: add immutable_objects + lexical_analyzer executables.
- Skipped godbolt.md (meta-doc about Compiler Explorer).1 parent c47e1b0 commit 1b6e3c9
10 files changed
Lines changed: 894 additions & 376 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
97 | 97 | | |
98 | 98 | | |
99 | 99 | | |
| 100 | + | |
100 | 101 | | |
101 | 102 | | |
102 | 103 | | |
| |||
125 | 126 | | |
126 | 127 | | |
127 | 128 | | |
| 129 | + | |
128 | 130 | | |
129 | 131 | | |
130 | 132 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
| 2 | + | |
| 3 | + | |
2 | 4 | | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
3 | 16 | | |
4 | | - | |
5 | | - | |
6 | | - | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
7 | 24 | | |
8 | | - | |
9 | | - | |
10 | | - | |
11 | | - | |
12 | | - | |
13 | | - | |
14 | | - | |
15 | | - | |
| 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 | + | |
16 | 55 | | |
17 | | - | |
| 56 | + | |
18 | 57 | | |
19 | 58 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
1 | 4 | | |
2 | | - | |
3 | 5 | | |
4 | 6 | | |
5 | 7 | | |
6 | 8 | | |
7 | | - | |
8 | | - | |
9 | | - | |
10 | | - | |
11 | | - | |
12 | | - | |
13 | | - | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
21 | 12 | | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
37 | 16 | | |
38 | | - | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
39 | 21 | | |
| 22 | + | |
40 | 23 | | |
41 | 24 | | |
42 | 25 | | |
43 | 26 | | |
44 | 27 | | |
45 | 28 | | |
46 | 29 | | |
47 | | - | |
48 | | - | |
| 30 | + | |
| 31 | + | |
49 | 32 | | |
50 | 33 | | |
51 | 34 | | |
| 35 | + | |
52 | 36 | | |
53 | | - | |
54 | 37 | | |
55 | 38 | | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
| 39 | + | |
61 | 40 | | |
62 | 41 | | |
63 | 42 | | |
64 | 43 | | |
65 | | - | |
66 | 44 | | |
67 | 45 | | |
68 | | - | |
69 | 46 | | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | 47 | | |
| 48 | + | |
74 | 49 | | |
75 | 50 | | |
76 | | - | |
77 | 51 | | |
78 | 52 | | |
79 | 53 | | |
80 | 54 | | |
81 | 55 | | |
82 | 56 | | |
83 | 57 | | |
84 | | - | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
85 | 62 | | |
86 | 63 | | |
87 | 64 | | |
88 | | - | |
| 65 | + | |
| 66 | + | |
89 | 67 | | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
90 | 71 | | |
91 | 72 | | |
92 | | - | |
93 | | - | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
94 | 77 | | |
95 | 78 | | |
96 | 79 | | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
103 | 83 | | |
104 | | - | |
105 | 84 | | |
106 | 85 | | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | | - | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
118 | 94 | | |
119 | 95 | | |
120 | 96 | | |
121 | | - | |
122 | | - | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
123 | 102 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | | - | |
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
3 | 12 | | |
4 | | - | |
| 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 | + | |
0 commit comments