dcousens / ranger

A header-only library for wrapping C++ STL iterators in a range-like interface.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ranger

An attempt at a header-only range library for wrapping C++ STL iterators in a range-like interface.

WARNING: There is no assured bounds protection.

The library does have some asserts internally for debugging purposes, but you still need to watch out for any undefined behaviour from your iterators, e.g dereferencing past end.

WARNING: This library is a work in progress, please report any bugs! If you need something production safe, this isn't the library for you.

Example

#include <ranger/ranger.hpp>

// ...

std::vector<int> numbers = {1, 2, 3};

for (auto &x : ranger::reverse(numbers)) {
	std::cout << x << ' ';
}
// 3, 2, 1

auto a = ranger::range(numbers).take(2); // {1, 2}
a[1] = 8; // {1, 8}

numbers.push_back(9);

auto b = ranger::range(numbers).drop(1); // {8, 3, 9}
auto c = ranger::reverse(b); // {9, 3, 8}

LICENSE MIT

Parts of this work are inspired by the concepts used in ranges as seen in the D programming language.

About

A header-only library for wrapping C++ STL iterators in a range-like interface.

License:MIT License


Languages

Language:C++ 99.6%Language:Makefile 0.4%