A header-only C++ 23 container providing a circular buffer where
begin()points to the oldest written element andend()to the newest.
- General Information
- Technologies Used
- Features
- Setup
- Usage
- Project Status
- Room for Improvement
- Acknowledgements
- License
forward_circular_bufferis a fixed-size circular buffer implementation usingstd::arrayas storage.- Iteration order starts from the oldest element and proceeds forward to the newest.
- It provides contiguous-style iterators, random access, and STL-like semantics (
begin,end,rbegin, etc.).
- C++ 23
- STL (
std::array,std::iterator,std::construct_at,std::destroy_at) - Custom runtime assertions via
stdfunc::assert
- Fixed-capacity, compile-time sized circular buffer (N elements)
- Iteration order: oldest - newest
begin(),end(),rbegin(),rend()with full iterator support- STL-like interface (push_back, emplace_back, pop_back, front, back, clear, fill)
- Compile-time safety via concepts and assertions
- Works with trivially or non-trivially constructible types
- Header-only - no linking required
There are no external dependencies other than the C++ 23 standard library and stdfunc for assertions.
To use it:
#include "forward_circular_buffer.hpp"See config.sh for what to include.
#include <print>
#include "forward_circular_buffer.hpp"
auto main() -> int {
fcb::forwardCircularBuffer_t< int, 5 > l_buffer;
l_buffer.push_back( 1 );
l_buffer.push_back( 2 );
l_buffer.push_back( 3 );
for (auto _value : l_buffer) {
std::print( "{} ", _value ); // Output: 1 2 3
}
l_buffer.pop_back(); // Removes 3
l_buffer.push_back( 4 );
l_buffer.push_back( 5 );
for (auto _value : l_buffer) {
std::print( "{} ", _value ); // Output: 1 2 4 5
}
return ( EXIT_SUCCESS );
}begin() returns the oldest written element, and end() refers to current write position.
front() and back() give the oldest and most recently written elements respectively.
Project is: in progress.
To do:
- Add
erase()andinsert()operations - Implement
begin(),end()
- This project was based on
std::arrayandstd::vector.
This project is open source and available under the GNU Affero General Public License v3.0.