-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a4bdb6a
commit 4811445
Showing
1 changed file
with
17 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,30 @@ | ||
# pr::any_view | ||
# any_view | ||
|
||
```cpp | ||
#include <pr/any_view.hpp> | ||
|
||
#include <algorithm> | ||
#include <array> | ||
#include <ranges> | ||
#include <span> | ||
#include <vector> | ||
|
||
static_assert([] { | ||
using enum pr::any_kind; | ||
constexpr auto sum(pr::any_view<const int> view) { | ||
return std::ranges::fold_left(view, 0, std::plus{}); | ||
} | ||
|
||
pr::any_view<int, random_access | sized> view; | ||
std::array arr{10, 20, 30, 40, 50}; | ||
std::vector vec{1, 2, 3}; | ||
|
||
view = arr; | ||
view[4] = 42; | ||
view = vec; | ||
view[0] = 7; | ||
|
||
return arr[4] == 42 and vec[0] == 7 and view.size() == 3; | ||
}()); | ||
static_assert(150 == sum(std::array{10, 20, 30, 40, 50})); | ||
static_assert(100 == sum(std::ranges::views::repeat(20, 5))); | ||
static_assert(75 == sum(std::span<const int>{{5, 10, 15, 20, 25}})); | ||
static_assert(15 == sum(std::vector{1, 2, 3, 4, 5})); | ||
``` | ||
## Features: | ||
## Features | ||
- C++23 implementation | ||
- Clang and GCC support (MSVC support planned) | ||
- Fully constexpr and SFINAE-friendly | ||
- Supports: | ||
* Ranges of any iterator category including `contiguous_range<R>` | ||
* `borrowed_range<R>`, `range<const R>`, `copyable<R>`, and `sized_range<R>` | ||
- Type-erased interfaces for | ||
* all input range categories including `contiguous_range<R>` | ||
* `borrowed_range<R>`, `common_range<R>`, `copyable<R>`, `range<const R>`, and `sized_range<R>` | ||
- No allocation performed for small view and iterator types |