#ifndef __INC_BUFFER_H__ #define __INC_BUFFER_H__ template class Buffer : std::array { typedef std::array ArrayT; typedef typename ArrayT::reference reference; typedef typename ArrayT::const_reference const_reference; typedef typename ArrayT::size_type size_type; typedef typename ArrayT::value_type value_type; typedef typename ArrayT::iterator iterator; typedef typename ArrayT::const_iterator const_iterator; public: Buffer() : length(0) {} constexpr reference front() noexcept { return ArrayT::front(); } constexpr reference back() noexcept { return *(ArrayT::begin() + length); } constexpr T * data() noexcept { return ArrayT::data(); } constexpr iterator begin() noexcept { return ArrayT::begin();} constexpr const_iterator cbegin() const noexcept { return ArrayT::cbegin(); } constexpr iterator end() noexcept { return (ArrayT::begin() + length); } constexpr const_iterator cend() const noexcept { return (ArrayT::cbegin() + length); } constexpr size_type size() const noexcept {return length;} constexpr size_type max_size() const noexcept {return ArrayT::max_size();} constexpr void push_back(const_reference v) noexcept { *(this->begin() + length++) = v; }; constexpr void push_back(value_type&&v) noexcept { *(this->begin() + length++) = std::move(v); } inline void fill(const_reference &v){ ArrayT::fill(v); length = ArrayT::max_size(); } inline void fill(const_iterator b, const_iterator e) { std::copy(b, e, ArrayT::begin()); length = e - b; } inline void fill_n(const_iterator b, size_type s) { std::copy(b, b + s, ArrayT::begin()); length = s; } constexpr void clear() noexcept { this->length = 0; } private: size_type length; }; #endif