Git Product home page Git Product logo

circular_buffer's Introduction

circular_buffer

A simple circular buffer implementation. Tests and documentation still needs work but I'd say it's working properly and the api is STL style.

Small example

#include "circular_buffer.hpp"

// constructors accept iterators, initializer lists or count + element
jm::circular_buffer<int, 4> cb{ 1,2,3 };
cb.push_back(4);  // 1234
cb.push_front(0); // 0123
cb.push_back(5);  // 1235
cb.pop_front(); // 235 also supports pop_back
// iterators are supported and constexpr ( except reverse ones because std::reverse_iterator ) 
for(auto& value : cb)
    std::cout << value; 
cb.size(); // 3
cb.max_size() // 4
cb.clear(); // 
// this can also be done constexpr.
// using c++14 the only non constexpr api is emplace_back and emplace_front

How to use

The library is a single header so all you need to do is copy the header to your directory and include it.

By default it uses c++ 11 features. However you can define JM_CIRCULAR_BUFFER_CXX_14 for most of the circular_buffer to become constexpr or JM_CIRCULAR_BUFFER_CXX_OLD for c++98 ( maybe even lower? ) support.

It is also possible to micro optimize the buffer ( on clang and gcc only ) if you know if it will likely be full or not by using JM_CIRCULAR_BUFFER_LIKELY_FULL OR JM_CIRCULAR_BUFFER_UNLIKELY_FULL.

circular_buffer's People

Contributors

justasmasiulis 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.