https://github.com/potatomaster101/rfrange
Control a range in C++'s range-based for loops
https://github.com/potatomaster101/rfrange
cpp17 header-only loops mit-license ranged-for
Last synced: about 1 month ago
JSON representation
Control a range in C++'s range-based for loops
- Host: GitHub
- URL: https://github.com/potatomaster101/rfrange
- Owner: PotatoMaster101
- License: mit
- Created: 2020-08-28T12:38:29.000Z (almost 6 years ago)
- Default Branch: main
- Last Pushed: 2021-08-27T10:07:10.000Z (almost 5 years ago)
- Last Synced: 2025-11-10T21:08:59.381Z (9 months ago)
- Topics: cpp17, header-only, loops, mit-license, ranged-for
- Language: C++
- Homepage:
- Size: 59.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Ranged For Range
Controls a range for C++'s range-based `for` loops. Useful for skipping over some starting/ending elements when using range-based `for`. Tested with C++17.
## Quick Start
### Using Random Access Iterator
```cpp
std::vector v{1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
for (const auto& n : rf::range{v.begin() + 3, v.end() - 2})
std::cout << n << ' '; // will print 4 5 6 7 8
```
### Using Bidirectional Iterator
```cpp
std::list l{1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
for (const auto& n : rf::range{std::next(l.begin(), 3), std::prev(l.end(), 2)})
std::cout << n << ' '; // will print 4 5 6 7 8
```
## Building Test
```
$ cmake -B bin -DRFRANGE_BUILD_TESTS=1
$ cmake --build bin
```