Giter Site home page Giter Site logo

itertools-cxx's Introduction

Iterator Tools

Clang Format status-badge

This is a collection of iterator templates to perform interator chaining in C++. This is by far no proven solution. It's just a personal playground and thus doesn't provide anything special and may be broken. Please be aware and look somewhere else for actively maintained libraries that provide a more fully featured implementation.

Iterator Chaining

This header library provides the functionality to perform chained operations on a any given container. The only requirement is that the container provides access to the beginning and end of the container via the .begin() and .end() functions. All chained operation are only applied if .next(), .collectInsert() (for containers with support of .insert()) or .collectPush() (for containers with support of .push_back()) is called.

Supported Functionality

  • map : Map the given values of the iterator into another type/value
  • filter : Filter the iterator based on a lamda function
  • zip : Combine two iterators into one to iterate over pairs of both
  • enumerate : Iterate over values and their indices
  • product : Create product of all values based on operator*
  • sum : Create sum of all values based on operator+

Usage

// Create any container providing .begin() and .end(), e.g. std::vector
std::vector<int> values = { 0x41, 0x42, 0x43, 0x44, 0x45, 0x46 };

// Now we can create the iterator wrapper from the container
auto iterator = itertools::Iterator::from(values);

// .. and apply any of the supported chaining operations

// map all values to char
auto iterator = itertools::Iterator::from(values).map<char>([](int &i) { return static_cast<char>(i); })

// filter all even values
auto iterator = itertools::Iterator::from(values).filter([](int &i) { return i % 2 == 0; })

// zip two iterators (note: the .into() call is necessary for the type change)
auto iterator = itertools::Iterator::from(v2).zip<char>(itertools::Iterator::from(v3).into())

// or chain everything
auto iterator = itertools::Iterator::from(values)
                    .filter([](int &i) { return i % 2 == 0; })
                    .map<char>([](int &i) { return static_cast<char>(i); })
                    .zip<char>(itertools::Iterator::from(v3).into())

itertools-cxx's People

Contributors

tumbleowlee avatar

Stargazers

 avatar

Watchers

 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.