#pragma once
#include <memory>

/// Generic containers
namespace data {
    /// Looping array
    template <class T>
    struct circular_buffer {
        circular_buffer(size_t size): size(size), buffer(std::unique_ptr<T[]>(new T[size])) { }
        circular_buffer(size_t size, const T& zero): circular_buffer(size) {
            for (size_t i = 0; i < size; i++) {
                buffer[i] = zero;
            }
        }

        size_t last = 0;
        size_t size;
        std::unique_ptr<T[]> buffer;

        void push(T in) {
            last = (last + 1) % size;
            buffer[last] = in;
        }
        T current() const {
            return buffer[last];
        }
    };
}
