1 // Copyright 2003-2008 Jan Gaspar.
2 // Copyright 2013 Paul A. Bristow. Added some Quickbook snippet markers.
4 // Distributed under the Boost Software License, Version 1.0.
5 // (See the accompanying file LICENSE_1_0.txt
6 // or a copy at <http://www.boost.org/LICENSE_1_0.txt>.)
8 //[circular_buffer_example_1
9 /*`For all examples, we need this include:
12 #include <boost/circular_buffer.hpp>
14 //] [/circular_buffer_example_1]
19 //[circular_buffer_example_2
20 // Create a circular buffer with a capacity for 3 integers.
21 boost::circular_buffer<int> cb(3);
23 // Insert threee elements into the buffer.
28 int a = cb[0]; // a == 1
29 int b = cb[1]; // b == 2
30 int c = cb[2]; // c == 3
32 // The buffer is full now, so pushing subsequent
33 // elements will overwrite the front-most elements.
35 cb.push_back(4); // Overwrite 1 with 4.
36 cb.push_back(5); // Overwrite 2 with 5.
38 // The buffer now contains 3, 4 and 5.
43 // Elements can be popped from either the front or the back.
44 cb.pop_back(); // 5 is removed.
45 cb.pop_front(); // 3 is removed.
47 // Leaving only one element with value = 4.
48 int d = cb[0]; // d == 4
50 //] [/circular_buffer_example_2]
56 //[circular_buffer_example_output
58 There is no output from this example.
60 //] [/circular_buffer_example_output]