@@ -36,13 +36,9 @@ To generate implementations, define `ARRAY_ALG_IMPLEMENTATION` in a C file and i
36
36
#define ARRAY_ALG_IMPLEMENTATION
37
37
#include "array_alg.h"
38
38
39
- Alternatively, you can include the algorithms as static functions to avoid the need for separate implementations:
40
39
41
- #define ARRAY_ALG_STATIC
42
- #define ARRAY_ALG_TYPE int
43
- #define ARRAY_ALG_PREFIX intv_
44
- #define ARRAY_ALG_IMPLEMENTATION
45
- #include "array_alg.h"
40
+ Alternatively, add ` #define ARRAY_ALG_STATIC ` before the original declaration
41
+ to avoid the need for separate implementations.
46
42
47
43
Repeat this process for each array type you want to use.
48
44
@@ -67,7 +63,7 @@ Remove duplicate entries:
67
63
68
64
## Design
69
65
70
- 1 . Iterators and Arrays
66
+ ### 1. Iterators and Arrays
71
67
72
68
The C++ STL is designed around the concept of iterators.
73
69
With iterators, one algorithm can be reused not just for multiple types, but also for many data structures.
@@ -79,7 +75,7 @@ For those cases where you do have a fancy data structure (graphs, trees, etc),
79
75
copy its contents to an array, perform the algorithm, and then copy the contents back.
80
76
This will often help it perform better anyway!
81
77
82
- 2 . Bounds vs counted ranges
78
+ ### 2. Bounds vs counted ranges
83
79
84
80
STL algorithms typically operate on half-open ranges bounded by iterators [ first, last).
85
81
This convention is not used as often in C, but we think it offers some benefits.
@@ -90,7 +86,7 @@ Operations also compose a little easier.
90
86
When a pointer is returned to an element of interest,
91
87
that same pointer can be used as an argument for another algorithm.
92
88
93
- 3 . What's left out
89
+ ### 3. What's left out
94
90
95
91
Because it's a bit verbose to define a C closure (function pointer and context), some STL algorithms are less useful in C.
96
92
If an algorithm can be written as a simple for loop with no additional state or control flow, this library doesn't implement it.
@@ -103,7 +99,7 @@ If an algorithm can be written as a simple for loop with no additional state or
103
99
The algorithms which rely on ordered types always require a comparison function.
104
100
We do not include any variants that operate on the ` == ` operator, as operators cannot be overloaded in C.
105
101
106
- 4 . Generics vs ` void* `
102
+ ### 4. Generics vs ` void* `
107
103
108
104
Including a header multiple times with various ` #define ` s is a little cumbersome.
109
105
However, we think it's a superior way to achieve C generics compared to the ` void* ` style used by ` qsort ` and ` bsearch ` .
0 commit comments