You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+15-15Lines changed: 15 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,17 +7,17 @@
7
7
Examples can be found [here](https://github.com/Kaaserne/cpp-lazy/tree/master/examples). Installation can be found [here](https://github.com/Kaaserne/cpp-lazy#installation).
8
8
9
9
# cpp-lazy
10
-
`cpp-lazy` is an easy and fast lazy evaluation library for C++11/14/17/20. The library tries to reduce redundant data usage for begin/end iterator pairs. For instance: `lz::random_iterable::end()` will return a `lz::default_sentinel` to prevent duplicate data that is also present in `lz::random_iterable::begin()`. If a 'symmetrical' end-begin iterator pair is needed, one can use `lz::common` or `lz::common_random`. Generally, `lz`*forward* iterators will return a `lz::default_sentinel` (or if the input iterable is sentinelled) because forward iterators can only go forward, so there is no need to store the end iterator, is the philosophy.
10
+
`cpp-lazy` is an easy and fast lazy evaluation library for C++11/14/17/20. The library tries to reduce redundant data usage for begin/end iterator pairs. For instance: `lz::random_iterable::end()` will return a `lz::default_sentinel_t` to prevent duplicate data that is also present in `lz::random_iterable::begin()`. If a 'symmetrical' end-begin iterator pair is needed, one can use `lz::common` or `lz::common_random`. Generally, `lz`*forward* iterators will return a `lz::default_sentinel_t` (or if the input iterable is sentinelled) because forward iterators can only go forward, so there is no need to store the end iterator, is the philosophy. Lz random access iterators can also return a `default_sentinel` if the internal data of `begin` can already decide whether end is reached, such as `lz::repeat`.
11
11
12
12
The library uses one optional dependency: the library `{fmt}`, more of which can be found out in the [installation section](https://github.com/Kaaserne/cpp-lazy#Installation). This dependency is only used for printing and formatting.
13
13
14
14
# Features
15
15
- C++11/14/17/20 compatible
16
16
- Easy printing/formatting using `lz::format`, `fmt::print` or `std::cout`
17
17
- Tested with `-Wpedantic -Wextra -Wall -Wshadow -Wno-unused-function -Werror -Wconversion` and `/WX` for MSVC
18
-
- One optional dependency ([`{fmt}`](https://github.com/fmtlib/fmt)), can be turned off by using option `CPP-LAZY_USE_STANDALONE=TRUE` in CMake
19
-
- STL compatible
20
-
- Little overhead, as little as data usage possible
18
+
- One optional dependency ([`{fmt}`](https://github.com/fmtlib/fmt)), can be turned off by using option `CPP-LAZY_USE_STANDALONE=TRUE`/`set(CPP-LAZY_USE_STANDALONE TRUE)` in CMake
19
+
- STL compatible (if the input iterable is not sentinelled, otherwise use `lz::*` equivalents)
20
+
- Little overhead, as little data usage as possible
21
21
- Any compiler with at least C++11 support should be suitable
// Some iterables will return sentinels, for instance (specific rules about when sentinels are returned can be found in the documentation):
92
92
std::vector<int> vec = {1, 2, 3, 4};
93
-
auto forward = lz::c_string("Hello World"); // .end() returns default_sentinel
94
-
auto inf_loop = lz::loop(vec); // .end() returns default_sentinel
95
-
auto random = lz::random(0, 32, 4); // .end() returns default_sentinel
93
+
auto forward = lz::c_string("Hello World"); // .end() returns default_sentinel_t
94
+
auto inf_loop = lz::loop(vec); // .end() returns default_sentinel_t
95
+
auto random = lz::random(0, 32, 4); // .end() returns default_sentinel_t
96
96
97
97
// Some iterables are sized, if the input iterable is also sized:
98
98
auto sized = lz::map(vec, [](int i) { return i + 1; });
@@ -112,7 +112,7 @@ int main() {
112
112
```
113
113
114
114
## Ownership
115
-
`lz` iterables will hold a reference to the input iterable if the input iterable is *not* inherited from `lz::lazy_view`. This means that the `lz` iterables will hold a reference to (but not excluded to) containers such as `std::vector`, `std::array` and `std::string`, as they do not inherit from `lz::lazy_view`. This is done by the class `lz::ref_or_view`. This can be altered using `lz::copied_iterable` or `lz::as_copied_iterable`. This will copy the input iterable instead of holding a reference to it. This is useful for cheap to copy iterables that are not inherited from `lz::lazy_view` (for example `boost::iterator_range`).
115
+
`lz` iterables will hold a reference to the input iterable if the input iterable is *not* inherited from `lz::lazy_view`. This means that the `lz` iterables will hold a reference to (but not excluded to) containers such as `std::vector`, `std::array` and `std::string`, as they do not inherit from `lz::lazy_view`. This is done by the class `lz::maybe_owned`. This can be altered using `lz::copied` or `lz::as_copied`. This will copy the input iterable instead of holding a reference to it. This is useful for cheap to copy iterables that are not inherited from `lz::lazy_view` (for example `boost::iterator_range`).
116
116
117
117
```cpp
118
118
#include<Lz/lz.hpp>
@@ -143,18 +143,18 @@ int main() {
143
143
// str will *not* hold a reference to random, because random is a lazy iterable and is trivial to copy
144
144
auto str = lz::map(random, [](int i) { return std::to_string(i); });
145
145
146
-
lz::ref_or_view<std::vector<int>> ref(vec); // Holds a reference to vec
146
+
lz::maybe_owned<std::vector<int>> ref(vec); // Holds a reference to vec
147
147
148
148
using random_iterable = decltype(random);
149
-
lz::ref_or_view<random_iterable> ref2(random); // Does NOT hold a reference to random
149
+
lz::maybe_owned<random_iterable> ref2(random); // Does NOT hold a reference to random
lz::ref_or_view<non_lz_iterable> ref(non_lz); // Holds a reference of non_lz! Watch out for this!
152
+
lz::maybe_owned<non_lz_iterable> ref(non_lz); // Holds a reference of non_lz! Watch out for this!
153
153
154
-
// Instead, if you don't want this behaviour, you can use lz::copied_iterable:
155
-
lz::copied_iterable<non_lz_iterable> copied(non_lz); // Holds a copy of non_lz = cheap to copy
154
+
// Instead, if you don't want this behaviour, you can use `lz::copied`:
155
+
lz::copied<non_lz_iterable> copied(non_lz); // Holds a copy of non_lz = cheap to copy
156
156
// Or use the helper function:
157
-
copied = lz::as_copied_iterable(non_lz); // Holds a copy of non_lz = cheap to copy
157
+
copied = lz::as_copied(non_lz); // Holds a copy of non_lz = cheap to copy
158
158
}
159
159
```
160
160
@@ -209,7 +209,7 @@ The following CMake options are available:
209
209
-`CPP-LAZY_USE_STANDALONE`: Use the standalone version of cpp-lazy. This will not use the library `{fmt}`. Default is `FALSE`
210
210
-`CPP-LAZY_LZ_USE_MODULES` (experimental): Use C++20 modules. Default is `FALSE`
211
211
-`CPP-LAZY_USE_INSTALLED_FMT`: Use the installed version of `{fmt}`. This will not use the bundled version. Will use `find_package(fmt)` if enabled. Default is `FALSE`.
212
-
-`CPP-LAZY_DEBUG_ASSERTIONS`: Enable debug assertions in other build configurations than debug (debug is always enabled). Default is `FALSE`.
212
+
-`CPP-LAZY_DEBUG_ASSERTIONS`: Enable debug assertions. Default is `TRUE` for debug mode, `FALSE` for release.
213
213
214
214
### Using `FetchContent`
215
215
The following way is recommended (cpp-lazy version >= 5.0.1). Note that you choose the cpp-lazy-src.zip, and not the source-code.zip/source-code.tar.gz. This prevents you from downloading stuff that you don't need, and thus preventing pollution of the cmake build directory:
0 commit comments