GithubHelp home page GithubHelp logo

rah's Introduction

rah

rah is range, header-only, "single-file" C++14/17 library.

What is a range library?

A range is anything that can be iterated. Typically in C++ something is a range if we can call begin(range) and end(range) on it.

A range library allows to create ranges and algorithms using them.

Why a new range library?

Yes there are some great range libraries in C++, like range-v3 and boost::range.

rah is not as complete as those libraries, but the goal of rah is to be "single file" and easy to integrate, read and understand. rah was designed with code simplicity as top priority.

What is inside rah

  • Namespace rah contains a subset of usual algorithms present in <algorithm>, but useable in a range fashion
  • More algorithms will be added soon
// Usual code with STL
std::cout << std::count(range.begin(), range.end(), 2);
// Using range algorithm
std::cout << rah::count(range, 2);
  • rah::view contains functions to create ranges, actually doing work only when iterated (lazy), saving some memory and simplifying the code, especially when wanting to chain algorithms.
// Usual code with STL
std::vector<int> ints;
ints.resize(10);
std::iota(range.begin(), range.end(), 0);
std::vector<int> even;
std::copy_if(ints.begin(), ints.end(), std::back_inserter(even), [](int a) {return a % 2 == 0;});
std::vector<int> values;
std::transform(even.begin(), even.end(), std::back_inserter(values), [](int a) {return a * 2;});
for(int i: values)
    std::cout << i << std::endl;
// Using range algorithms
auto values = 
    rah::view::transform(
        rah::view::filter(
            rah::view::iota(0, 10), 
            [](int a) {return a % 2 == 0;})
        [](int a) {return a * 2;});
for(int i: values) // The job in done here, without memory allocation
    std::cout << i << std::endl;
  • Most of views have a pipeable version, making theme easier to write and read.
// Using pipeable range algorithms
auto values = rah::view::iota(0, 10)
    | rah::view::filter([](int a) {return a % 2 == 0;}) 
    | rah::view::transform([](int a) {return a * 2;});
for(int i: values) // The job in done here, without memory allocation
    std::cout << i << std::endl;

License

rah is licensed under the Boost Software License

Documentation

You can find the doc here

Supported Compilers

  • On Windows
    • Visual Studio 2015 (stdcpp14)
    • Visual Studio 2017 (stdcpp14 and stdcpp17)
    • clang 7 (-std=c++14 and -std=c++17)
  • On Linux
    • clang 4 and 5 (-std=c++14 and -std=c++17)
    • gcc 7,8 and 9 (-std=c++14 and -std=c++17)

Continuous integration

Linux

Build Status

Windows

Build status

How to use?

  • Just include the rah.hpp file in your project
  • range version of STL algorithms are in the rah namespace
  • Views are in rah::view namespace
  • Read the doc

The future of rah

  • Wrap more std algorithms
  • Add more ranges

rah's People

Contributors

lhamot avatar sebtoun avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

sebtoun

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.