#define UNIT r6_bounded #include class insufficient_space {}; class bounded_queue { std::vector< int > _data; int _first = 0, _count = 0; public: explicit bounded_queue( int cnt ) : _data( cnt ) {} bool empty() const { return !_count; } bool full() const { return _count == int( _data.size() ); } int next() const { return _data[ _first ]; } int pop() { int rv = _data[ _first ++ ]; _first %= _data.size(); -- _count; return rv; } void push( int v ) { if ( full() ) throw insufficient_space(); _data[ ( _first + _count ) % _data.size() ] = v; ++ _count; } }; #include "test_main.cpp"