Giter Site home page Giter Site logo

cpp_range's Introduction

C++ Range

Travis Build Status Appveyor Build status

Have your cake and eat it too. Who says you can't have nice things in an efficient, type-safe, compiled language? Don't let your Python-slinging coworkers have the last laugh, this is C++ Range:

#include <iostream>
#include "range.h"

using namespace whoshuu;

int main(int argc, char** argv) {
    for (auto i : range(100)) {
        std::cout << i << std::endl; // Prints 0 to 99
    }

    for (auto i : range(10, 100)) {
        std::cout << i << std::endl; // Prints 10 to 99
    }

    for (auto i : range(10, 0, -1) {
        std::cout << i << std::endl; // Prints 10 to 1, counting down
    }

    for (auto i : range(2.718, 100.0, 3.14) {
        std::cout << i << std::endl; // Prints 2.178 to 96.918, by increments of ฯ€, yum!
    }
}

Benchmarks

Here's a benchmark using gcc-5.1 with -O2 optimization of my library against a naive vector range implementation and basic for-loop:

C++ Range Benchmark

As you can see, C++ Range behaves identically to a basic for-loop, and both outperform the vector implementation considerably (the last data point is left off because it would ruin the nice benchmark image here!).

You can find raw data for the analysis here.

Install

Just throw the header into your project, be wary of the whoshuu namespace, and let it rip!

Other libraries

For a more fully featured iterator toolset, check out Ryan Haining's cppitertool library, which implements most of the Python itertool module in C++. There's also Eric Niebler's range-v3, a formally proposed range library for the C++ standard library.

Requirements

The only explicit requirement is a C++11 compatible compiler such as clang, gcc, or a recent version of MSVC. The minimum required version of gcc is unknown, so if anyone has trouble using library with a specific version of gcc, do let me know.

Contributing

Please fork this repository and contribute back using pull requests. Features can be requested using issues. All code, comments, and critiques are greatly appreciated.

cpp_range's People

Contributors

aadebuger avatar romainletendart avatar whoshuu avatar

Watchers

 avatar  avatar

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.