summaryrefslogtreecommitdiffstats
path: root/src/boost/libs/circular_buffer/example
diff options
context:
space:
mode:
Diffstat (limited to 'src/boost/libs/circular_buffer/example')
-rw-r--r--src/boost/libs/circular_buffer/example/bounded_buffer_comparison.cpp316
-rw-r--r--src/boost/libs/circular_buffer/example/circular_buffer_bound_example.cpp192
-rw-r--r--src/boost/libs/circular_buffer/example/circular_buffer_example.cpp63
-rw-r--r--src/boost/libs/circular_buffer/example/circular_buffer_examples.bat14
-rw-r--r--src/boost/libs/circular_buffer/example/circular_buffer_iter_example.cpp40
-rw-r--r--src/boost/libs/circular_buffer/example/circular_buffer_sum_example.cpp64
-rw-r--r--src/boost/libs/circular_buffer/example/jamfile.v242
7 files changed, 731 insertions, 0 deletions
diff --git a/src/boost/libs/circular_buffer/example/bounded_buffer_comparison.cpp b/src/boost/libs/circular_buffer/example/bounded_buffer_comparison.cpp
new file mode 100644
index 000000000..69ab224e0
--- /dev/null
+++ b/src/boost/libs/circular_buffer/example/bounded_buffer_comparison.cpp
@@ -0,0 +1,316 @@
+// Comparison of bounded buffers based on different containers.
+
+// Copyright (c) 2003-2008 Jan Gaspar
+// Copyright 2013 Paul A. Bristow. Added some Quickbook snippet markers.
+
+// Use, modification, and distribution is subject to the Boost Software
+// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+#include <boost/circular_buffer.hpp>
+#include <boost/thread/mutex.hpp>
+#include <boost/thread/condition.hpp>
+#include <boost/thread/thread.hpp>
+#include <boost/timer/timer.hpp>
+#include <boost/call_traits.hpp>
+#include <boost/bind.hpp>
+#include <deque>
+#include <list>
+#include <string>
+#include <iostream>
+
+const unsigned long QUEUE_SIZE = 1000L;
+const unsigned long TOTAL_ELEMENTS = QUEUE_SIZE * 1000L;
+
+template <class T>
+class bounded_buffer {
+public:
+
+ typedef boost::circular_buffer<T> container_type;
+ typedef typename container_type::size_type size_type;
+ typedef typename container_type::value_type value_type;
+ typedef typename boost::call_traits<value_type>::param_type param_type;
+
+ explicit bounded_buffer(size_type capacity) : m_unread(0), m_container(capacity) {}
+
+ void push_front(param_type item) {
+ boost::mutex::scoped_lock lock(m_mutex);
+ m_not_full.wait(lock, boost::bind(&bounded_buffer<value_type>::is_not_full, this));
+ m_container.push_front(item);
+ ++m_unread;
+ lock.unlock();
+ m_not_empty.notify_one();
+ }
+
+ void pop_back(value_type* pItem) {
+ boost::mutex::scoped_lock lock(m_mutex);
+ m_not_empty.wait(lock, boost::bind(&bounded_buffer<value_type>::is_not_empty, this));
+ *pItem = m_container[--m_unread];
+ lock.unlock();
+ m_not_full.notify_one();
+ }
+
+private:
+ bounded_buffer(const bounded_buffer&); // Disabled copy constructor
+ bounded_buffer& operator = (const bounded_buffer&); // Disabled assign operator
+
+ bool is_not_empty() const { return m_unread > 0; }
+ bool is_not_full() const { return m_unread < m_container.capacity(); }
+
+ size_type m_unread;
+ container_type m_container;
+ boost::mutex m_mutex;
+ boost::condition m_not_empty;
+ boost::condition m_not_full;
+};
+
+template <class T>
+class bounded_buffer_space_optimized {
+public:
+
+ typedef boost::circular_buffer_space_optimized<T> container_type;
+ typedef typename container_type::size_type size_type;
+ typedef typename container_type::value_type value_type;
+ typedef typename boost::call_traits<value_type>::param_type param_type;
+
+ explicit bounded_buffer_space_optimized(size_type capacity) : m_container(capacity) {}
+
+ void push_front(param_type item) {
+ boost::mutex::scoped_lock lock(m_mutex);
+ m_not_full.wait(lock, boost::bind(&bounded_buffer_space_optimized<value_type>::is_not_full, this));
+ m_container.push_front(item);
+ lock.unlock();
+ m_not_empty.notify_one();
+ }
+
+ void pop_back(value_type* pItem) {
+ boost::mutex::scoped_lock lock(m_mutex);
+ m_not_empty.wait(lock, boost::bind(&bounded_buffer_space_optimized<value_type>::is_not_empty, this));
+ *pItem = m_container.back();
+ m_container.pop_back();
+ lock.unlock();
+ m_not_full.notify_one();
+ }
+
+private:
+
+ bounded_buffer_space_optimized(const bounded_buffer_space_optimized&); // Disabled copy constructor
+ bounded_buffer_space_optimized& operator = (const bounded_buffer_space_optimized&); // Disabled assign operator
+
+ bool is_not_empty() const { return m_container.size() > 0; }
+ bool is_not_full() const { return m_container.size() < m_container.capacity(); }
+
+ container_type m_container;
+ boost::mutex m_mutex;
+ boost::condition m_not_empty;
+ boost::condition m_not_full;
+};
+
+template <class T>
+class bounded_buffer_deque_based {
+public:
+
+ typedef std::deque<T> container_type;
+ typedef typename container_type::size_type size_type;
+ typedef typename container_type::value_type value_type;
+ typedef typename boost::call_traits<value_type>::param_type param_type;
+
+ explicit bounded_buffer_deque_based(size_type capacity) : m_capacity(capacity) {}
+
+ void push_front(param_type item) {
+ boost::mutex::scoped_lock lock(m_mutex);
+ m_not_full.wait(lock, boost::bind(&bounded_buffer_deque_based<value_type>::is_not_full, this));
+ m_container.push_front(item);
+ lock.unlock();
+ m_not_empty.notify_one();
+ }
+
+ void pop_back(value_type* pItem) {
+ boost::mutex::scoped_lock lock(m_mutex);
+ m_not_empty.wait(lock, boost::bind(&bounded_buffer_deque_based<value_type>::is_not_empty, this));
+ *pItem = m_container.back();
+ m_container.pop_back();
+ lock.unlock();
+ m_not_full.notify_one();
+ }
+
+private:
+
+ bounded_buffer_deque_based(const bounded_buffer_deque_based&); // Disabled copy constructor
+ bounded_buffer_deque_based& operator = (const bounded_buffer_deque_based&); // Disabled assign operator
+
+ bool is_not_empty() const { return m_container.size() > 0; }
+ bool is_not_full() const { return m_container.size() < m_capacity; }
+
+ const size_type m_capacity;
+ container_type m_container;
+ boost::mutex m_mutex;
+ boost::condition m_not_empty;
+ boost::condition m_not_full;
+};
+
+template <class T>
+class bounded_buffer_list_based {
+public:
+
+ typedef std::list<T> container_type;
+ typedef typename container_type::size_type size_type;
+ typedef typename container_type::value_type value_type;
+ typedef typename boost::call_traits<value_type>::param_type param_type;
+
+ explicit bounded_buffer_list_based(size_type capacity) : m_capacity(capacity) {}
+
+ void push_front(param_type item) {
+ boost::mutex::scoped_lock lock(m_mutex);
+ m_not_full.wait(lock, boost::bind(&bounded_buffer_list_based<value_type>::is_not_full, this));
+ m_container.push_front(item);
+ lock.unlock();
+ m_not_empty.notify_one();
+ }
+
+ void pop_back(value_type* pItem) {
+ boost::mutex::scoped_lock lock(m_mutex);
+ m_not_empty.wait(lock, boost::bind(&bounded_buffer_list_based<value_type>::is_not_empty, this));
+ *pItem = m_container.back();
+ m_container.pop_back();
+ lock.unlock();
+ m_not_full.notify_one();
+ }
+
+private:
+
+ bounded_buffer_list_based(const bounded_buffer_list_based&); // Disabled copy constructor
+ bounded_buffer_list_based& operator = (const bounded_buffer_list_based&); // Disabled assign operator
+
+ bool is_not_empty() const { return m_container.size() > 0; }
+ bool is_not_full() const { return m_container.size() < m_capacity; }
+
+ const size_type m_capacity;
+ container_type m_container;
+ boost::mutex m_mutex;
+ boost::condition m_not_empty;
+ boost::condition m_not_full;
+};
+
+template<class Buffer>
+class Consumer {
+
+ typedef typename Buffer::value_type value_type;
+ Buffer* m_container;
+ value_type m_item;
+
+public:
+ Consumer(Buffer* buffer) : m_container(buffer) {}
+
+ void operator()() {
+ for (unsigned long i = 0L; i < TOTAL_ELEMENTS; ++i) {
+ m_container->pop_back(&m_item);
+ }
+ }
+};
+
+template<class Buffer>
+class Producer {
+
+ typedef typename Buffer::value_type value_type;
+ Buffer* m_container;
+
+public:
+ Producer(Buffer* buffer) : m_container(buffer) {}
+
+ void operator()() {
+ for (unsigned long i = 0L; i < TOTAL_ELEMENTS; ++i) {
+ m_container->push_front(value_type());
+ }
+ }
+};
+
+template<class Buffer>
+void fifo_test(Buffer* buffer) {
+
+ // Start of measurement
+ boost::timer::auto_cpu_timer progress;
+
+ // Initialize the buffer with some values before launching producer and consumer threads.
+ for (unsigned long i = QUEUE_SIZE / 2L; i > 0; --i) {
+#if BOOST_WORKAROUND(BOOST_BORLANDC, BOOST_TESTED_AT(0x581))
+ buffer->push_front(Buffer::value_type());
+#else
+ buffer->push_front(BOOST_DEDUCED_TYPENAME Buffer::value_type());
+#endif
+ }
+
+ Consumer<Buffer> consumer(buffer);
+ Producer<Buffer> producer(buffer);
+
+ // Start the threads.
+ boost::thread consume(consumer);
+ boost::thread produce(producer);
+
+ // Wait for completion.
+ consume.join();
+ produce.join();
+
+ // End of measurement
+}
+
+int main(int /*argc*/, char* /*argv*/[]) {
+
+ bounded_buffer<int> bb_int(QUEUE_SIZE);
+ std::cout << "bounded_buffer<int> ";
+ fifo_test(&bb_int);
+
+ bounded_buffer_space_optimized<int> bb_space_optimized_int(QUEUE_SIZE);
+ std::cout << "bounded_buffer_space_optimized<int> ";
+ fifo_test(&bb_space_optimized_int);
+
+ bounded_buffer_deque_based<int> bb_deque_based_int(QUEUE_SIZE);
+ std::cout << "bounded_buffer_deque_based<int> ";
+ fifo_test(&bb_deque_based_int);
+
+ bounded_buffer_list_based<int> bb_list_based_int(QUEUE_SIZE);
+ std::cout << "bounded_buffer_list_based<int> ";
+ fifo_test(&bb_list_based_int);
+
+ bounded_buffer<std::string> bb_string(QUEUE_SIZE);
+ std::cout << "bounded_buffer<std::string> ";
+ fifo_test(&bb_string);
+
+ bounded_buffer_space_optimized<std::string> bb_space_optimized_string(QUEUE_SIZE);
+ std::cout << "bounded_buffer_space_optimized<std::string> ";
+ fifo_test(&bb_space_optimized_string);
+
+ bounded_buffer_deque_based<std::string> bb_deque_based_string(QUEUE_SIZE);
+ std::cout << "bounded_buffer_deque_based<std::string> ";
+ fifo_test(&bb_deque_based_string);
+
+ bounded_buffer_list_based<std::string> bb_list_based_string(QUEUE_SIZE);
+ std::cout << "bounded_buffer_list_based<std::string> ";
+ fifo_test(&bb_list_based_string);
+
+ return 0;
+}
+/*
+
+//[bounded_buffer_comparison_output
+
+ Description: Autorun "J:\Cpp\Misc\Debug\bounded_buffer_comparison.exe"
+ bounded_buffer<int> 5.15 s
+
+ bounded_buffer_space_optimized<int> 5.71 s
+
+ bounded_buffer_deque_based<int> 15.57 s
+
+ bounded_buffer_list_based<int> 17.33 s
+
+ bounded_buffer<std::string> 24.49 s
+
+ bounded_buffer_space_optimized<std::string> 28.33 s
+
+ bounded_buffer_deque_based<std::string> 29.45 s
+
+ bounded_buffer_list_based<std::string> 31.29 s
+
+ //] //[bounded_buffer_comparison_output]
+
+*/
diff --git a/src/boost/libs/circular_buffer/example/circular_buffer_bound_example.cpp b/src/boost/libs/circular_buffer/example/circular_buffer_bound_example.cpp
new file mode 100644
index 000000000..673166513
--- /dev/null
+++ b/src/boost/libs/circular_buffer/example/circular_buffer_bound_example.cpp
@@ -0,0 +1,192 @@
+// Copyright 2003-2008 Jan Gaspar.
+// Copyright 2013 Paul A. Bristow. Added some Quickbook snippet markers.
+
+// Distributed under the Boost Software License, Version 1.0.
+// (See the accompanying file LICENSE_1_0.txt
+// or a copy at <http://www.boost.org/LICENSE_1_0.txt>.)
+
+//[circular_buffer_bound_example_1
+/*`
+This example shows how the `circular_buffer` can be utilized
+as an underlying container of the bounded buffer.
+*/
+
+#include <boost/circular_buffer.hpp>
+#include <boost/thread/mutex.hpp>
+#include <boost/thread/condition.hpp>
+#include <boost/thread/thread.hpp>
+#include <boost/call_traits.hpp>
+#include <boost/bind.hpp>
+
+#include <boost/timer/timer.hpp> // for auto_cpu_timer
+#include <iostream>
+
+template <class T>
+class bounded_buffer
+{
+public:
+
+ typedef boost::circular_buffer<T> container_type;
+ typedef typename container_type::size_type size_type;
+ typedef typename container_type::value_type value_type;
+ typedef typename boost::call_traits<value_type>::param_type param_type;
+
+ explicit bounded_buffer(size_type capacity) : m_unread(0), m_container(capacity) {}
+
+ void push_front(typename boost::call_traits<value_type>::param_type item)
+ { // `param_type` represents the "best" way to pass a parameter of type `value_type` to a method.
+
+ boost::mutex::scoped_lock lock(m_mutex);
+ m_not_full.wait(lock, boost::bind(&bounded_buffer<value_type>::is_not_full, this));
+ m_container.push_front(item);
+ ++m_unread;
+ lock.unlock();
+ m_not_empty.notify_one();
+ }
+
+ void pop_back(value_type* pItem) {
+ boost::mutex::scoped_lock lock(m_mutex);
+ m_not_empty.wait(lock, boost::bind(&bounded_buffer<value_type>::is_not_empty, this));
+ *pItem = m_container[--m_unread];
+ lock.unlock();
+ m_not_full.notify_one();
+ }
+
+private:
+ bounded_buffer(const bounded_buffer&); // Disabled copy constructor.
+ bounded_buffer& operator = (const bounded_buffer&); // Disabled assign operator.
+
+ bool is_not_empty() const { return m_unread > 0; }
+ bool is_not_full() const { return m_unread < m_container.capacity(); }
+
+ size_type m_unread;
+ container_type m_container;
+ boost::mutex m_mutex;
+ boost::condition m_not_empty;
+ boost::condition m_not_full;
+}; //
+
+//] [/circular_buffer_bound_example_1]
+
+const unsigned long queue_size = 1000L;
+const unsigned long total_elements = queue_size * 1000L;
+
+//[circular_buffer_bound_example_2]
+/*`To demonstrate, create two classes to exercise the buffer.
+
+The producer class fills the buffer with elements.
+
+The consumer class consumes the buffer contents.
+
+*/
+
+template<class Buffer>
+class Producer
+{
+
+ typedef typename Buffer::value_type value_type;
+ Buffer* m_container;
+
+public:
+ Producer(Buffer* buffer) : m_container(buffer)
+ {}
+
+ void operator()()
+ {
+ for (unsigned long i = 0L; i < total_elements; ++i)
+ {
+ m_container->push_front(value_type());
+ }
+ }
+};
+
+template<class Buffer>
+class Consumer
+{
+
+ typedef typename Buffer::value_type value_type;
+ Buffer* m_container;
+ value_type m_item;
+
+public:
+ Consumer(Buffer* buffer) : m_container(buffer)
+ {}
+
+ void operator()()
+ {
+ for (unsigned long i = 0L; i < total_elements; ++i)
+ {
+ m_container->pop_back(&m_item);
+ }
+ }
+};
+
+/*`Create a first-int first-out test of the bound_buffer.
+Include a call to boost::progress_timer
+
+[@http://www.boost.org/doc/libs/1_53_0/libs/timer/doc/cpu_timers.html CPU timer]
+
+*/
+template<class Buffer>
+void fifo_test(Buffer* buffer)
+{
+ // Start of timing.
+ boost::timer::auto_cpu_timer progress;
+
+ // Initialize the buffer with some values before launching producer and consumer threads.
+ for (unsigned long i = queue_size / 2L; i > 0; --i)
+ {
+#if BOOST_WORKAROUND(BOOST_BORLANDC, BOOST_TESTED_AT(0x581))
+ buffer->push_front(Buffer::value_type());
+#else
+ buffer->push_front(BOOST_DEDUCED_TYPENAME Buffer::value_type());
+#endif
+ }
+
+ // Construct the threads.
+ Consumer<Buffer> consumer(buffer);
+ Producer<Buffer> producer(buffer);
+
+ // Start the threads.
+ boost::thread consume(consumer);
+ boost::thread produce(producer);
+
+ // Wait for completion.
+ consume.join();
+ produce.join();
+
+ // End of timing.
+ // destructor of boost::timer::auto_cpu_timer will output the time to std::cout.
+
+}
+//] [/circular_buffer_bound_example_2]
+
+
+int main()
+{
+//[circular_buffer_bound_example_3]
+ //`Construct a bounded_buffer to hold the chosen type, here int.
+ bounded_buffer<int> bb_int(queue_size);
+ std::cout << "Testing bounded_buffer<int> ";
+
+ //`Start the fifo test.
+ fifo_test(&bb_int);
+ //` destructor of boost::timer::auto_cpu_timer will output the time to std::cout
+
+//] [/circular_buffer_bound_example_3]
+
+return 0;
+} // int main()
+
+/*
+
+//[circular_buffer_bound_output
+
+ Description: Autorun "J:\Cpp\Misc\Debug\circular_buffer_bound_example.exe"
+
+ Testing bounded_buffer<int> 15.010692s wall, 9.188459s user + 7.207246s system = 16.395705s CPU (109.2%)
+
+//] [/circular_buffer_bound_output]
+*/
+
+
diff --git a/src/boost/libs/circular_buffer/example/circular_buffer_example.cpp b/src/boost/libs/circular_buffer/example/circular_buffer_example.cpp
new file mode 100644
index 000000000..010074122
--- /dev/null
+++ b/src/boost/libs/circular_buffer/example/circular_buffer_example.cpp
@@ -0,0 +1,63 @@
+// Copyright 2003-2008 Jan Gaspar.
+// Copyright 2013 Paul A. Bristow. Added some Quickbook snippet markers.
+
+// Distributed under the Boost Software License, Version 1.0.
+// (See the accompanying file LICENSE_1_0.txt
+// or a copy at <http://www.boost.org/LICENSE_1_0.txt>.)
+
+//[circular_buffer_example_1
+/*`For all examples, we need this include:
+*/
+
+#include <boost/circular_buffer.hpp>
+
+//] [/circular_buffer_example_1]
+
+ int main()
+ {
+
+//[circular_buffer_example_2
+ // Create a circular buffer with a capacity for 3 integers.
+ boost::circular_buffer<int> cb(3);
+
+ // Insert three elements into the buffer.
+ cb.push_back(1);
+ cb.push_back(2);
+ cb.push_back(3);
+
+ int a = cb[0]; // a == 1
+ int b = cb[1]; // b == 2
+ int c = cb[2]; // c == 3
+
+ // The buffer is full now, so pushing subsequent
+ // elements will overwrite the front-most elements.
+
+ cb.push_back(4); // Overwrite 1 with 4.
+ cb.push_back(5); // Overwrite 2 with 5.
+
+ // The buffer now contains 3, 4 and 5.
+ a = cb[0]; // a == 3
+ b = cb[1]; // b == 4
+ c = cb[2]; // c == 5
+
+ // Elements can be popped from either the front or the back.
+ cb.pop_back(); // 5 is removed.
+ cb.pop_front(); // 3 is removed.
+
+ // Leaving only one element with value = 4.
+ int d = cb[0]; // d == 4
+
+//] [/circular_buffer_example_2]
+ return 0;
+ }
+
+ /*
+
+ //[circular_buffer_example_output
+
+There is no output from this example.
+
+//] [/circular_buffer_example_output]
+
+ */
+
diff --git a/src/boost/libs/circular_buffer/example/circular_buffer_examples.bat b/src/boost/libs/circular_buffer/example/circular_buffer_examples.bat
new file mode 100644
index 000000000..9f6c8f789
--- /dev/null
+++ b/src/boost/libs/circular_buffer/example/circular_buffer_examples.bat
@@ -0,0 +1,14 @@
+echo off
+rem quickbook doxygen auto-index docs template circular_buffer_html_index.bat
+rem echo circular_buffer_html_index_%date%_%time:~0,2%_%time:~3,2%.log
+rem The DOS time format is assumed 12:34 and the : separator is not used.
+set t=%time% /T
+set tim=%t:~0,2%%t:~3,2%
+rem pick just hours and minutes.
+rem time may include leading space, like " 915", so remove space.
+set tim=%tim: =%
+rem boost-no-inspect
+rem cd \boost-trunk/circular_buffer\libs\circular_buffer\example
+bjam -a > circular_buffer_examples_%date%_%tim%.log
+if not ERRORLEVEL 0 (echo Errorlevel is %ERRORLEVEL%) else (echo OK)
+pause
diff --git a/src/boost/libs/circular_buffer/example/circular_buffer_iter_example.cpp b/src/boost/libs/circular_buffer/example/circular_buffer_iter_example.cpp
new file mode 100644
index 000000000..339d284fe
--- /dev/null
+++ b/src/boost/libs/circular_buffer/example/circular_buffer_iter_example.cpp
@@ -0,0 +1,40 @@
+// Copyright 2003-2008 Jan Gaspar.
+// Copyright 2013 Paul A. Bristow. Added some Quickbook snippet markers.
+
+// Distributed under the Boost Software License, Version 1.0.
+// (See the accompanying file LICENSE_1_0.txt
+// or a copy at <http://www.boost.org/LICENSE_1_0.txt>.)
+
+#undef BOOST_CB_ENABLE_DEBUG
+
+//[circular_buffer_iter_example_1
+/*`
+*/
+
+#define BOOST_CB_ENABLE_DEBUG 0 // The Debug Support has to be disabled, otherwise the code produces a runtime error.
+
+#include <boost/circular_buffer.hpp>
+#include <boost/assert.hpp>
+#include <assert.h>
+
+int main(int /*argc*/, char* /*argv*/[])
+{
+
+ boost::circular_buffer<int> cb(3);
+
+ cb.push_back(1);
+ cb.push_back(2);
+ cb.push_back(3);
+
+ boost::circular_buffer<int>::iterator it = cb.begin();
+
+ assert(*it == 1);
+
+ cb.push_back(4);
+
+ assert(*it == 4); // The iterator still points to the initialized memory.
+
+ return 0;
+}
+
+//] [/circular_buffer_iter_example_1]
diff --git a/src/boost/libs/circular_buffer/example/circular_buffer_sum_example.cpp b/src/boost/libs/circular_buffer/example/circular_buffer_sum_example.cpp
new file mode 100644
index 000000000..16f00174f
--- /dev/null
+++ b/src/boost/libs/circular_buffer/example/circular_buffer_sum_example.cpp
@@ -0,0 +1,64 @@
+// Copyright 2003-2008 Jan Gaspar.
+// Copyright 2013 Paul A. Bristow. Added some Quickbook snippet markers.
+
+// Distributed under the Boost Software License, Version 1.0.
+// (See the accompanying file LICENSE_1_0.txt
+// or a copy at <http://www.boost.org/LICENSE_1_0.txt>.)
+
+//[circular_buffer_sum_example_1
+
+/*`This example shows several functions, including summing all valid values.
+*/
+
+ #include <boost/circular_buffer.hpp>
+ #include <numeric>
+ #include <assert.h>
+
+ int main(int /*argc*/, char* /*argv*/[])
+ {
+ // Create a circular buffer of capacity 3.
+ boost::circular_buffer<int> cb(3);
+ assert(cb.capacity() == 3);
+ // Check is empty.
+ assert(cb.size() == 0);
+ assert(cb.empty());
+
+ // Insert some elements into the circular buffer.
+ cb.push_back(1);
+ cb.push_back(2);
+
+ // Assertions to check push_backs have expected effect.
+ assert(cb[0] == 1);
+ assert(cb[1] == 2);
+ assert(!cb.full());
+ assert(cb.size() == 2);
+ assert(cb.capacity() == 3);
+
+ // Insert some other elements.
+ cb.push_back(3);
+ cb.push_back(4);
+
+ // Evaluate the sum of all elements.
+ int sum = std::accumulate(cb.begin(), cb.end(), 0);
+
+ // Assertions to check state.
+ assert(sum == 9);
+ assert(cb[0] == 2);
+ assert(cb[1] == 3);
+ assert(cb[2] == 4);
+ assert(*cb.begin() == 2);
+ assert(cb.front() == 2);
+ assert(cb.back() == 4);
+ assert(cb.full());
+ assert(cb.size() == 3);
+ assert(cb.capacity() == 3);
+
+ return 0;
+ }
+
+ //] [/circular_buffer_sum_example_1]
+
+
+ /*
+ There is no output from this example.
+ */
diff --git a/src/boost/libs/circular_buffer/example/jamfile.v2 b/src/boost/libs/circular_buffer/example/jamfile.v2
new file mode 100644
index 000000000..9a6e9e038
--- /dev/null
+++ b/src/boost/libs/circular_buffer/example/jamfile.v2
@@ -0,0 +1,42 @@
+# Copyright Paul A. Bristow 2013
+
+# Distributed under the Boost Software License, Version 1.0.
+# (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+# jamfile.v2 to run all circular_buffer examples.
+
+# bring in the rules for testing.
+import testing ;
+
+project
+ : requirements
+ <library>/boost/system//boost_system
+ <library>/boost/thread//boost_thread
+ #<define>BOOST_ALL_NO_LIB=1
+ <threading>multi
+
+ <toolset>gcc:<cxxflags>-Wno-missing-braces
+ <toolset>darwin:<cxxflags>-Wno-missing-braces
+ <toolset>acc:<cxxflags>+W2068,2461,2236,4070
+ <toolset>intel:<cxxflags>-Qwd264,239
+ <toolset>msvc:<warnings>all
+ <toolset>msvc:<asynch-exceptions>on
+ <toolset>msvc:<define>_CRT_SECURE_NO_DEPRECATE
+ <toolset>msvc:<define>_SCL_SECURE_NO_DEPRECATE
+ <toolset>msvc:<define>_SCL_SECURE_NO_WARNINGS
+ <toolset>msvc:<define>_CRT_SECURE_NO_WARNINGS
+ <toolset>msvc:<cxxflags>/wd4996
+ <toolset>msvc:<cxxflags>/wd4512
+ <toolset>msvc:<cxxflags>/wd4610
+ <toolset>msvc:<cxxflags>/wd4510
+ <toolset>msvc:<cxxflags>/wd4127
+ <toolset>msvc:<cxxflags>/wd4701
+ <toolset>msvc:<cxxflags>/wd4127
+ <toolset>msvc:<cxxflags>/wd4305
+ ;
+
+run bounded_buffer_comparison.cpp ../../timer/build//boost_timer ;
+run circular_buffer_iter_example.cpp ;
+run circular_buffer_sum_example.cpp ;
+run circular_buffer_bound_example.cpp ../../thread/build//boost_thread ../../timer/build//boost_timer ;
+