Compare commits

..

97 Commits

Author SHA1 Message Date
Rene Rivera
0b9a59f270 Add, and update, documentation build targets. 2016-10-10 11:39:47 -05:00
Glen Fernandes
99c93337d7 Merge pull request #10 from boostorg/develop
Synchronize master with develop
2016-08-18 21:55:24 -04:00
Glen Fernandes
12b896d57f Merge pull request #9 from Lastique/disable_debug_by_default
Disable debug implementation by default
2016-08-11 19:50:08 -04:00
Andrey Semashev
ea60799f31 Disable debug implementation by default
The debug implementation is not thread-safe, even if different threads are using separate iterators for reading elements of the container. BOOST_CB_DISABLE_DEBUG macro is no longer used, BOOST_CB_ENABLE_DEBUG=1 should be defined instead to enable debug support.

Fixes https://svn.boost.org/trac/boost/ticket/6277.
2016-04-29 00:56:06 +03:00
Glen Fernandes
d49044344f Merge pull request #8 from MarcelRaad/patch-1
Remove deprecated include
2015-09-12 06:53:50 -04:00
Marcel Raad
45c5d05b1d Remove deprecated include
All that boost/iterator.hpp does is pull std::iterator into namespace boost. A comment in that header mentions: "This header is obsolete and will be deprecated."
2015-09-11 16:30:17 +02:00
Antony Polukhin
9cf5fbb0fe Merge pull request #7 from amerry/adl_swap
Use boost/move/adl_move_swap.hpp to perform swaps.
2015-04-21 22:43:21 +04:00
Alexander Merry
2c88fa2f27 Use boost/move/adl_move_swap.hpp to perform swaps. 2015-04-21 09:02:26 +01:00
Alex Henrie
ce9a8538f2 Correct spelling of "suppress" 2015-01-30 15:28:08 -07:00
Antony Polukhin
5136d09e0a Merge branch 'master' into develop 2014-10-14 13:54:40 +04:00
Antony Polukhin
8a35c1deb0 Merge pull request #4 from danieljames/metadata
Create metadata file.
2014-08-18 19:55:51 +04:00
Daniel James
a54ccf9962 Add metadata file. 2014-08-18 14:57:42 +01:00
Antony Polukhin
d48b479c6a Use move_if_noexcept from Boost.Move 2014-08-18 12:08:23 +04:00
Glen Fernandes
8ba2c24454 Merge pull request #2 from jzmaddock/patch-1
Update jamfile.v2
2014-08-14 12:28:36 -07:00
Glen Fernandes
05a6e6e0d5 Merge pull request #3 from jzmaddock/patch-2
Update jamfile.v2
2014-08-14 12:26:40 -07:00
jzmaddock
483a1bdc2d Update jamfile.v2
Fix image location for PDF builds.
Use SVG for admon graphics (default path works OK for these).
Change name of pdf install target as current Boost.Build chokes over targets with hyphens in them.
2014-08-14 17:33:00 +01:00
jzmaddock
cfdf5c063b Update jamfile.v2
Fix image location for PDF builds.
Use SVG for admon graphics (default path works OK for these).
Change name of pdf install target as current Boost.Build chokes over targets with hyphens in them.
2014-08-14 17:31:43 +01:00
Antony Polukhin
f02cbb939c Finished sync of develop and master branches 2014-08-12 20:50:49 +04:00
Antony Polukhin
d18e2283a4 Merge branch 'master' into develop 2014-08-12 20:47:16 +04:00
Glen Fernandes
7e233f7b41 Merge branch 'develop' 2014-05-04 07:42:32 -07:00
Glen Fernandes
689e79abd9 Correct unit test custom pointer dereference operator 2014-05-02 22:06:39 -07:00
Glen Fernandes
002f351a9f Merge pull request #1 from glenfe/develop
Add C++11 allocator model support
2014-05-02 13:20:22 -07:00
Glen Fernandes
18306aee33 Eliminate need for do_construct helper 2014-05-02 10:26:11 -07:00
Glen Fernandes
c4b62627e7 Add C++11 allocator model support 2014-05-01 23:50:44 -07:00
Antony Polukhin
f5303c70d8 Merge branch 'develop' 2014-01-19 12:02:44 +04:00
Antony Polukhin
b896ace67c Create first merge point for Git 2014-01-01 15:35:13 +04:00
Antony Polukhin
62233c53bb Removed some whitespaces 2013-12-09 11:13:34 +04:00
Antony Polukhin
fc1d341a26 Fixed setting memory to '0xcc' in debug mode for non-pointer allocator::pointer types 2013-12-09 11:13:34 +04:00
Antony Polukhin
ece1277965 Fixed issues with allocators that do not return pointers, added tes case for such situations (refs #9334) 2013-12-09 11:13:34 +04:00
Antony Polukhin
33cfe492d9 Merge circular_buffer from trunk:
* dropped support of antique compilers (thanks to Stephen Kelly for doing it all around the boost!)

[SVN r86677]
2013-11-13 13:30:10 +00:00
Stephen Kelly
f9694e2dcb Remove remaining occurances of BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
These evaded scripting.

[SVN r86249]
2013-10-11 23:22:36 +00:00
Daniel James
90711fb1fe Merge circular buffer documentation fixes.
[SVN r86209]
2013-10-08 21:01:18 +00:00
Daniel James
783ea198b9 Final (hopefully?) fixed link.
[SVN r86197]
2013-10-07 23:06:58 +00:00
Daniel James
4b86f0994d Try to fix the images in the circular buffer documentation.
It's really awkward because the image path has to be relative to the combined
documentation location.

[SVN r86196]
2013-10-07 20:29:54 +00:00
Daniel James
1e48373264 Fix another circular buffer link.
[SVN r86176]
2013-10-06 15:15:34 +00:00
Daniel James
0c7032c145 Try to fix some links in circular buffer.
Changes some links to use the location independent 'boost:' links.

Also changes the build settings so that 'boost:' is used as a prefix when
generating docbook. The reason is a bit obscure. When generating documentation
with an index, the docbook documentation has to first be generated separately,
so that the index doesn't get confused with other documents. But when this
happens the boost.root parameter from the circular buffer jamfile is used -
which was the wrong location. So I changed it to use the prefix 'boost:'
which will later get converted to the correct location when building the
combined documentation. Sorry if that doesn't make any sense, but hopefully it
should fix some broken links.

[SVN r86174]
2013-10-06 08:03:35 +00:00
Stephen Kelly
6b14d766d2 CircularBuffer: Remove obsolete MSVC version checks.
[SVN r86081]
2013-09-30 16:03:51 +00:00
Stephen Kelly
d2d2710560 Remove use of BOOST_ITERATOR_CATEGORY
[SVN r86056]
2013-09-30 15:54:32 +00:00
Stephen Kelly
1f3a0aaa3d Remove obsolete MSVC check from pragma guard
git grep -h -B1 "^#\s*pragma once" | grep -v pragma | sort | uniq

is now clean.

[SVN r85952]
2013-09-26 13:02:51 +00:00
Antony Polukhin
6eb5fd4a3d Big merge of Boost.CircularBuffer :
* Full merge of QuickBoock documentation from Paul A. Bristow
* Merged rvalue references support with tests and documentation (fixed #7888)

[SVN r85510]
2013-08-29 08:39:09 +00:00
Antony Polukhin
f129fc1a7e Make move_if_noexcept more strict and move values only if they have noexcept move constructor *and* noexcept move assignment operator (refs #7888)
[SVN r85458]
2013-08-25 12:36:51 +00:00
Antony Polukhin
24ef3b6939 Updated documentaion of the circular_buffer to reflect the rvalue references support (refs #7888) + replaced some tabs with whitespaces and added the boost.root parameter to jamfile.v2
[SVN r85240]
2013-08-08 15:32:11 +00:00
Antony Polukhin
584239fb3a Fix errors in circular_buffer tests(refs #7888).
[SVN r85133]
2013-07-23 16:06:38 +00:00
Antony Polukhin
a08fb95e1f Make tests of circular_buffer compile with -DBOOST_THREAD_VERSION=4
[SVN r85102]
2013-07-22 11:49:48 +00:00
Antony Polukhin
f91a722738 Fixed MSVC related bug for rvalues move support of circular_buffer (refs #7888)
[SVN r85101]
2013-07-22 11:44:10 +00:00
Antony Polukhin
25b1edf93c Fixed my own typo (refs #7888)
[SVN r85082]
2013-07-19 14:41:41 +00:00
Antony Polukhin
1d0e7d01f9 Fix errors in circular_buffer tests(refs #7888).
[SVN r85059]
2013-07-17 14:09:32 +00:00
Paul A. Bristow
7ea5ea0d00 Deleted old docs, leaving only re-factored Quickbook version.
[SVN r85054]
2013-07-16 17:15:46 +00:00
Paul A. Bristow
2c97b19896 Changed redirection to refactored version in Boostbook collection
[SVN r85053]
2013-07-16 17:12:21 +00:00
Paul A. Bristow
9167a3edb4 Updated to correct broken links.
[SVN r85035]
2013-07-14 16:32:46 +00:00
Antony Polukhin
a739343a66 Improved rvalues move support for elements of circular_buffer (refs #7888):
* all `erase` methods now use move construction to to move elements
* space optimized circullar buffer now has move constructor, move assignment and functions that work with rvalues 
* more methods marked as BOOST_NOEXCEPT
* much more tests

[SVN r85003]
2013-07-11 14:55:24 +00:00
John Maddock
c1ac2a4cf8 Commit of circular buffer doc build.
[SVN r85000]
2013-07-10 16:19:37 +00:00
Antony Polukhin
62b25b47c7 Improved rvalues move support for elements of circular_buffer (refs #7888):
* set_capacity and rset_capacity now work with move-only types if move constructor of type marked with `noexcept`
* force placement ::new usage
* minor optimizations (move values in more cases)
* more tests

[SVN r84991]
2013-07-09 15:06:16 +00:00
Antony Polukhin
4d86f119cb Improved rvalues move support for elements of circular_buffer (refs #7888):
* move_if_noexcept uses is_copy_constructible trait
* more tests, tests are now more strict
* linearize() now works with move-only types

[SVN r84988]
2013-07-09 09:32:45 +00:00
Antony Polukhin
4eb876042e Add basic rvalues move support for elements of circular_buffer (refs #7888). Patch uses Boost.Move to emulate rvalues in C++03
[SVN r84984]
2013-07-08 13:41:58 +00:00
Vicente J. Botet Escriba
e06194c3d3 CircularBuffer: manage with #5362, #7025, #7050.
[SVN r84971]
2013-07-07 12:59:57 +00:00
Antony Polukhin
693933160d Basic commit of C++11 move constructor and move assignment for circular_buffer (refs #7888). some of the functions marked with BOOST_NOEXCEPT
[SVN r84941]
2013-07-02 13:51:55 +00:00
Paul A. Bristow
754f3a8011 Quickbook version of docs.
[SVN r84938]
2013-07-02 07:44:38 +00:00
Paul A. Bristow
82bf47c8d2 Changed Doxygen comments for new Quickbook/Doxygen based documentation. No intentional changes to code.
[SVN r84881]
2013-06-22 13:43:44 +00:00
Paul A. Bristow
d5f31115b9 Added typical output for use with new version of docs.
[SVN r84652]
2013-06-06 13:14:18 +00:00
Paul A. Bristow
d9927cdf32 Removed log file added by mistake.
[SVN r84651]
2013-06-06 13:13:21 +00:00
Paul A. Bristow
c36b612595 Examples extracted from previous docs separated out, annotated with Quickbook snippets for use with new docs, and run with the new jamfile.
[SVN r84650]
2013-06-06 13:12:16 +00:00
Marshall Clow
6998f28fda Apply patch to release branch; Fixes #8032
[SVN r84450]
2013-05-23 18:45:31 +00:00
Marshall Clow
dc0aa175a9 Applied patch from #8032
[SVN r84405]
2013-05-21 18:48:05 +00:00
Gennadiy Rozental
a3d9f1266d eliminated unit_test_framework
[SVN r74733]
2011-10-05 10:00:14 +00:00
Jan Gaspar
ed237fa058 circular_buffer: fixed when BOOST_NO_STDC_NAMESPACE defined
[SVN r66704]
2010-11-23 19:45:36 +00:00
Jan Gaspar
fb85032783 circular_buffer: fixed (the fix ;-) when BOOST_NO_STDC_NAMESPACE defined
[SVN r66691]
2010-11-22 22:06:08 +00:00
Jan Gaspar
2a5aa64de6 circular_buffer: fixed when BOOST_NO_STDC_NAMESPACE defined
[SVN r66690]
2010-11-22 22:01:09 +00:00
Jan Gaspar
2bd298dec7 circular_buffer: applied patch to remove workaround for DEC C++ compiler - now all compilers will use this->invalidate_iterators_except
[SVN r61570]
2010-04-26 09:40:08 +00:00
Jan Gaspar
d495873185 circular_buffer: applied patch to remove workaround for DEC C++ compiler - now all compilers will use this->invalidate_iterators_except
[SVN r61473]
2010-04-21 21:33:52 +00:00
Jan Gaspar
65810242ee circular_buffer: updated documentation
[SVN r60691]
2010-03-18 12:39:52 +00:00
Jan Gaspar
1c17ae088e circular_buffer: doc update
[SVN r60690]
2010-03-18 12:36:41 +00:00
Jan Gaspar
2f6170ccbe circular_buffer: documentation update - Interprocess compatibility
[SVN r60675]
2010-03-17 14:37:23 +00:00
Jan Gaspar
0282b8ee74 circular_buffer: constant complexity of clear method and destructor; added erase_begin and erase_end methods
[SVN r58681]
2010-01-04 15:54:37 +00:00
Jan Gaspar
637c7535a0 circular_buffer: updated documentation
[SVN r58672]
2010-01-04 12:39:18 +00:00
Jan Gaspar
8572432cb7 circular_buffer: constant complexity of clear method and destructor
[SVN r58619]
2010-01-01 22:23:27 +00:00
Jan Gaspar
5a30fe21d8 circular_buffer: added erase_begin and erase_end methods
[SVN r57161]
2009-10-26 21:37:01 +00:00
Troy D. Straszheim
18b8465b25 rm cmake from trunk. I'm not entirely sure this is necessary to satisfy the inspect script, but I'm not taking any chances, and it is easy to put back
[SVN r56942]
2009-10-17 02:07:38 +00:00
Troy D. Straszheim
cde2abac0c rm cmake from the release branch before it goes out broken. Policy dictates that you never commit to release, you commit to trunk and merge to release.
[SVN r56941]
2009-10-17 01:10:45 +00:00
Jan Gaspar
27c34a47b5 circular_buffer: #3285
[SVN r55203]
2009-07-27 11:50:24 +00:00
Troy D. Straszheim
4849492a53 Copyrights on CMakeLists.txt to keep them from clogging up the inspect
reports.  This is essentially the same commit as r55095 on the release
branch.



[SVN r55159]
2009-07-26 00:49:56 +00:00
Jan Gaspar
666ef1141f circular_buffer: fixed bounded_buffer_comparison
[SVN r53340]
2009-05-28 10:48:21 +00:00
Jan Gaspar
9e014030ee circular_buffer: #2785, #3032
[SVN r53263]
2009-05-25 22:11:02 +00:00
Jeremiah Willcock
9465df5d75 More tab and min/max fixes
[SVN r53143]
2009-05-20 19:46:06 +00:00
Troy D. Straszheim
c36065dc88 Merge cmake files release -> trunk.
[SVN r52866]
2009-05-09 22:57:30 +00:00
Jan Gaspar
1f51450f23 circular_buffer: #2538 Warning suppression in circular buffer test jamfile
[SVN r50051]
2008-12-01 10:41:06 +00:00
Michael A. Jackson
a2d270aa33 Updating dependency information for modularized libraries.
[SVN r49628]
2008-11-07 17:05:27 +00:00
Michael A. Jackson
83d617f9e4 Updating CMake files to latest trunk. Added dependency information for regression tests and a few new macros for internal use.
[SVN r49627]
2008-11-07 17:02:56 +00:00
Michael A. Jackson
9ff6fa759a Continuing merge of CMake build system files into trunk with the encouragement of Doug Gregor
[SVN r49510]
2008-11-01 13:15:41 +00:00
Jan Gaspar
868cc3dcde circular_buffer: fixed MSVC9 warning
[SVN r48221]
2008-08-19 17:02:48 +00:00
Jan Gaspar
0b7c6063ed circular_buffer: updated documentation for Boost 1.37
[SVN r48189]
2008-08-18 08:45:30 +00:00
Jan Gaspar
5a680c08ee circular_buffer: major update; added rotate method, bugfix #1987
[SVN r47738]
2008-07-23 20:40:46 +00:00
Jan Gaspar
6c59b9fe12 circular_buffer: bugfix #1919, #1852
[SVN r45609]
2008-05-21 15:53:50 +00:00
Jan Gaspar
f9f143d114 circular_buffer: improved documentation
[SVN r43719]
2008-03-19 09:24:24 +00:00
Jan Gaspar
4619a3ab9a circular_buffer: bugfix #1692
[SVN r43686]
2008-03-17 22:27:15 +00:00
Jan Gaspar
e1472df6d8 circular_buffer: updated documentation
[SVN r42938]
2008-01-23 23:04:57 +00:00
Jan Gaspar
87657ada36 circular_buffer: g++ warning fix
[SVN r41987]
2007-12-12 10:40:31 +00:00
43 changed files with 3650 additions and 12893 deletions

View File

@@ -1,29 +0,0 @@
#
# Copyright Troy D. Straszheim
#
# Distributed under the Boost Software License, Version 1.0.
# See http://www.boost.org/LICENSE_1_0.txt
#
#----------------------------------------------------------------------------
# This file was automatically generated from the original CMakeLists.txt file
# Add a variable to hold the headers for the library
set (lib_headers
circular_buffer.hpp
circular_buffer_fwd.hpp
circular_buffer
)
# Add a library target to the build system
boost_library_project(
circular_buffer
# SRCDIRS
TESTDIRS test
HEADERS ${lib_headers}
# DOCDIRS
DESCRIPTION "STL compliant container also known as ring or cyclic buffer."
MODULARIZED
AUTHORS "Jan Gaspar <jano_gaspar -at- yahoo.com>"
# MAINTAINERS
)

View File

@@ -1,227 +0,0 @@
# Doxygen configuration file.
#
# Copyright (c) 2003-2008 Jan Gaspar
#
# 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)
#
#---------------------------------------------------------------------------
# Project related configuration options
#---------------------------------------------------------------------------
PROJECT_NAME = "Circular Buffer"
PROJECT_NUMBER = 3.7
OUTPUT_DIRECTORY = srcdoc
CREATE_SUBDIRS = NO
OUTPUT_LANGUAGE = English
USE_WINDOWS_ENCODING = NO
BRIEF_MEMBER_DESC = YES
REPEAT_BRIEF = YES
ABBREVIATE_BRIEF =
ALWAYS_DETAILED_SEC = YES
INLINE_INHERITED_MEMB = NO
FULL_PATH_NAMES = NO
STRIP_FROM_PATH =
STRIP_FROM_INC_PATH =
SHORT_NAMES = NO
JAVADOC_AUTOBRIEF = NO
MULTILINE_CPP_IS_BRIEF = NO
DETAILS_AT_TOP = NO
INHERIT_DOCS = YES
DISTRIBUTE_GROUP_DOC = NO
TAB_SIZE = 8
ALIASES =
OPTIMIZE_OUTPUT_FOR_C = NO
OPTIMIZE_OUTPUT_JAVA = NO
SUBGROUPING = YES
#---------------------------------------------------------------------------
# Build related configuration options
#---------------------------------------------------------------------------
EXTRACT_ALL = YES
EXTRACT_PRIVATE = YES
EXTRACT_STATIC = YES
EXTRACT_LOCAL_CLASSES = YES
EXTRACT_LOCAL_METHODS = NO
HIDE_UNDOC_MEMBERS = NO
HIDE_UNDOC_CLASSES = NO
HIDE_FRIEND_COMPOUNDS = NO
HIDE_IN_BODY_DOCS = YES
INTERNAL_DOCS = NO
CASE_SENSE_NAMES = YES
HIDE_SCOPE_NAMES = NO
SHOW_INCLUDE_FILES = YES
INLINE_INFO = YES
SORT_MEMBER_DOCS = NO
SORT_BRIEF_DOCS = NO
SORT_BY_SCOPE_NAME = NO
GENERATE_TODOLIST = YES
GENERATE_TESTLIST = YES
GENERATE_BUGLIST = YES
GENERATE_DEPRECATEDLIST= YES
ENABLED_SECTIONS =
MAX_INITIALIZER_LINES = 30
SHOW_USED_FILES = NO
SHOW_DIRECTORIES = YES
FILE_VERSION_FILTER =
#---------------------------------------------------------------------------
# configuration options related to warning and progress messages
#---------------------------------------------------------------------------
QUIET = NO
WARNINGS = YES
WARN_IF_UNDOCUMENTED = YES
WARN_IF_DOC_ERROR = YES
WARN_NO_PARAMDOC = YES
WARN_FORMAT = "$file:$line: $text"
WARN_LOGFILE =
#---------------------------------------------------------------------------
# configuration options related to the input files
#---------------------------------------------------------------------------
INPUT = ../../../boost/circular_buffer
FILE_PATTERNS = *.hpp
RECURSIVE = YES
EXCLUDE = ../../../boost/circular_buffer/debug.hpp \
../../../boost/circular_buffer/details.hpp
EXCLUDE_SYMLINKS = NO
EXCLUDE_PATTERNS =
EXAMPLE_PATH =
EXAMPLE_PATTERNS =
EXAMPLE_RECURSIVE = NO
IMAGE_PATH =
INPUT_FILTER =
FILTER_PATTERNS =
FILTER_SOURCE_FILES = NO
#---------------------------------------------------------------------------
# configuration options related to source browsing
#---------------------------------------------------------------------------
SOURCE_BROWSER = NO
INLINE_SOURCES = NO
STRIP_CODE_COMMENTS = NO
REFERENCED_BY_RELATION = YES
REFERENCES_RELATION = YES
VERBATIM_HEADERS = YES
#---------------------------------------------------------------------------
# configuration options related to the alphabetical class index
#---------------------------------------------------------------------------
ALPHABETICAL_INDEX = NO
COLS_IN_ALPHA_INDEX = 5
IGNORE_PREFIX =
#---------------------------------------------------------------------------
# configuration options related to the HTML output
#---------------------------------------------------------------------------
GENERATE_HTML = NO
HTML_OUTPUT = html
HTML_FILE_EXTENSION = .html
HTML_HEADER =
HTML_FOOTER =
HTML_STYLESHEET =
HTML_ALIGN_MEMBERS = YES
GENERATE_HTMLHELP = NO
CHM_FILE =
HHC_LOCATION =
GENERATE_CHI = NO
BINARY_TOC = NO
TOC_EXPAND = NO
DISABLE_INDEX = NO
ENUM_VALUES_PER_LINE = 4
GENERATE_TREEVIEW = NO
TREEVIEW_WIDTH = 250
#---------------------------------------------------------------------------
# configuration options related to the LaTeX output
#---------------------------------------------------------------------------
GENERATE_LATEX = NO
LATEX_OUTPUT = latex
LATEX_CMD_NAME = latex
MAKEINDEX_CMD_NAME = makeindex
COMPACT_LATEX = NO
PAPER_TYPE = a4wide
EXTRA_PACKAGES =
LATEX_HEADER =
PDF_HYPERLINKS = NO
USE_PDFLATEX = NO
LATEX_BATCHMODE = NO
LATEX_HIDE_INDICES = NO
#---------------------------------------------------------------------------
# configuration options related to the RTF output
#---------------------------------------------------------------------------
GENERATE_RTF = NO
RTF_OUTPUT = rtf
COMPACT_RTF = NO
RTF_HYPERLINKS = NO
RTF_STYLESHEET_FILE =
RTF_EXTENSIONS_FILE =
#---------------------------------------------------------------------------
# configuration options related to the man page output
#---------------------------------------------------------------------------
GENERATE_MAN = NO
MAN_OUTPUT = man
MAN_EXTENSION = .3
MAN_LINKS = NO
#---------------------------------------------------------------------------
# configuration options related to the XML output
#---------------------------------------------------------------------------
GENERATE_XML = YES
XML_OUTPUT = .
XML_SCHEMA =
XML_DTD =
XML_PROGRAMLISTING = NO
#---------------------------------------------------------------------------
# configuration options for the AutoGen Definitions output
#---------------------------------------------------------------------------
GENERATE_AUTOGEN_DEF = NO
#---------------------------------------------------------------------------
# configuration options related to the Perl module output
#---------------------------------------------------------------------------
GENERATE_PERLMOD = NO
PERLMOD_LATEX = NO
PERLMOD_PRETTY = YES
PERLMOD_MAKEVAR_PREFIX =
#---------------------------------------------------------------------------
# Configuration options related to the preprocessor
#---------------------------------------------------------------------------
ENABLE_PREPROCESSING = NO
MACRO_EXPANSION = NO
EXPAND_ONLY_PREDEF = NO
SEARCH_INCLUDES = YES
INCLUDE_PATH =
INCLUDE_FILE_PATTERNS =
PREDEFINED =
EXPAND_AS_DEFINED =
SKIP_FUNCTION_MACROS = YES
#---------------------------------------------------------------------------
# Configuration::additions related to external references
#---------------------------------------------------------------------------
TAGFILES =
GENERATE_TAGFILE =
ALLEXTERNALS = NO
EXTERNAL_GROUPS = NO
PERL_PATH =
#---------------------------------------------------------------------------
# Configuration options related to the dot tool
#---------------------------------------------------------------------------
CLASS_DIAGRAMS = NO
HIDE_UNDOC_RELATIONS = NO
HAVE_DOT = NO
CLASS_GRAPH = YES
COLLABORATION_GRAPH = YES
GROUP_GRAPHS = YES
UML_LOOK = NO
TEMPLATE_RELATIONS = YES
INCLUDE_GRAPH = YES
INCLUDED_BY_GRAPH = YES
CALL_GRAPH = NO
GRAPHICAL_HIERARCHY = YES
DIRECTORY_GRAPH = YES
DOT_IMAGE_FORMAT = png
DOT_PATH =
DOTFILE_DIRS =
MAX_DOT_GRAPH_WIDTH = 1024
MAX_DOT_GRAPH_HEIGHT = 1024
MAX_DOT_GRAPH_DEPTH = 0
DOT_TRANSPARENT = NO
DOT_MULTI_TARGETS = NO
GENERATE_LEGEND = YES
DOT_CLEANUP = YES
#---------------------------------------------------------------------------
# Configuration::additions related to the search engine
#---------------------------------------------------------------------------
SEARCHENGINE = NO

View File

@@ -1,52 +0,0 @@
################################################################################
# HOW-TO documentation about generating/updating source code documentation for #
# the Circular Buffer library. #
# #
# Copyright (c) 2003-2008 Jan Gaspar #
# #
# 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) #
################################################################################
The source code documentation (i.e. documentation of functions, classes and
their methods, etc.) is part of the source code. This makes it convenient for
a developer when browsing source files or developing new (documented) code.
The source code documentation is included in the larger, more detailed library
documentation as well which makes it more convenient for the user of the
library. In order to make it easier for the developer, the source code
documentation included in the library documentation is generated from the source
files. Which means the developer does not have to write the same source
documentation twice.
Prerequisites:
1) Unix/Linux shell (with sed editor) available.
(The script can be easily converted into Windows batch file if you do not
have access to Unix/Linux shell.)
2) Installed Doxygen http://www.doxygen.org.
(Source documentation generation was tested with the Doxygen version
1.4.6.)
3) Installed xsltproc http://xmlsoft.org/XSLT/xsltproc2.html.
4) Installed HTML Tidy http://tidy.sourceforge.net. (Tested with version
released on 1 September 2005.)
Updating source code documentation:
The source code documentation of the Circular Buffer library obeys the Doxygen
syntax. The library documentation is written in HTML (files circular_buffer.html
and space_optimized.html). The generation of the source code documentation is
performed by executing the update_srcdoc.sh script which relies mainly on
Doxygen and several XSL transformations.
After editing the source code documentation in the source file(s), update the
library documentation by executing:
$>./update_srcdoc.sh circular_buffer
for the circular_buffer or/and
$>./update_srcdoc.sh circular_buffer_space_optimized
for the circular_buffer_space_optimized.

View File

@@ -1,18 +0,0 @@
# HTML Tidy configuration file.
#
# Copyright (c) 2003-2008 Jan Gaspar
#
# 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)
#
bare: yes
char-encoding: latin1
doctype: transitional
indent: yes
indent-attributes: no
quiet: yes
show-warnings: no
tidy-mark: no
wrap: 120
write-back: yes

File diff suppressed because it is too large Load Diff

22
doc/circular_buffer.idx Normal file
View File

@@ -0,0 +1,22 @@
# circular_buffer.idx index script file
# for Boost.circular_buffer Quickbook Doxygen documentation Auto-indexing forcircular_buffer library.
# Copyright (c) 2011 Paul A. Bristow
# Copyright (c) 2003 - 2008 Jan Gaspar
# boost-no-inspect
# 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)
# All header files, recursing down to include sub-folders.
!scan-path "boost/circular_buffer" ".*\.hpp" true
# All example source files, assuming no sub-folders.
!scan-path "libs/circular_buffer/example" ".*\.cpp"

626
doc/circular_buffer.qbk Normal file
View File

@@ -0,0 +1,626 @@
[article Boost.Circular Buffer
[quickbook 1.6]
[id circular_buffer]
[copyright 2003-2013 Jan Gaspar]
[license
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])
]
[authors [Gaspar, Jan]]
[source-mode c++]
]
[/ Links - by (most common) convention, prefixed with double underscore so not confused with other names.]
[def __alert [$./images/alert.png]] [/ Examples of your own images (in doc/html/images/ .]
[def __tip [$./images/tip.png]]
[/ If you provide a file type like .png, you will probably find that the file is missing in the pdf version.]
[/ This is because the default file type specified is .png in html, but .svg for pdf version.]
[/ Some links to external sources.]
[/ You often want to link more than once, so using a def ensures you always refer to the same location.]
[def __boost [@http://www.boost.org/ Boost]] [/Boost.org]
[def __boostroot [@boost: Boost root]] [/ Your boost root]
[/Note the custom boost root url schema for linking to files within the Boost distribution.]
[/Note It can't be used for images, nor for pdf, so not so useful.]
[/def __boostlicense [@http://www.boost.org/LICENSE_1_0.txt Boost License]]
[/ Or refer to your most recent version of Boost.]
[def __boostlicense [@boost:/LICENSE_1_0.txt Boost License]]
[def __boostbook [@http://www.boost.org/doc/html/boostbook.html BoostBook]]
[def __boostbook_docs [@http://www.boost.org/doc/libs/1_53_0/doc/html/boostbook.html BoostBook documentation]]
[def __quickbook [@http://www.boost.org/doc/tools/quickbook/index.html Quickbook]]
[def __quickbook_syntax [@http://www.boost.org/doc/libs/1_53_0/doc/html/quickbook/ref.html Quickbook Syntax Compendium]]
[def __docbook [@http://www.docbook.org/ DocBook]]
[def __doxygen [@http://www.doxygen.org/ Doxygen]]
[def __autoindex [@boost:/tools/auto_index/doc/html/index.html AutoIndex]]
[def __pdf [@http://www.adobe.com/products/acrobat/adobepdf.html PDF]]
[def __textpad [@http://www.textpad.com Textpad]]
[def __emacs [@http://www.gnu.org/software/emacs/ GNU emacs]]
[def __css [@http://en.wikipedia.org/wiki/Cascading_Style_Sheets Cascading Style Sheet]]
[def __intro [link circular_buffer.intro Introduction]] [/Link to a Quickbook section (see below).]
[def __docbook_params [@http://docbook.sourceforge.net/release/xsl/current/doc/ Docbook xsl:param format options]]
[def __cb [classref boost::circular_buffer circular_buffer]]
[def __cbso [classref boost::circular_buffer_space_optimized circular_buffer_space_optimized]]
[def __min_capacity [memberref boost::circular_buffer_space_optimized::min_capacity() min_capacity]]
[def __capacity_control [memberref boost::circular_buffer_space_optimized::capacity_control () capacity_control ]]
[def __debug_support [link circular_buffer.implmentation.debug_support debug support]]
[include ../../../tools/auto_index/include/auto_index_helpers.qbk]
[/ Must be first included file!]
[note A printer-friendly PDF version of this manual is also available.]
[section:intro Introduction]
A Circular Buffer.
[h2 Description]
The term [@http://en.wikipedia.org/wiki/Circular_buffer circular buffer]
(also called a ['ring] or ['cyclic buffer])
refers to an area in memory which is used to store incoming data.
When the buffer is filled,
new data is written starting at the beginning of the buffer and overwriting the old.
[classref boost::circular_buffer] is a STL compliant container.
It is a kind of sequence similar to [@http://www.sgi.com/tech/stl/List.html std::list]
or [@http://www.sgi.com/tech/stl/Deque.html std::deque].
It supports random access iterators, constant time insert and erase operations
at the beginning or the end of the buffer and interoperability with std algorithms.
The __cb is especially designed to provide [*fixed capacity] storage.
When its capacity is exhausted, newly inserted elements will cause elements
to be overwritten, either at the beginning or end of the buffer
(depending on what insert operation is used).
The __cb only allocates memory when created,
when the capacity is adjusted explicitly,
or as necessary to accommodate resizing or assign operations.
[$../../libs/circular_buffer/doc/images/circular_buffer.png]
There is also a __cbso version available.
[$../../libs/circular_buffer/doc/images/space_optimized.png]
__cbso is an adaptation of the __cb
which [*does not allocate memory all at once when created],
instead it allocates memory as needed.
The predictive memory allocation is similar to typical `std::vector` implementation.
Memory is automatically freed as the size of the container decreases.
The memory allocation process of the space-optimized circular buffer.
The __min_capacity of the capacity controller represents
the minimal guaranteed amount of allocated memory.
The allocated memory will never drop under this value.
The default value of the `min_capacity` is set to 0.
The `min_capacity` can be set using the constructor parameter __capacity_control
or the function `set_capacity`.
The space-optimized version is, of course, a little slower.
[endsect] [/section:intro Introduction]
[section:example Circular_buffer example]
Here is a simple example to introduce the class __cb.
[import ../example/circular_buffer_example.cpp]
[circular_buffer_example_1]
This example shows contruction, inserting elements, overwriting and popping.
[circular_buffer_example_2]
[/circular_buffer_example_output - there is no output for this example]
You can see the full example code at [@boost:libs/circular_buffer/example/circular_buffer_example.cpp circular_buffer_example.cpp].
The full annotated description is in the C++ Reference section.
[endsect] [/section:example circular_buffer example]
[section:rationale Rationale]
The basic motivation behind the __cb was to create a container which would [*work seamlessly with STL].
Additionally, the design of the __cb was guided by the following principles:
* Maximum ['efficiency] for envisaged applications.
* Suitable for ['general purpose use].
* The behaviour of the buffer as ['intuitive] as possible.
* Suitable for ['specialization] by means of adaptors. (The __cbso is such an example of the adaptor.)
* Easy to ['debug]. (See Debug Support for details.)
In order to achieve maximum efficiency, the __cb and __cbso store their elements in a
[*contiguous region of memory], which then enables:
* Use of fixed memory and no implicit or unexpected memory allocation.
* Fast constant-time insertion and removal of elements from the front and back.
* Fast constant-time random access of elements.
* Suitability for real-time and performance critical applications.
Possible applications of the circular buffer include:
* Storage of the ['most recently received samples], overwriting the oldest as new samples arrive.
* As an underlying container for a ['bounded buffer]
(see the Bounded Buffer example, code at [@boost:libs/circular_buffer/example/circular_buffer_bound_example.cpp circular_buffer_bound_example.cpp]).
* A kind of ['cache] storing a specified number of last inserted elements.
* Efficient fixed capacity ['FIFO (First In, First Out)],
* Efficient fixed capacity ['LIFO (Last In, First Out)] queue which removes the oldest (inserted as first) elements when full.
[endsect] [/section:rationale Rationale]
[section:implementation Implementation ]
The following paragraphs describe issues that had to be considered during the implementation of the circular_buffer:
[h3 Thread-Safety]
The thread-safety of the __cb is the same as the thread-safety of containers in most STL implementations.
This means the __cb is not fully thread-safe.
The thread-safety is guaranteed only in the sense that simultaneous accesses
to distinct instances of the __cb are safe,
and simultaneous read accesses to a shared __cb are safe.
If multiple threads access a single __cb,
and at least one of the threads may potentially write,
then the user is responsible for ensuring mutual exclusion between the threads during the container accesses.
The mutual exclusion between the threads can be achieved by wrapping
operations of the underlying __cb with a lock acquisition and release.
(See the Bounded Buffer example code at [@boost:libs/circular_buffer/example/circular_buffer_bound_example.cpp circular_buffer_bound_example.cpp])
[h3 Overwrite Operation]
Overwrite operation occurs when an element is inserted into a full __cb -
the old element is being overwritten by the new one.
There was a discussion what exactly "overwriting of an element" means during the formal review.
It may be either a destruction of the original element and
a consequent inplace construction of a new element
or it may be an assignment of a new element into an old one.
The __cb implements assignment because it is more effective.
From the point of business logic of a stored element,
the destruction/construction operation and assignment usually mean the same.
However, in very rare cases (if in any) they may differ.
If there is a requirement for elements to be destructed/constructed instead of being assigned,
consider implementing a wrapper of the element which would implement the assign operator,
and store the wrappers instead.
It is necessary to note that storing such wrappers has a drawback.
The destruction/construction will be invoked on every assignment of the wrapper -
not only when a wrapper is being overwritten (when the buffer is full)
but also when the stored wrappers are being shifted
(e.g. as a result of insertion into the middle of container).
[h3 Writing to a Full Buffer]
There are several options how to cope if a data source produces more data than can fit in the fixed-sized buffer:
* Inform the data source to wait until there is room in the buffer (e.g. by throwing an overflow exception).
* If the oldest data is the most important, ignore new data from the source until there is room in the buffer again.
* If the latest data is the most important, write over the oldest data.
* Let the producer to be responsible for checking the size of the buffer prior writing into it.
It is apparent that the __cb implements the third option.
But it may be less apparent it does not implement any other option -
especially the first two.
One can get an impression that the __cb should implement first three options
and offer a mechanism of choosing among them. This impression is wrong.
The __cb was designed and optimized to be circular
(which means overwriting the oldest data when full).
If such a controlling mechanism had been enabled,
it would just complicate the matters
and the usage of the __cb would be probably less straightforward.
Moreover, the first two options (and the fourth option as well)
do not require the buffer to be circular at all.
If there is a need for the first or second option, consider implementing an adaptor of e.g. std::vector.
In this case the __cb is not suitable for adapting, because,
contrary to std::vector, it bears an overhead for its circular behaviour.
[h3 Reading/Removing from an Empty Buffer]
When reading or removing an element from an empty buffer,
the buffer should be able to notify the data consumer
(e.g. by throwing underflow exception) that there are no elements stored in it.
The __cb does not implement such a behaviour for two reasons:
* It would introduce a performance overhead.
* No other std container implements it this way.
It is considered to be a bug to read or remove an element
(e.g. by calling [memberref boost::circular_buffer::front() front()]
or [memberref boost::circular_buffer::pop_back() pop_back()])
from an empty std container and from an empty __cb as well.
The data consumer has to test if the container is not empty before reading/removing from it by testing
[memberref boost::circular_buffer::empty empty()].
However, when reading from the __cb,
there is an option to rely on the [memberref boost::circular_buffer::at() at()]
method which throws an exception when the index is out of range.
[h3 Iterator Invalidation]
An iterator is usually considered to be invalidated if an element,
the iterator pointed to, had been removed or overwritten by an another element.
This definition is enforced by the Debug Support and is documented for every method.
However, some applications utilizing __cb may require less strict definition:
an iterator is invalid only if it points to an uninitialized memory.
Consider following example:
[import ../example/circular_buffer_iter_example.cpp]
[circular_buffer_iter_example_1]
The iterator does not point to the original element any more
(and is considered to be invalid from the "strict" point of view)
but it still points to the same valid place in the memory.
This "soft" definition of iterator invalidation is supported by the __cb
but should be considered as an implementation detail rather than a full-fledged feature.
The rules when the iterator is still valid can be inferred from the code in
[@boost:libs/circular_buffer/test/soft_iterator_invalidation.cpp soft_iterator_invalidation.cpp].
[h3 Move emulation and rvalues]
Since Boost 1.54.0 support for move semantics was implemented using
the [@boost:libs/move/index.html Boost.Move] library.
If rvalue references are available __cb will use them, but if not it uses a close,
but imperfect emulation. On such compilers:
* Non-copyable objects can be stored in the containers.
They can be constructed in place using `emplace`, or if they support
Boost.Move, moved into place.
* The containers themselves are not movable.
* Argument forwarding is not perfect.
__cb will use rvalues and move emulations for value types only if move constructor and move assignment operator of the value type do not throw;
or if the value type has no copy constructor.
Some methods won't use move constructor for the value type at all, if the constructor throws. This is
required for data consistency and avoidance of situations, when aftrer an exception __cb
contains moved away objects along with the good ones.
See documentation for [@boost:libs/type_traits/doc/html/boost_typetraits/reference/is_copy_constructible.html `is_copy_constructible`], [@boost:libs/type_traits/doc/html/boost_typetraits/reference/is_nothrow_move_assignable.html `is_nothrow_move_assignable`] and [@boost:libs/type_traits/doc/html/boost_typetraits/reference/is_nothrow_move_constructible.html `is_nothrow_move_constructible`] type triats.
There you'll find information about how to make constructor of class noexcept and how to make a non-copyable
class in C++03 and C++98.
Performance of __cb will *greatly improve* if value type has noexcept move constructor and noexcept move assignment.
[h3 Exceptions of move_if_noexcept(T&)]
Reference documentation of the __cb contains notes like "Throws: See Exceptions of `move_if_noexcept(T&)`".
That note means the following: `move_if_noexcept(T& value)` does not throws exceptions at all, but it returns
`value` as rvalue reference only if class `T` have noexcept move constructor and noexcept move assignment operator;
or if it has no copy constructor. Otherwise `move_if_noexcept(T& value)` returns `value` as const reference.
This leads us to the following situation:
* If `value` has a noexcept move constructor and noexcept move assignment operator, then no exceptions will be thrown at all.
* If `value` has a throwing move constructor and some copy constructor, then method may throw exceptions of copy constructor.
* If `value` has no copy constructor, then method may throw exceptions of move constructor.
`move_if_noexcept(T&)` uses [@boost:libs/move/index.html Boost.Move], [@boost:libs/type_traits/doc/html/boost_typetraits/reference/is_copy_constructible.html `is_copy_constructible`], [@boost:libs/type_traits/doc/html/boost_typetraits/reference/is_nothrow_move_assignable.html `is_nothrow_move_assignable`] and [@boost:libs/type_traits/doc/html/boost_typetraits/reference/is_nothrow_move_constructible.html `is_nothrow_move_constructible`] type triats.
[h3 Caveats]
The __cb should not be used for storing pointers to dynamically allocated objects.
When a circular buffer becomes full, further insertion will overwrite the stored pointers
- resulting in a [*memory leak]. One recommend alternative is the use of smart pointers, for example
[@http://www.boost.org/doc/libs/1_53_0/libs/smart_ptr/smart_ptr.htm Boost Smart pointers].
[@http://en.wikipedia.org/wiki/Std::auto_ptr std::auto_ptr]
[caution Any container of `std::auto_ptr` is considered particularly hazardous.]
[tip Never create a circular buffer of `std::auto_ptr`.
Refer to Scott Meyers' excellent book Effective STL for a detailed discussion.
(Meyers S., Effective STL: 50 Specific Ways to Improve Your Use of the Standard Template Library.
Addison-Wesley, 2001.)
]
While internals of a __cb are circular, [*iterators are not].
Iterators of a __cb are only valid for the range `\[begin(), end()\]`,
so for example: iterators `(begin() - 1)` and `(end() + 1)` are both invalid.
[h3 Debug Support]
In order to help a programmer to avoid and find common bugs,
the __cb can be enabled to provide a kind of debug support.
When the debugging functionality is enabled, the __cb maintains a list of valid iterators.
As soon as any element gets destroyed all iterators pointing to this element
are removed from this list and explicitly invalidated (an invalidation flag is set).
The debug support also consists of many assertions (`BOOST_ASSERT` macros)
which ensure the __cb and its iterators are used in the correct manner at runtime.
In case an invalid iterator is used, the assertion will report an error.
The connection of explicit iterator invalidation and assertions
makes a very robust debug technique which catches most of the errors.
Moreover, the uninitialized memory allocated by __cb is filled with the value `0xcc` in the debug mode.
When debugging the code, this can help the programmer to recognize the initialized memory from the uninitialized.
For details refer the source code [@boost:boost/circular_buffer/debug.hpp circular_buffer/debug.hpp].
[caution Since the debugging code makes __cb and its iterators more interconnected, thread safety guarantees of __cb
are different when debug support is enabled. In addition to the container itself, all iterators tracked by the container
(including any copies thereof) must be protected from concurrent access. In particular, this includes copying, destroying or
obtaining iterators from the container, even if for read-only access.]
The debug support is disabled by default. To enable it, one has to define `BOOST_CB_ENABLE_DEBUG` macro with the value of 1
while compiling the code using __cb.
[h3 Compatibility with Interprocess library]
The __cb is compatible with the [@boost:libs/interprocess/index.html Boost.Interprocess]
[/ This should be in @boost:libs/interprocess/doc/index.html ]
library used for interprocess communication.
Considering that the circular_buffer's debug support relies on 'raw' pointers
(which is not permited by the Interprocess library)
the code has to compiled with debug support disabled (i.e. with `BOOST_CB_ENABLE_DEBUG` macro not defined or defined to 0).
Not doing that will cause the compilation to fail.
[endsect] [/section:implementation Implementation ]
[section:examples More Examples]
[h3 Summing all the values in a circular buffer]
[import ../example/circular_buffer_sum_example.cpp]
[circular_buffer_sum_example_1]
[/circular_buffer_example_output - there is no output for this example]
The __cb has a capacity of three `int`.
Therefore, the size of the buffer will never exceed three.
The `std::accumulate` algorithm evaluates the sum of the stored elements.
The semantics of the __cb can be inferred from the assertions.
You can see the full example code at [@boost:libs/circular_buffer/example/circular_buffer_sum_example.cpp circular_buffer_sum_example.cpp].
[h3 Bounded Buffer Example]
The bounded buffer is normally used in a producer-consumer mode:
producer threads produce items and store them in the container
and consumer threads remove these items and process them.
The bounded buffer has to guarantee that
* producers do not insert items into the container when the container is full,
* consumers do not try to remove items when the container is empty,
* each produced item is consumed by exactly one consumer.
[import ../example/circular_buffer_bound_example.cpp]
[circular_buffer_bound_example_1]
[/ there is no output for this example]
The bounded_buffer relies on [@boost:/doc/html/thread.html Boost.Thread]
and [@boost:libs/bind/index.html Boost.Bind] libraries
and [@boost:libs/utility/call_traits.htm Boost.call_traits utility].
The [memberref boost::circular_buffer::push_front() push_front()]
method is called by the producer thread in order to insert a new item into the buffer.
The method locks the mutex and waits until there is a space for the new item.
(The mutex is unlocked during the waiting stage and has to be regained when the condition is met.)
If there is a space in the buffer available,
the execution continues and the method inserts the item at the end of the __cb.
Then it increments the number of unread items and unlocks the mutex
(in case an exception is thrown before the mutex is unlocked,
the mutex is unlocked automatically by the destructor of the scoped_lock).
At last the method notifies one of the consumer threads
waiting for a new item to be inserted into the buffer.
The [memberref boost::circular_buffer::pop_back() pop_back()]
method is called by the consumer thread in order to read the next item from the buffer.
The method locks the mutex and waits until there is an unread item in the buffer.
If there is at least one unread item,
the method decrements the number of unread items and reads the next item from the __cb.
Then it unlocks the mutex and notifies one of the producer threads
waiting for the buffer to free a space for the next item.
The `bounded buffer::pop_back()`
method [*does not remove the item] but the item is left
in the circular_buffer which then [*replaces it with a new one]
(inserted by a producer) when the circular_buffer is full.
This technique is more effective than removing the item
explicitly by calling the [memberref boost::circular_buffer::pop_back() circular_buffer::pop_back()]
method of the __cb.
This claim is based on the assumption that an assignment (replacement)
of a new item into an old one is more effective than a destruction
(removal) of an old item and a consequent inplace construction (insertion) of a new item.
For comparison of bounded buffers based on different containers compile and
run [@boost:libs/circular_buffer/test/bounded_buffer_comparison.cpp bounded_buffer_comparison.cpp].
The test should reveal the bounded buffer based on the __cb is most effective
closely followed by the `std::deque` based bounded buffer.
(In reality, the result may differ sometimes because the test
is always affected by external factors such as immediate CPU load.)
[import ../test/bounded_buffer_comparison.cpp]
You can see the full test code at [@boost:libs/circular_buffer/test/bounded_buffer_comparison.cpp bounded_buffer_comparison.cpp],
and an example of output is [bounded_buffer_comparison_output].
[endsect] [/section:examples More examples]
[section:headers Header Files]
The circular buffer library is defined in the file [@boost:boost/circular_buffer.hpp circular_buffer.hpp].
#include <boost/circular_buffer.hpp>
(There is also a forward declaration for the __cb
in the header file [@boost:boost/circular_buffer_fwd.hpp circular_buffer_fwd.hpp]).
The __cb is defined in the file [@boost:boost/circular_buffer/base.hpp base.hpp].
The __cbso is defined in the file [@boost:boost/circular_buffer/space_optimized.hpp space_optimized.hpp].
[endsect] [/section:headers Header Files]
[section:concepts Modelled Concepts]
[@http://www.sgi.com/tech/stl/RandomAccessContainer.html Random Access Container],
[@http://www.sgi.com/tech/stl/FrontInsertionSequence.html Front Insertion Sequence], and
[@http://www.sgi.com/tech/stl/BackInsertionSequence.html Back Insertion sequence]
[endsect] [/section:concepts Modelled Concepts]
[section:template_params Template Parameters]
[table:templ Template parameter requirements
[[parameter] [Requirements]]
[[T] [The type of the elements stored in the circular_buffer.
The T has to be [@boost:libs/utility/Assignable.html Assignable]
and [@boost:libs/utility/CopyConstructible.html CopyConstructible].
Moreover T has to be [@http://www.sgi.com/tech/stl/DefaultConstructible.html DefaultConstructible]
if supplied as a default parameter when invoking some of the circular_buffer's methods,
e.g. `insert(iterator pos, const value_type& item = value_type())`.
And [@http://www.sgi.com/tech/stl/EqualityComparable.html EqualityComparable]
and/or [@boost:libs/utility/LessThanComparable.html LessThanComparable]
if the circular_buffer will be compared with another container.]]
[[Alloc] [The allocator type used for all internal memory management.
The Alloc has to meet the allocator requirements imposed by STL.]]
]
[endsect] [/section:template_params Template Parameters]
[section:tickets Trac Tickets]
Report and view bugs and features by adding a ticket at [@https://svn.boost.org/trac/boost Boost.Trac].
Existing open tickets for this library alone can be viewed
[@https://svn.boost.org/trac/boost/query?status=assigned&status=new&status=reopened&component=circular_buffer&col=id&col=summary&col=status&col=owner&col=type&col=milestone&order=priority here].
Existing tickets for this library - including closed ones - can be viewed
[@https://svn.boost.org/trac/boost/query?status=assigned&status=closed&status=new&status=reopened&component=circular_buffer&col=id&col=summary&col=status&col=owner&col=type&col=milestone&order=priority here].
Type: Bugs
[@https://svn.boost.org/trac/boost/ticket/4100 #4100] Some boost classes have sizeof that depends on NDEBUG.
[@https://svn.boost.org/trac/boost/ticket/5362 #5362] circular_buffer does not compile with BOOST_NO_EXCEPTIONS.
[@https://svn.boost.org/trac/boost/ticket/6277 #6277] Checked iterators are not threadsafe.
[@https://svn.boost.org/trac/boost/ticket/6747 #6747] Circular_Buffer / Bounded_Buffer inside Template class problem.
[@https://svn.boost.org/trac/boost/ticket/7025 #7025] circular buffer reports warning: " type qualifiers ignored on function return type" while compile.
[@https://svn.boost.org/trac/boost/ticket/7950 #7950] Eliminate W4-warnings under VS2005.
[@https://svn.boost.org/trac/boost/ticket/8012 #8012] Inconsistency in `linearize()`.
[@https://svn.boost.org/trac/boost/ticket/8438 #8438] `vector` & __cb storage misbehave when using compiler optimizations.
Type: Feature Requests
[@https://svn.boost.org/trac/boost/ticket/5511 #5511] Documentation needs some improvement.
[@https://svn.boost.org/trac/boost/ticket/7888 #7888] circular_buffer should support move semantics.
Type: Patches
[@https://svn.boost.org/trac/boost/ticket/8032 #8032] Warning fixes in circular_buffer.
[endsect] [/section:tickets Trac Tickets]
[section:release Release Notes]
[h4 Boost 1.56]
* C++11 allocator model support implemented by Glen Fernandes using Boost allocator_traits.
[h4 Boost 1.55]
* Documentation refactored by Paul A. Bristow using Quickbook, Doxygen and Autoindexing.
* Rvalue references emulation added by Antony Polukhin using Boost.Move.
[h4 Boost 1.42]
* Added methods erase_begin(size_type) and erase_end(size_type) with constant complexity for such types of stored elements which do not need an explicit destruction e.g. int or double.
* Similarly changed implementation of the clear() method and the destructor so their complexity is now constant for such types of stored elements which do not require an explicit destruction (the complexity for other types remains linear).
[h4 Boost 1.37]
*Added new methods is_linearized() and rotate(const_iterator).
* Fixed bugs:
[@https://svn.boost.org/trac/boost/ticket/1987 #1987] Patch to make circular_buffer.hpp #includes absolute.
[@https://svn.boost.org/trac/boost/ticket/1852 #1852] Copy constructor does not copy capacity.
[h4 Boost 1.36]
* Changed behaviour of the circular_buffer(const allocator_type&) constructor.
Since this version the constructor does not allocate any memory and both capacity and size are set to zero.
* Fixed bug:
[@https://svn.boost.org/trac/boost/ticket/191 #1919] Default constructed circular buffer throws std::bad_alloc.
[h4 Boost 1.35]
* Initial release.
[endsect] [/section:release Release Notes]
[section:acknowledgements Acknowledgements]
Thomas Witt in 2002 produced a prototype called cyclic buffer.
The circular_buffer has a short history. Its first version was a std::deque adaptor.
This container was not very effective because of many reallocations when inserting/removing an element.
Thomas Wenish did a review of this version and
motivated me to create a circular buffer which allocates memory at once when created.
The second version adapted `std::vector` but it has been abandoned soon
because of limited control over iterator invalidation.
The current version is a full-fledged STL compliant container.
Pavel Vozenilek did a thorough review of this version and came with many good ideas and improvements.
The idea of the space optimized circular buffer has been introduced by Pavel Vozenilek.
Also, I would like to thank Howard Hinnant, Nigel Stewart and everyone
who participated at the formal review for valuable comments and ideas.
Paul A. Bristow refactored the documentation in 2013 to use the full power of Quickbook, Doxygen and Autoindexing.
[endsect] [/section:acknowledgements Acknowledgements]
[section:version_id Documentation Version Info]
Last edit to Quickbook file __FILENAME__ was at __TIME__ on __DATE__.
[tip This should appear on the pdf version
(but may be redundant on a html version where the last edit date is on the first (home) page).]
[warning Home page "Last revised" is GMT, not local time. Last edit date is local time.]
[/See also Adobe Reader pdf File Properties for creation date, and PDF producer, version and page count.]
[endsect] [/section:version_id Version Info]
[xinclude autodoc.xml] [/ Using Doxygen reference documentation.]
[/ The position of this in the Quickbook determines the location of the Doxygen references section.]
[/ Index(es) should be invoked in the main module, not within a section.]
'''
<index/>
'''
[/ circular_buffer.qbk
Copyright 2013 Paul A. Bristow.
Copyright 2003-2008 Jan Gaspar.
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).
]

View File

@@ -1,68 +0,0 @@
<?xml version='1.0' encoding='iso-8859-1'?>
<!--
XSL transformation from the XML files generated by Doxygen into XHTML source
code documentation of the circular_buffer.
Copyright (c) 2003-2008 Jan Gaspar
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)
-->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:import href="doxygen2html.xslt"/>
<xsl:output method="xml" version="1.0" encoding="iso-8859-1" indent="yes" media-type="text/xml"/>
<xsl:variable name="link-prefix" select="''"/>
<xsl:variable name="standalone-functions" select="document(concat($xmldir, '/namespaceboost.xml'))/doxygen/compounddef/sectiondef[@kind='func']"/>
<xsl:template name="reference">
<xsl:value-of select="concat('#', @refid)"/>
</xsl:template>
<xsl:template name="template-parameters">
<xsl:apply-templates select="templateparamlist/param" mode="synopsis"/>
</xsl:template>
<xsl:template name="public-types">
<xsl:apply-templates select="sectiondef[@kind='public-type']/memberdef" mode="synopsis"/>
</xsl:template>
<xsl:template name="constructors">
<xsl:apply-templates select="sectiondef[@kind='public-func']/memberdef[type = '']" mode="synopsis"/>
</xsl:template>
<xsl:template name="member-functions">
<xsl:apply-templates select="sectiondef[@kind='public-func']/memberdef[type != '']" mode="synopsis"/>
</xsl:template>
<xsl:template name="standalone-functions">
<xsl:apply-templates select="$standalone-functions/memberdef[contains(argsstring, 'circular_buffer&lt;')]" mode="synopsis">
<xsl:with-param name="indent" select="''"/>
</xsl:apply-templates>
</xsl:template>
<xsl:template name="template-parameters-details">
<xsl:apply-templates select="detaileddescription//parameterlist[@kind='param']/parameteritem" mode="description"/>
</xsl:template>
<xsl:template name="public-types-details">
<xsl:apply-templates select="sectiondef[@kind='public-type']/memberdef" mode="description"/>
</xsl:template>
<xsl:template name="constructors-details">
<xsl:apply-templates select="sectiondef[@kind='public-func']/memberdef[type = '']" mode="description"/>
</xsl:template>
<xsl:template name="member-functions-details">
<xsl:apply-templates select="sectiondef[@kind='public-func']/memberdef[type != '']" mode="description"/>
</xsl:template>
<xsl:template name="standalone-functions-details">
<xsl:apply-templates select="$standalone-functions/memberdef[contains(argsstring, 'circular_buffer&lt;')]" mode="description"/>
</xsl:template>
</xsl:stylesheet>

View File

@@ -1,20 +0,0 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!--
Helper XSL transformation making plain copy of an XML tree.
Copyright (c) 2003-2008 Jan Gaspar
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)
-->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/ | node() | @* | comment() | processing-instruction()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>

View File

@@ -1,363 +0,0 @@
<?xml version='1.0' encoding='iso-8859-1'?>
<!--
Generic XSL transformation from the XML files generated by Doxygen into XHTML
source code documentation.
Copyright (c) 2003-2008 Jan Gaspar
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)
-->
<!DOCTYPE stylesheet [
<!ENTITY nbsp "&#160;">
<!ENTITY space "&#32;">
]>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:param name="container"/>
<xsl:param name="xmldir"/>
<xsl:variable name="container-ref" select="//compound[name=concat('boost::', $container) and @kind='class']/@refid"/>
<xsl:variable name="class-file" select="concat($xmldir, '/', $container-ref, '.xml')"/>
<xsl:variable name="class" select="document($class-file)/doxygen/compounddef[@id = $container-ref]"/>
<xsl:template match="/">
<html>
<header><title>Source Code Documentation</title></header>
<body>
<xsl:apply-templates select="$class" mode="synopsis"/>
<xsl:apply-templates select="$class" mode="description"/>
</body>
</html>
</xsl:template>
<xsl:template match="nonbreakablespace">
&nbsp;
</xsl:template>
<xsl:template match="bold">
<b><xsl:apply-templates/></b>
</xsl:template>
<xsl:template match="emphasis">
<i><xsl:apply-templates/></i>
</xsl:template>
<xsl:template match="linebreak">
<br />
</xsl:template>
<xsl:template match="preformatted">
<pre><xsl:apply-templates/></pre>
</xsl:template>
<xsl:template match="computeroutput">
<code><xsl:apply-templates/></code>
</xsl:template>
<xsl:template match="para">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="ref">
<xsl:variable name="link-text" select="substring-after(text(), concat($container, '::'))"/>
<xsl:choose>
<xsl:when test="string-length($link-text) &gt; 0">
<xsl:element name="a">
<xsl:attribute name="href"><xsl:call-template name="reference"/></xsl:attribute>
<xsl:value-of select="$link-text"/>
</xsl:element>
</xsl:when>
<xsl:when test="text() = $container">
<xsl:value-of select="text()"/>
</xsl:when>
<xsl:otherwise>
<xsl:element name="a">
<xsl:choose>
<xsl:when test="count(//memberdef[@id=current()/@refid]) &gt; 0">
<xsl:attribute name="href"><xsl:value-of select="concat('#', @refid)"/></xsl:attribute>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="href"><xsl:value-of select="concat($link-prefix, '#', @refid)"/></xsl:attribute>
</xsl:otherwise>
</xsl:choose>
<xsl:value-of select="text()"/>
</xsl:element>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="ulink">
<a href="{@url}"><xsl:apply-templates/></a>
</xsl:template>
<xsl:template match="parameteritem">
<xsl:param name="desc" select="''"/>
<xsl:param name="style" select="'code'"/>
<xsl:if test="$desc != ''">
<dt><b><xsl:value-of select="$desc"/></b></dt>
</xsl:if>
<dd>
<xsl:choose>
<xsl:when test="$style = 'code'">
<dl compact="yes">
<dt><code><xsl:apply-templates select="parameternamelist/parametername"/></code></dt>
<dd><xsl:apply-templates select="parameterdescription"/></dd>
</dl>
</xsl:when>
<xsl:when test="contains(parameternamelist/parametername, '&lt;code&gt;')">
<code><xsl:value-of select="substring-before(substring-after(parameternamelist/parametername, '&lt;code&gt;'), '&lt;/code&gt;')"/></code>
<xsl:apply-templates select="parameterdescription"/>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="parameternamelist/parametername"/>
<xsl:apply-templates select="parameterdescription"/>
</xsl:otherwise>
</xsl:choose>
</dd>
<xsl:apply-templates select="following-sibling::parameteritem[1]">
<xsl:with-param name="style" select="$style"/>
</xsl:apply-templates>
</xsl:template>
<xsl:template match="simplesect[@kind='return']">
<dl><dt><b>Returns:</b></dt><dd><xsl:apply-templates/></dd></dl>
</xsl:template>
<xsl:template match="simplesect[@kind='pre']">
<dl><dt><b>Precondition:</b></dt><dd><xsl:apply-templates/></dd></dl>
</xsl:template>
<xsl:template match="simplesect[@kind='post']">
<dl><dt><b>Effect:</b></dt><dd><xsl:apply-templates/></dd></dl>
</xsl:template>
<xsl:template match="simplesect[@kind='par']">
<dl><dt><b><xsl:value-of select="title"/>:</b></dt><dd><xsl:apply-templates select="para"/></dd></dl>
</xsl:template>
<xsl:template match="simplesect[@kind='warning']">
<dl><dt><b>Warning:</b></dt><dd><xsl:apply-templates/></dd></dl>
</xsl:template>
<xsl:template match="simplesect[@kind='note']">
<dl><dt><b>Note:</b></dt><dd><xsl:apply-templates/></dd></dl>
</xsl:template>
<xsl:template match="simplesect[@kind='see']">
<dl><dt><b>See Also:</b></dt><dd><xsl:apply-templates/></dd></dl>
</xsl:template>
<xsl:template match="parameterlist[@kind='param']">
<dl><xsl:apply-templates select="parameteritem[1]">
<xsl:with-param name="desc" select="'Parameter(s):'"/>
</xsl:apply-templates></dl>
</xsl:template>
<xsl:template match="parameterlist[@kind='exception']">
<dl><xsl:apply-templates select="parameteritem[1]">
<xsl:with-param name="desc" select="'Throws:'"/>
<xsl:with-param name="style" select="'plain'"/>
</xsl:apply-templates></dl>
</xsl:template>
<xsl:template match="briefdescription">
<xsl:apply-templates/>
</xsl:template>
<!-- Synopsis mode -->
<xsl:template match="compounddef[@kind = 'class']" mode="synopsis">
<div id="srcdoc_synopsis">
<table id="table_synopsis" border="0" cellpadding="10">
<tr><td>
<pre>
namespace boost {
template &lt;<xsl:call-template name="template-parameters"/>&gt;
class <xsl:value-of select="$container"/>
{
public:
<xsl:call-template name="public-types"/><xsl:text disable-output-escaping="yes">
</xsl:text>
<xsl:call-template name="constructors"/><xsl:text disable-output-escaping="yes">
</xsl:text>
<xsl:call-template name="member-functions"/><xsl:text disable-output-escaping="yes">};
</xsl:text>
<xsl:call-template name="standalone-functions"/>
} // namespace boost
</pre>
</td></tr>
</table>
</div>
</xsl:template>
<xsl:template match="param" mode="synopsis">
<xsl:param name="link-prefix" select="''"/>
<xsl:value-of select="type"/>&nbsp;<a href="{$link-prefix}#templateparam_{declname}"><xsl:value-of select="declname"/></a><xsl:value-of select="substring(', ', 1 div (count(following-sibling::param) != 0))"/>
</xsl:template>
<xsl:template match="memberdef[@kind='typedef']" mode="synopsis">
<xsl:param name="link-prefix" select="''"/>
<xsl:if test="normalize-space(briefdescription) != ''">&nbsp;&nbsp;&nbsp;typedef&nbsp;<xsl:value-of select="substring('typename ', 1 div (contains(type, '::') and not(contains(type, '&gt;'))))"/>
<xsl:choose>
<xsl:when test="contains(type, 'cb_details::')"><i>implementation-defined</i>&nbsp;</xsl:when>
<xsl:otherwise><xsl:apply-templates select="type" mode="synopsis"/>&nbsp;</xsl:otherwise>
</xsl:choose>
<a href="{$link-prefix}#{@id}"><xsl:value-of select="name"/></a>;<xsl:text disable-output-escaping="yes">
</xsl:text>
</xsl:if>
</xsl:template>
<xsl:template match="memberdef[@kind='function']" mode="synopsis">
<xsl:param name="indent" select="'&nbsp;&nbsp;&nbsp;'"/>
<xsl:param name="link-prefix" select="''"/>
<xsl:param name="link" select="''"/>
<xsl:value-of select="$indent"/>
<xsl:value-of select="substring('explicit ', 1 div (@explicit = 'yes'))"/>
<xsl:if test="count(templateparamlist) &gt; 0">template&nbsp;&lt;<xsl:for-each select="templateparamlist/param"><xsl:value-of select="type"/>&nbsp;<xsl:value-of select="declname"/><xsl:value-of select="substring(', ', 1 div (count(following-sibling::param) != 0))"/></xsl:for-each>&gt;<xsl:text disable-output-escaping="yes">
&nbsp;&nbsp;&nbsp;</xsl:text><xsl:value-of select="$indent"/>
</xsl:if>
<xsl:if test="type != ''"><xsl:apply-templates select="type" mode="synopsis"/>&nbsp;</xsl:if>
<a href="{$link-prefix}#{concat(substring(@id, 1 div (string-length($link) = 0)), substring($link, 1 div (string-length($link) &gt; 0)))}">
<xsl:value-of select="name"/>
</a>(<xsl:for-each select="param">
<xsl:apply-templates select="type" mode="synopsis"/>&nbsp;<xsl:value-of select="declname"/>
<xsl:value-of select="substring(concat(' = ', defval), 1 div (normalize-space(defval) != ''))"/>
<xsl:value-of select="substring(', ', 1 div (count(following-sibling::param) != 0))"/>
</xsl:for-each>)<xsl:value-of select="substring(' const', 1 div (@const = 'yes'))"/>;<xsl:text disable-output-escaping="yes">
</xsl:text>
</xsl:template>
<xsl:template match="type" mode="synopsis">
<xsl:for-each select="text() | ref">
<xsl:variable name="item" select="translate(., '&space;', '')"/>
<xsl:choose>
<xsl:when test="contains($item, 'return_value_type') or contains($item, 'param_value_type')">const_reference</xsl:when>
<xsl:otherwise>
<xsl:choose>
<xsl:when test="contains($item, ',')"><xsl:value-of select="concat(substring-before($item, ','), ',&nbsp;', substring-after($item, ','))"/></xsl:when>
<xsl:otherwise><xsl:value-of select="$item"/></xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
<xsl:if test="not(contains($item, '&lt;')) and not(contains($item, ',')) and name(.) != 'ref' and position() != last()">&nbsp;</xsl:if>
</xsl:for-each>
</xsl:template>
<!-- Description mode -->
<xsl:template match="compounddef[@kind = 'class']" mode="description">
<div id="srcdoc_params">
<table id="table_template_params" border="1" cellpadding="3">
<tr><th>Parameter</th><th>Description</th><th>Default</th></tr>
<xsl:call-template name="template-parameters-details"/>
</table>
</div>
<div id="srcdoc_types">
<table id="table_public_types" border="1" cellpadding="3">
<tr><th>Type</th><th>Description</th></tr>
<xsl:call-template name="public-types-details"/>
</table>
</div>
<div id="srcdoc_constructors">
<table id="table_constructors" border="1" cellpadding="3">
<xsl:call-template name="constructors-details"/>
</table>
</div>
<div id="srcdoc_methods">
<table id="table_methods" border="1" cellpadding="3">
<xsl:call-template name="member-functions-details"/>
</table>
</div>
<div id="srcdoc_functions">
<table id="table_functions" border="1" cellpadding="3">
<xsl:call-template name="standalone-functions-details"/>
</table>
</div>
</xsl:template>
<xsl:template match="parameteritem" mode="description">
<tr><td><a id="templateparam_{parameternamelist/parametername}"><code><xsl:value-of select="parameternamelist/parametername"/></code></a></td>
<td>
<xsl:apply-templates select="parameterdescription"/>
<xsl:variable name="type-rqmts" select="concat('Type Requirements ', parameternamelist/parametername)"/>
<xsl:if test="../../simplesect[@kind='par']/title = $type-rqmts">
<dl><dt><b>Type Requirements:</b></dt>
<dd><xsl:apply-templates select="../../simplesect[@kind='par'][title=$type-rqmts]/para"/></dd></dl>
</xsl:if>
</td>
<xsl:variable name="default-value" select="concat('Default ', parameternamelist/parametername)"/>
<xsl:choose>
<xsl:when test="../../simplesect[@kind='par']/title = $default-value">
<td><code><xsl:value-of select="../../simplesect[@kind='par'][title=$default-value]/para"/></code></td>
</xsl:when>
<xsl:otherwise><td><br/></td></xsl:otherwise>
</xsl:choose>
</tr>
</xsl:template>
<xsl:template match="memberdef[@kind='typedef']" mode="description">
<xsl:if test="normalize-space(briefdescription) != ''">
<tr><td><a id="{@id}"><code><xsl:value-of select="name"/></code></a></td>
<td>
<xsl:apply-templates select="briefdescription/child::*"/>
<xsl:if test="boolean(detaileddescription/para)">
<xsl:apply-templates select="detaileddescription/para/text()|detaileddescription/para/child::*"/>
</xsl:if>
</td></tr>
</xsl:if>
</xsl:template>
<xsl:template match="memberdef[@kind='function']" mode="description">
<xsl:param name="link-prefix" select="''"/>
<tr><td><a id="{@id}" /><code><b><xsl:value-of select="substring('explicit ', 1 div (@explicit = 'yes'))"/>
<xsl:if test="count(templateparamlist) &gt; 0">
template&nbsp;&lt;<xsl:for-each select="templateparamlist/param"><xsl:value-of select="type"/>&nbsp;<xsl:value-of select="declname"/><xsl:value-of select="substring(', ', 1 div (count(following-sibling::param) != 0))"/></xsl:for-each>&gt;<br />&nbsp;&nbsp;&nbsp;
</xsl:if>
<xsl:if test="type != ''"><xsl:apply-templates select="type" mode="description"/>&nbsp;</xsl:if>
<xsl:value-of select="name"/>(<xsl:for-each select="param">
<xsl:apply-templates select="type" mode="description"/>&nbsp;<xsl:value-of select="declname"/>
<xsl:value-of select="substring(concat(' = ', defval), 1 div (normalize-space(defval) != ''))"/>
<xsl:value-of select="substring(', ', 1 div (count(following-sibling::param) != 0))"/>
</xsl:for-each>)<xsl:value-of select="substring(' const', 1 div (@const = 'yes'))"/>;</b></code><br /><br />
<xsl:apply-templates select="briefdescription"/>
<xsl:if test="normalize-space(detaileddescription) = ''">
<br /><br />
</xsl:if>
<p><xsl:apply-templates select="detaileddescription"/></p>
</td></tr>
</xsl:template>
<xsl:template match="type" mode="description">
<xsl:for-each select="text() | ref">
<xsl:variable name="item" select="translate(., '&space;', '')"/>
<xsl:choose>
<xsl:when test="$item = 'return_value_type' or $item = 'param_value_type'">
<xsl:variable name="const-reference" select="$class[@kind = 'class']/sectiondef[@kind='public-type']/memberdef[@kind='typedef' and name='const_reference']"/>
<xsl:choose>
<xsl:when test="boolean($const-reference/reimplements)">
<a href="{$link-prefix}#{$const-reference/reimplements/@refid}">const_reference</a>
</xsl:when>
<xsl:otherwise>
<a href="{$link-prefix}#{$const-reference/@id}">const_reference</a>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:when test="contains($item, 'circular_buffer')"><xsl:value-of select="$item"/></xsl:when>
<xsl:when test="@refid">
<xsl:element name="a">
<xsl:attribute name="href"><xsl:call-template name="reference"/></xsl:attribute>
<xsl:value-of select="$item"/>
</xsl:element>
</xsl:when>
<xsl:otherwise><xsl:value-of select="$item"/></xsl:otherwise>
</xsl:choose>
<xsl:if test="name(.) != 'ref' and position() != last()">&nbsp;</xsl:if>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

View File

@@ -1,18 +0,0 @@
<?xml version='1.0' encoding='iso-8859-1'?>
<!--
Helper XSL transformation which converts HTML into XHTML.
Copyright (c) 2003-2008 Jan Gaspar
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)
-->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:import href="copy.xslt"/>
<xsl:output method="xml" version="1.0" encoding="iso-8859-1" indent="yes" media-type="text/html"/>
</xsl:stylesheet>

View File

Before

Width:  |  Height:  |  Size: 21 KiB

After

Width:  |  Height:  |  Size: 21 KiB

View File

Before

Width:  |  Height:  |  Size: 25 KiB

After

Width:  |  Height:  |  Size: 25 KiB

219
doc/jamfile.v2 Normal file
View File

@@ -0,0 +1,219 @@
# Boost.circular_buffer library documentation Jamfile.v2
#
# Copyright Paul A. Bristow 2013.
# Copyright Jan Gaspar 2003-2008.
# 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)
path-constant nav_images : html/images/ ; # png and svg images for home, next, note, tip...
path-constant images_location : html/images ; # location of my SVG and PNG images referenced by Quickbook.
path-constant pdf_images_location : .. ; # location of SVG and PNG images referenced by pdf.
path-constant here : . ; # location of /doc folder.
# echo "nav_images = " $(nav_images) ; # "nav_images = I:\boost-trunk\libs\circular_buffer\doc\html\images
# echo "images_location = " $(images_location) ; # images_location = I:\boost-trunk\libs\circular_buffer\doc\html\images
# echo "pdf_images_location = " $(pdf_images_location) #
import modules ;
using auto-index ;
using doxygen ; # Required if you want to use Doxygen.
using quickbook ;
doxygen autodoc
:
# List all the files individually (RECURSIVE=NO ).
[ glob ../../../boost/circular_buffer.hpp ]
[ glob ../../../boost/circular_buffer/base.hpp ]
[ glob ../../../boost/circular_buffer/space_optimized.hpp ]
[ glob ../../../boost/circular_buffer/details.hpp ] # Needed for capacity_control at least.
[ glob ../../../boost/circular_buffer/debug.hpp ] # not needed?
:
# Pass some setting parameters to Doxygen.
<doxygen:param>WARNINGS=YES # Default NO, but useful to see warnings, especially in a logfile.
# It is also wise to to set a warnings logfile like this:
<doxygen:param>WARN_LOGFILE=AutoDoxywarnings.log # This may not be empty (usually not a good sign!), depending on options chosen.
# Much better to send message to a logfile than the default stderr.
# and make sure that there are no Doxygen errors or significant warnings in the log file.
<doxygen:param>RECURSIVE=NO # Search recursively down .hpp and .cpp subdirectories.
<doxygen:param>EXTRACT_ALL=NO
<doxygen:param>EXTRACT_PRIVATE=NO # NO means do not extract info about private member functions and data.
<doxygen:param>HIDE_UNDOC_MEMBERS=YES # Only show members that have some documentation like \param, \return ...
<doxygen:param>MACRO_EXPANSION=YES # YES will expand all macro names in the source code (default = NO).
<doxygen:param>EXPAND_ONLY_PREDEF=YES # If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES
# then the macro expansion is limited to the macros specified with the PREDEFINED and EXPAND_AS_DEFINED tags.
# If EXPAND_ONLY_PREDEF tag can be used to specify a list of macro names that should be expanded (as defined).
# The PREDEFINED tag can be used to specify one or more macro names that are defined
# before the preprocessor is started (similar to the -D option of gcc).
# The argument of the tag is a list of macros of the form:
# name or name=definition (no spaces).
# If the definition and the "=" are omitted, "=1" is assumed.
# To prevent a macro definition from being undefined via #undef or
# recursively expanded use the := operator instead of the = operator.
# See http://www.stack.nl/~dimitri/doxygen/config.html#cfg_predefined.
# static char *malloc BOOST_PREVENT_MACRO_SUBSTITUTION(const size_type bytes);
# will not produce a helpful Doxygen output, so
# replace some with more helpful text, or none, for example:
<doxygen:param>"PREDEFINED= \\
\"BOOST_PREVENT_MACRO_SUBSTITUTION\" \\
\"BOOST_STATIC_CONSTANT(T,V)=static x const y\" \\
\"BOOST_UNITS_AUTO_STATIC_CONSTANT(a,b)=static const auto a = b\" \\
\"BOOST_DEDUCED_TYPENAME=typename\" \\
\"BOOST_CONSTEXPR=constexpr\" \\
\"BOOST_CONTAINER_NOEXCEPT=noexcept\" \\
\"BOOST_CONTAINER_NOEXCEPT_IF(T)=noexcept(T)\" \\
\"BOOST_UNITS_TYPEOF(a)=typeof(a)\" \\
\"BOOST_UNITS_HAS_TYPEOF=1\" \\
\"BOOST_MPL_ASSERT(expr)=\" \\
\"BOOST_ASSERT(expr)=\" \\
\"BOOST_RV_REF(T)=T &&\" \\
\"ASSERT(x)=assert(x)\" \\
\"__cplusplus \""
# BOOST_PREVENT_MACRO_SUBSTITUTION, will not be replaced by ,
# BOOST_STATIC_CONSTANT will be replaced by "static x const y",
# BOOST_DEDUCED_TYPENAME will be replaced by "typename",
# BOOST_CONSTEXPR will be replaced by "constexpr".
<doxygen:param>EXCLUDE_SYMBOLS=*_throws
# <doxygen:param>IMAGE_PATH="../images" # for circular_buffer.png
# See autodoxywarnings.log to check this is correct.
# The syntax hoops to jump through are 'interesting' for more than one PREDEFINED,
# and to permit spaces within definitions (use double quotes).
# Don't forget that every double quote " needs a preceeding \trip character!
# and that each trailing continuation \ needs a preceeding \trip character too!
# And finally that if more than one item is included (as here) the whole is
# enclosed in "PREDEFINED=... ", but without a leading \. Go figure...
# A grep for PREDEFINED= in jamfiles will reveal even more complex examples.
# Boost Libraries with useful examples are: Accumulators, Interprocess, MPI, Random, Units, Expressive.
# Optionally, you can provide a Reference section name specific for your library, for example:
<xsl:param>"boost.doxygen.reftitle=Boost.Circular_buffer C++ Reference"
;
xml circular_buffer : circular_buffer.qbk ;
using boostbook ;
boostbook standalone
:
circular_buffer
:
# General settings
# =================
<format>html:<xsl:param>boost.root=../../../..
<format>html:<xsl:param>img.src.path=../../../../doc/html/
<format>docbook:<xsl:param>boost.root=boost:
# Options for html and pdf
# ========================
# No indent on body text:
<xsl:param>body.start.indent=0pt
# Margin size:
<xsl:param>page.margin.inner=0.5in
# Margin size:
<xsl:param>page.margin.outer=0.5in
# Yes, we want graphics for admonishments:
<xsl:param>admon.graphics=1
# HTML options:
# =============
# Use graphics icons not text for navigation:
<xsl:param>navig.graphics=1
# How far down we chunk nested sections, basically all of them:
<xsl:param>chunk.section.depth=2
# Don't put the first section on the same page as the TOC itself:
<xsl:param>chunk.first.sections=1
# How far down sections get TOC's
<xsl:param>toc.section.depth=4
# Max depth in each TOC:
<xsl:param>toc.max.depth=2
# How far down we go with TOC's
<xsl:param>generate.section.toc.level=10
# Horizontal ? spacing in table cells.
<format>html:<xsl:param>html.cellspacing=3 # pixels
# Vertical spacing in table cells.
<format>html:<xsl:param>html.cellpadding=5 # pixels
# Not sure if these are right way round?
<auto-index>on # Turns on index (or off).
# Turns on (or off) index-verbose for diagnostic info (using /bin auto-index-verbose folders).
<auto-index-verbose>on
<format>pdf:<auto-index-internal>off # on (or off) to use internally generated indexes.
<format>html:<xsl:param>index.on.type=1 # = 1 For the native stylesheets to generate multiple different indexes.
<auto-index-script>circular_buffer.idx # Specifies the name of the script to load for circular_buffer.
<auto-index-prefix>../../.. # Will get you back up to /circular_buffer, so !scan-path "boost/circular_buffer/" is where *.hpp will be,
# and /libs/circular_buffer for other files.
# Without this would need !scan-path "../../../boost/circular_buffer"
# Used by Quickbook to invoke indexing.
# Required by boost-trunk/doc/ see jamfile.v2 to use auto-index.
# Choose indexing method for html:
<format>html:<auto-index-internal>on
<format>docbook:<auto-index-internal>on
# PDF Options:
# ============
# TOC Generation: this is needed for FOP-0.9 and later:
<format>pdf:<xsl:param>fop1.extensions=0
# Or enable this if you're using XEP:
<format>pdf:<xsl:param>xep.extensions=1
# TOC generation: this is needed for FOP 0.2, but must not be set to zero for FOP-0.9!
<format>pdf:<xsl:param>fop.extensions=0
# No indent on body text:
<xsl:param>body.start.indent=0pt
# Margin size:
<xsl:param>page.margin.inner=0.5in
# Margin size:
<xsl:param>page.margin.outer=0.5in
# Yes, we want graphics for admonishments:
<xsl:param>admon.graphics=1
# Set these one for PDF generation *only*:
# default png graphics are awful in PDF form,
# better use SVG instead:
<format>pdf:<xsl:param>admon.graphics.extension=".svg"
#<format>pdf:<xsl:param>admon.graphics.extension=".png" # Only png images are available.
# Don't need this, default path works OK:
#<format>pdf:<xsl:param>admon.graphics.path=$(nav_images)/ # next, prev, note, tip ... for pdf.
<format>pdf:<xsl:param>use.role.for.mediaobject=1
<format>pdf:<xsl:param>preferred.mediaobject.role=print
<format>pdf:<xsl:param>img.src.path=$(pdf_images_location)/ # graphics (diagrams) for pdf.
<format>pdf:<xsl:param>draft.mode="no"
<format>pdf:<xsl:param>boost.url.prefix=../../../..
<dependency>autodoc #
<dependency>png_install
;
# Install (copy) the 'master' copies of all icon images (both PNG and SVG)
# and the Boost logo from your current Boost-root
# to the local /doc/html/images folder so that html is complete and standalone.
install png_install : [ glob $(here)/*.png ] : <location>$(here)/../../../doc/html/images ;
# install pdf-install : standalone : <install-type>PDF <location>. ;
# Effectively copies the file from \bin folder to the \doc folder,
# but will not work as expected if doxygen and/or autoindex is used
# because a modified pdf file is created, so this command
# will rename the file to the expected filename, here circular_buffer.pdf.
install pdfinstall : standalone : <install-type>PDF <location>. <name>circular_buffer.pdf ;
###############################################################################
alias boostdoc
: standalone/<format>docbook
:
:
: ;
explicit boostdoc ;
alias boostrelease ;
explicit boostrelease ;

File diff suppressed because it is too large Load Diff

View File

@@ -1,106 +0,0 @@
<?xml version='1.0' encoding='iso-8859-1'?>
<!--
XSL transformation from the XML files generated by Doxygen into XHTML source
code documentation of the circular_buffer_space_optimized.
Copyright (c) 2003-2008 Jan Gaspar
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)
-->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:import href="doxygen2html.xslt"/>
<xsl:output method="xml" version="1.0" encoding="iso-8859-1" indent="yes" media-type="text/xml"/>
<xsl:variable name="link-prefix" select="'circular_buffer.html'"/>
<xsl:variable name="circular_buffer-ref" select="//compound[name='boost::circular_buffer' and @kind='class']/@refid"/>
<xsl:variable name="circular_buffer-file" select="concat($xmldir, '/', $circular_buffer-ref, '.xml')"/>
<xsl:variable name="circular_buffer-reimplemented" select="document($circular_buffer-file)/doxygen/compounddef[@id = $circular_buffer-ref and @kind = 'class']//reimplementedby"/>
<xsl:variable name="standalone-functions" select="document(concat($xmldir, '/namespaceboost.xml'))/doxygen/compounddef/sectiondef[@kind='func']"/>
<xsl:template name="reference">
<xsl:variable name="refid" select="$circular_buffer-reimplemented[@refid=current()/@refid and text()!='capacity_type']/../@id"/>
<xsl:value-of select="concat(substring(concat($link-prefix, '#', $refid), 1 div (string-length($refid) &gt; 0)), substring(concat('#', @refid), 1 div (string-length($refid) = 0)))"/>
</xsl:template>
<xsl:template name="template-parameters">
<xsl:apply-templates select="templateparamlist/param" mode="synopsis">
<xsl:with-param name="link-prefix" select="$link-prefix"/>
</xsl:apply-templates>
</xsl:template>
<xsl:template name="public-types">
<xsl:for-each select="sectiondef[@kind='public-type']/memberdef">
<xsl:if test="string-length(normalize-space(briefdescription)) &gt; 0">
<xsl:choose>
<xsl:when test="document($circular_buffer-file)/doxygen/compounddef[@id = $circular_buffer-ref and @kind = 'class']/sectiondef[@kind='public-type']/memberdef[name=current()/name]/briefdescription = briefdescription">
<xsl:apply-templates select="document($circular_buffer-file)/doxygen/compounddef[@id = $circular_buffer-ref and @kind = 'class']/sectiondef[@kind='public-type']/memberdef[name=current()/name]" mode="synopsis">
<xsl:with-param name="link-prefix" select="$link-prefix"/>
</xsl:apply-templates>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="." mode="synopsis"/>
</xsl:otherwise>
</xsl:choose>
</xsl:if>
</xsl:for-each>
</xsl:template>
<xsl:template name="constructors">
<xsl:for-each select="sectiondef[@kind='public-func']/memberdef[type = '']">
<xsl:variable name="briefdescription" select="normalize-space(briefdescription)"/>
<xsl:if test="string-length($briefdescription) &gt; 0">
<xsl:apply-templates select="." mode="synopsis"/>
</xsl:if>
</xsl:for-each>
</xsl:template>
<xsl:template name="member-functions">
<xsl:variable name="current" select="sectiondef[@kind='public-func']/memberdef[type != '']"/>
<xsl:for-each select="document($circular_buffer-file)/doxygen/compounddef[@id = $circular_buffer-ref and @kind = 'class']/sectiondef[@kind='public-func']/memberdef[type != '']">
<xsl:if test="count($current[name=current()/name and string-length(normalize-space(briefdescription)) &gt; 0]) = 0">
<xsl:apply-templates select="." mode="synopsis">
<xsl:with-param name="link-prefix" select="$link-prefix"/>
</xsl:apply-templates>
</xsl:if>
</xsl:for-each>
<xsl:for-each select="$current[string-length(normalize-space(briefdescription)) &gt; 0]">
<xsl:apply-templates select="." mode="synopsis"/>
</xsl:for-each>
</xsl:template>
<xsl:template name="standalone-functions">
<xsl:for-each select="$standalone-functions/memberdef[contains(argsstring, 'circular_buffer_space_optimized&lt;')]">
<xsl:apply-templates select="." mode="synopsis">
<xsl:with-param name="indent" select="''"/>
<xsl:with-param name="link-prefix" select="$link-prefix"/>
<xsl:with-param name="link" select="$standalone-functions/memberdef[contains(argsstring, 'circular_buffer&lt;') and name=current()/name]/@id"/>
</xsl:apply-templates>
</xsl:for-each>
</xsl:template>
<xsl:template name="template-parameters-details"/>
<xsl:template name="public-types-details">
<xsl:apply-templates select="sectiondef[@kind='public-type']/memberdef[not(contains(type, 'circular_buffer&lt;'))]" mode="description"/>
</xsl:template>
<xsl:template name="constructors-details">
<xsl:for-each select="sectiondef[@kind='public-func']/memberdef[type = '' and string-length(normalize-space(briefdescription)) &gt; 0]">
<xsl:apply-templates select="." mode="description"/>
</xsl:for-each>
</xsl:template>
<xsl:template name="member-functions-details">
<xsl:for-each select="sectiondef[@kind='public-func']/memberdef[type != '' and string-length(normalize-space(briefdescription)) &gt; 0]">
<xsl:apply-templates select="." mode="description"/>
</xsl:for-each>
</xsl:template>
<xsl:template name="standalone-functions-details"/>
</xsl:stylesheet>

View File

@@ -1,54 +0,0 @@
#!/bin/sh
################################################################################
# Shell script which updates the Circular Buffer library documentation with #
# the latest source code documentation (which is in the source files). #
# #
# Copyright (c) 2003-2008 Jan Gaspar #
# #
# 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) #
################################################################################
CONTAINER=$1
DOCFILE="$CONTAINER.html"
XSLT="$CONTAINER.xslt"
XHTML="$CONTAINER.xhtml"
SPECIALIZATION=${CONTAINER#circular_buffer_}
if [ ${#SPECIALIZATION} -gt 0 ]; then
DOCFILE=${DOCFILE#circular_buffer_}
XSLT=${XSLT#circular_buffer_}
XHTML=${XHTML#circular_buffer_}
fi
if [ -f $DOCFILE ]; then
echo Starting Doxygen ...
doxygen
echo Converting Doxygen generated source code documentation into XHTML ...
xsltproc --stringparam container $CONTAINER --stringparam xmldir srcdoc -o srcdoc/srcdoc.xhtml $XSLT srcdoc/index.xml
echo Preprocessing $DOCFILE ...
sed 's/<a\s*id="[^"]*"/<a /g' $DOCFILE | sed 's/<a\s*\(name="[^"]*"\)\s*\(id="[^"]*"\)/<a \1/g' > srcdoc/$DOCFILE
echo Converting preprocessed $DOCFILE into XHTML ...
xsltproc --html -o srcdoc/$XHTML html2xhtml.xslt srcdoc/$DOCFILE
echo Generating $DOCFILE with updated source code documentation ...
xsltproc --stringparam srcdoc srcdoc/srcdoc.xhtml -o $DOCFILE update_srcdoc.xslt srcdoc/$XHTML
echo Correcting and pretty-printing $DOCFILE with HTML Tidy ...
tidy -ashtml -config Tidy.conf $DOCFILE
echo Removing temporary directory ...
rm -rf srcdoc
echo Done.
else
echo Usage: update_srcdoc.sh container
fi

View File

@@ -1,25 +0,0 @@
<?xml version='1.0' encoding='iso-8859-1'?>
<!--
Helper XSL transformation updating source code documentation sections
in the specified HTML file.
Copyright (c) 2003-2008 Jan Gaspar
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)
-->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:import href="copy.xslt"/>
<xsl:output method="html" version="1.0" encoding="iso-8859-1" indent="yes" omit-xml-declaration="yes" media-type="text/html"/>
<xsl:param name="srcdoc"/>
<xsl:template match="div[contains(@id, 'srcdoc')]">
<xsl:copy-of select="document($srcdoc)//body/div[@id=current()/@id]"/>
</xsl:template>
</xsl:stylesheet>

View File

@@ -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/call_traits.hpp>
#include <boost/progress.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::progress_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(__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]
*/

View File

@@ -0,0 +1,191 @@
// 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
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(__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]
*/

View File

@@ -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 threee 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]
*/

View File

@@ -0,0 +1,14 @@
echo off
rem quickbook doxgen 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

View File

@@ -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]

View File

@@ -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.
*/

42
example/jamfile.v2 Normal file
View File

@@ -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 ;
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 ;

View File

@@ -11,18 +11,17 @@
#if !defined(BOOST_CIRCULAR_BUFFER_HPP)
#define BOOST_CIRCULAR_BUFFER_HPP
#if defined(_MSC_VER) && _MSC_VER >= 1200
#if defined(_MSC_VER)
#pragma once
#endif
#include <boost/circular_buffer_fwd.hpp>
#include <boost/detail/workaround.hpp>
#include <boost/static_assert.hpp>
// BOOST_CB_ENABLE_DEBUG: Debug support control.
#if defined(NDEBUG) || defined(BOOST_CB_DISABLE_DEBUG)
#if !defined(BOOST_CB_ENABLE_DEBUG)
#define BOOST_CB_ENABLE_DEBUG 0
#else
#define BOOST_CB_ENABLE_DEBUG 1
#endif
// BOOST_CB_ASSERT: Runtime assertion.
@@ -33,29 +32,20 @@
#define BOOST_CB_ASSERT(Expr) ((void)0)
#endif
// BOOST_CB_STATIC_ASSERT: Compile time assertion.
#if BOOST_WORKAROUND(BOOST_MSVC, < 1300)
#define BOOST_CB_STATIC_ASSERT(Expr) ((void)0)
#else
#include <boost/static_assert.hpp>
#define BOOST_CB_STATIC_ASSERT(Expr) BOOST_STATIC_ASSERT(Expr)
#endif
// BOOST_CB_IS_CONVERTIBLE: Check if Iterator::value_type is convertible to Type.
#if BOOST_WORKAROUND(__BORLANDC__, <= 0x0550) || BOOST_WORKAROUND(__MWERKS__, <= 0x2407) || \
BOOST_WORKAROUND(BOOST_MSVC, < 1300)
#if BOOST_WORKAROUND(__BORLANDC__, <= 0x0550) || BOOST_WORKAROUND(__MWERKS__, <= 0x2407)
#define BOOST_CB_IS_CONVERTIBLE(Iterator, Type) ((void)0)
#else
#include <boost/detail/iterator.hpp>
#include <boost/type_traits/is_convertible.hpp>
#define BOOST_CB_IS_CONVERTIBLE(Iterator, Type) \
BOOST_CB_STATIC_ASSERT((is_convertible<typename detail::iterator_traits<Iterator>::value_type, Type>::value))
BOOST_STATIC_ASSERT((is_convertible<typename detail::iterator_traits<Iterator>::value_type, Type>::value))
#endif
// BOOST_CB_ASSERT_TEMPLATED_ITERATOR_CONSTRUCTORS:
// Check if the STL provides templated iterator constructors for its containers.
#if defined(BOOST_NO_TEMPLATED_ITERATOR_CONSTRUCTORS)
#define BOOST_CB_ASSERT_TEMPLATED_ITERATOR_CONSTRUCTORS BOOST_CB_STATIC_ASSERT(false);
#define BOOST_CB_ASSERT_TEMPLATED_ITERATOR_CONSTRUCTORS BOOST_STATIC_ASSERT(false);
#else
#define BOOST_CB_ASSERT_TEMPLATED_ITERATOR_CONSTRUCTORS ((void)0);
#endif
@@ -67,8 +57,6 @@
#undef BOOST_CB_ASSERT_TEMPLATED_ITERATOR_CONSTRUCTORS
#undef BOOST_CB_IS_CONVERTIBLE
#undef BOOST_CB_STATIC_ASSERT
#undef BOOST_CB_ASSERT
#undef BOOST_CB_ENABLE_DEBUG
#endif // #if !defined(BOOST_CIRCULAR_BUFFER_HPP)

File diff suppressed because it is too large Load Diff

View File

@@ -9,10 +9,20 @@
#if !defined(BOOST_CIRCULAR_BUFFER_DEBUG_HPP)
#define BOOST_CIRCULAR_BUFFER_DEBUG_HPP
#if defined(_MSC_VER) && _MSC_VER >= 1200
#if defined(_MSC_VER)
#pragma once
#endif
#if BOOST_CB_ENABLE_DEBUG
#include <cstring>
#if defined(BOOST_NO_STDC_NAMESPACE)
namespace std {
using ::memset;
}
#endif
#endif // BOOST_CB_ENABLE_DEBUG
namespace boost {
namespace cb_details {
@@ -22,6 +32,17 @@ namespace cb_details {
// The value the uninitialized memory is filled with.
const int UNINITIALIZED = 0xcc;
template <class T>
inline void do_fill_uninitialized_memory(T* data, std::size_t size_in_bytes) BOOST_NOEXCEPT {
std::memset(static_cast<void*>(data), UNINITIALIZED, size_in_bytes);
}
template <class T>
inline void do_fill_uninitialized_memory(T& /*data*/, std::size_t /*size_in_bytes*/) BOOST_NOEXCEPT {
// Do nothing
}
class debug_iterator_registry;
/*!

View File

@@ -1,6 +1,7 @@
// Helper classes and functions for the circular buffer.
// Copyright (c) 2003-2008 Jan Gaspar
// Copyright (c) 2014 Glen Fernandes // C++11 allocator model support.
// Use, modification, and distribution is subject to the Boost Software
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
@@ -9,15 +10,26 @@
#if !defined(BOOST_CIRCULAR_BUFFER_DETAILS_HPP)
#define BOOST_CIRCULAR_BUFFER_DETAILS_HPP
#if defined(_MSC_VER) && _MSC_VER >= 1200
#if defined(_MSC_VER)
#pragma once
#endif
#include <boost/iterator.hpp>
#include <boost/throw_exception.hpp>
#include <boost/container/allocator_traits.hpp>
#include <boost/move/move.hpp>
#include <boost/type_traits/is_nothrow_move_constructible.hpp>
#include <boost/utility/addressof.hpp>
#include <boost/detail/no_exceptions_support.hpp>
#include <iterator>
// Silence MS /W4 warnings like C4913:
// "user defined binary operator ',' exists but no overload could convert all operands, default built-in binary operator ',' used"
// This might happen when previously including some boost headers that overload the coma operator.
#if defined(_MSC_VER)
# pragma warning(push)
# pragma warning(disable:4913)
#endif
namespace boost {
namespace cb_details {
@@ -29,8 +41,10 @@ void uninitialized_fill_n_with_alloc(
ForwardIterator first, Diff n, const T& item, Alloc& alloc);
template<class InputIterator, class ForwardIterator, class Alloc>
ForwardIterator uninitialized_copy_with_alloc(
InputIterator first, InputIterator last, ForwardIterator dest, Alloc& alloc);
ForwardIterator uninitialized_copy(InputIterator first, InputIterator last, ForwardIterator dest, Alloc& a);
template<class InputIterator, class ForwardIterator, class Alloc>
ForwardIterator uninitialized_move_if_noexcept(InputIterator first, InputIterator last, ForwardIterator dest, Alloc& a);
/*!
\struct const_traits
@@ -98,7 +112,7 @@ private:
*/
template <class Value, class Alloc>
struct assign_n {
typedef typename Alloc::size_type size_type;
typedef typename boost::container::allocator_traits<Alloc>::size_type size_type;
size_type m_n;
Value m_item;
Alloc& m_alloc;
@@ -117,19 +131,24 @@ private:
*/
template <class Iterator, class Alloc>
struct assign_range {
const Iterator& m_first;
const Iterator& m_last;
Alloc& m_alloc;
Iterator m_first;
Iterator m_last;
Alloc& m_alloc;
assign_range(const Iterator& first, const Iterator& last, Alloc& alloc)
: m_first(first), m_last(last), m_alloc(alloc) {}
: m_first(first), m_last(last), m_alloc(alloc) {}
template <class Pointer>
void operator () (Pointer p) const {
uninitialized_copy_with_alloc(m_first, m_last, p, m_alloc);
boost::cb_details::uninitialized_copy(m_first, m_last, p, m_alloc);
}
private:
assign_range<Iterator, Alloc>& operator = (const assign_range<Iterator, Alloc>&); // do not generate
};
template <class Iterator, class Alloc>
inline assign_range<Iterator, Alloc> make_assign_range(const Iterator& first, const Iterator& last, Alloc& a) {
return assign_range<Iterator, Alloc>(first, last, a);
}
/*!
\class capacity_control
\brief Capacity controller of the space optimized circular buffer.
@@ -137,18 +156,19 @@ private:
template <class Size>
class capacity_control {
//! The capacity of the space optimized circular buffer.
//! The capacity of the space-optimized circular buffer.
Size m_capacity;
//! The lowest guaranteed capacity of the adapted circular buffer.
//! The lowest guaranteed or minimum capacity of the adapted space-optimized circular buffer.
Size m_min_capacity;
public:
//! Constructor.
capacity_control(Size buffer_capacity, Size min_buffer_capacity = 0)
: m_capacity(buffer_capacity), m_min_capacity(min_buffer_capacity) {
BOOST_CB_ASSERT(buffer_capacity >= min_buffer_capacity); // check for capacity lower than min_capacity
: m_capacity(buffer_capacity), m_min_capacity(min_buffer_capacity)
{ // Check for capacity lower than min_capacity.
BOOST_CB_ASSERT(buffer_capacity >= min_buffer_capacity);
}
// Default copy constructor.
@@ -175,7 +195,7 @@ public:
*/
template <class Buff, class Traits>
struct iterator :
public boost::iterator<
public std::iterator<
std::random_access_iterator_tag,
typename Traits::value_type,
typename Traits::difference_type,
@@ -188,7 +208,7 @@ struct iterator :
// Helper types
//! Base iterator.
typedef boost::iterator<
typedef std::iterator<
std::random_access_iterator_tag,
typename Traits::value_type,
typename Traits::difference_type,
@@ -406,45 +426,49 @@ operator + (typename Traits::difference_type n, const iterator<Buff, Traits>& it
return it + n;
}
#if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) && !defined(BOOST_MSVC_STD_ITERATOR)
//! Iterator category.
template <class Buff, class Traits>
inline std::random_access_iterator_tag iterator_category(const iterator<Buff, Traits>&) {
return std::random_access_iterator_tag();
}
//! The type of the elements stored in the circular buffer.
template <class Buff, class Traits>
inline typename Traits::value_type* value_type(const iterator<Buff, Traits>&) { return 0; }
//! Distance type.
template <class Buff, class Traits>
inline typename Traits::difference_type* distance_type(const iterator<Buff, Traits>&) { return 0; }
#endif // #if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) && !defined(BOOST_MSVC_STD_ITERATOR)
/*!
\fn ForwardIterator uninitialized_copy_with_alloc(InputIterator first, InputIterator last, ForwardIterator dest,
Alloc& alloc)
\brief Equivalent of <code>std::uninitialized_copy</code> with allocator.
\fn ForwardIterator uninitialized_copy(InputIterator first, InputIterator last, ForwardIterator dest)
\brief Equivalent of <code>std::uninitialized_copy</code> but with explicit specification of value type.
*/
template<class InputIterator, class ForwardIterator, class Alloc>
inline ForwardIterator uninitialized_copy_with_alloc(InputIterator first, InputIterator last, ForwardIterator dest,
Alloc& alloc) {
inline ForwardIterator uninitialized_copy(InputIterator first, InputIterator last, ForwardIterator dest, Alloc& a) {
ForwardIterator next = dest;
BOOST_TRY {
for (; first != last; ++first, ++dest)
alloc.construct(dest, *first);
boost::container::allocator_traits<Alloc>::construct(a, boost::addressof(*dest), *first);
} BOOST_CATCH(...) {
for (; next != dest; ++next)
alloc.destroy(next);
boost::container::allocator_traits<Alloc>::destroy(a, boost::addressof(*next));
BOOST_RETHROW
}
BOOST_CATCH_END
return dest;
}
template<class InputIterator, class ForwardIterator, class Alloc>
ForwardIterator uninitialized_move_if_noexcept_impl(InputIterator first, InputIterator last, ForwardIterator dest, Alloc& a,
true_type) {
for (; first != last; ++first, ++dest)
boost::container::allocator_traits<Alloc>::construct(a, boost::addressof(*dest), boost::move(*first));
return dest;
}
template<class InputIterator, class ForwardIterator, class Alloc>
ForwardIterator uninitialized_move_if_noexcept_impl(InputIterator first, InputIterator last, ForwardIterator dest, Alloc& a,
false_type) {
return uninitialized_copy(first, last, dest, a);
}
/*!
\fn ForwardIterator uninitialized_move_if_noexcept(InputIterator first, InputIterator last, ForwardIterator dest)
\brief Equivalent of <code>std::uninitialized_copy</code> but with explicit specification of value type and moves elements if they have noexcept move constructors.
*/
template<class InputIterator, class ForwardIterator, class Alloc>
ForwardIterator uninitialized_move_if_noexcept(InputIterator first, InputIterator last, ForwardIterator dest, Alloc& a) {
typedef typename boost::is_nothrow_move_constructible<typename boost::container::allocator_traits<Alloc>::value_type>::type tag_t;
return uninitialized_move_if_noexcept_impl(first, last, dest, a, tag_t());
}
/*!
\fn void uninitialized_fill_n_with_alloc(ForwardIterator first, Diff n, const T& item, Alloc& alloc)
\brief Equivalent of <code>std::uninitialized_fill_n</code> with allocator.
@@ -454,10 +478,10 @@ inline void uninitialized_fill_n_with_alloc(ForwardIterator first, Diff n, const
ForwardIterator next = first;
BOOST_TRY {
for (; n > 0; ++first, --n)
alloc.construct(first, item);
boost::container::allocator_traits<Alloc>::construct(alloc, boost::addressof(*first), item);
} BOOST_CATCH(...) {
for (; next != first; ++next)
alloc.destroy(next);
boost::container::allocator_traits<Alloc>::destroy(alloc, boost::addressof(*next));
BOOST_RETHROW
}
BOOST_CATCH_END
@@ -467,4 +491,8 @@ inline void uninitialized_fill_n_with_alloc(ForwardIterator first, Diff n, const
} // namespace boost
#if defined(_MSC_VER)
# pragma warning(pop)
#endif
#endif // #if !defined(BOOST_CIRCULAR_BUFFER_DETAILS_HPP)

View File

@@ -1,6 +1,8 @@
// Implementation of the circular buffer adaptor.
// Copyright (c) 2003-2008 Jan Gaspar
// Copyright (c) 2013 Paul A. Bristow // Doxygen comments changed for new version of documentation.
// Copyright (c) 2013 Antony Polukhin // Move semantics implementation.
// Use, modification, and distribution is subject to the Boost Software
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
@@ -9,7 +11,7 @@
#if !defined(BOOST_CIRCULAR_BUFFER_SPACE_OPTIMIZED_HPP)
#define BOOST_CIRCULAR_BUFFER_SPACE_OPTIMIZED_HPP
#if defined(_MSC_VER) && _MSC_VER >= 1200
#if defined(_MSC_VER)
#pragma once
#endif
@@ -20,10 +22,9 @@ namespace boost {
/*!
\class circular_buffer_space_optimized
\brief Space optimized circular buffer container adaptor.
For detailed documentation of the space_optimized_circular_buffer visit:
http://www.boost.org/libs/circular_buffer/doc/space_optimized.html
\brief Space optimized circular buffer container adaptor.
<code>T</code> must be a copyable class or must have an noexcept move constructor
and move assignment operator.
*/
template <class T, class Alloc>
class circular_buffer_space_optimized :
@@ -51,29 +52,53 @@ public:
typedef typename circular_buffer<T, Alloc>::array_range array_range;
typedef typename circular_buffer<T, Alloc>::const_array_range const_array_range;
typedef typename circular_buffer<T, Alloc>::param_value_type param_value_type;
typedef typename circular_buffer<T, Alloc>::return_value_type return_value_type;
typedef typename circular_buffer<T, Alloc>::rvalue_type rvalue_type;
//typedef typename circular_buffer<T, Alloc>::return_value_type return_value_type;
//! Capacity controller of the space optimized circular buffer.
/*!
<p><pre>
class capacity_control {
size_type m_capacity;
size_type m_min_capacity;
public:
capacity_control(size_type capacity, size_type min_capacity = 0) : m_capacity(capacity), m_min_capacity(min_capacity) {};
size_type %capacity() const { return m_capacity; }
size_type min_capacity() const { return m_min_capacity; }
operator size_type() const { return m_capacity; }
};</pre></p>
\pre <code>capacity >= min_capacity</code>
<p>The <code>capacity()</code> represents the capacity of the <code>circular_buffer_space_optimized</code> and
the <code>min_capacity()</code> determines the minimal allocated size of its internal buffer.</p>
<p>The converting constructor of the <code>capacity_control</code> allows implicit conversion from
<code>size_type</code>-like types which ensures compatibility of creating an instance of the
<code>circular_buffer_space_optimized</code> with other STL containers. On the other hand the operator
<code>%size_type()</code> provides implicit conversion to the <code>size_type</code> which allows to treat the
capacity of the <code>circular_buffer_space_optimized</code> the same way as in the
<code><a href="circular_buffer.html">circular_buffer</a></code>.</p>
/* <pre> is not passed through to html or pdf. So <br> is used in code section below. Ugly :-(
Ideally want a link to capacity_control, but this would require include details
and this would expose all the functions in details.
There must be a better way of doing this.
*/
/*! Capacity controller of the space optimized circular buffer.
\see capacity_control in details.hpp.
<p>
<code>
class capacity_control<br>
{<br>
size_type m_capacity; // Available capacity.<br>
size_type m_min_capacity; // Minimum capacity.<br>
public:<br>
capacity_control(size_type capacity, size_type min_capacity = 0)<br>
: m_capacity(capacity), m_min_capacity(min_capacity)<br>
{};<br>
size_type %capacity() const { return m_capacity; }<br>
size_type min_capacity() const { return m_min_capacity; }<br>
operator size_type() const { return m_capacity; }<br>
};<br>
</code>
</p>
<p>Always
<code>capacity >= min_capacity</code>.
</p>
<p>
The <code>capacity()</code> represents the capacity
of the <code>circular_buffer_space_optimized</code> and
the <code>min_capacity()</code> determines the minimal allocated size of its internal buffer.
</p>
<p>The converting constructor of the <code>capacity_control</code> allows implicit conversion from
<code>size_type</code>-like types which ensures compatibility of creating an instance of the
<code>circular_buffer_space_optimized</code> with other STL containers.
On the other hand the operator <code>%size_type()</code>
provides implicit conversion to the <code>size_type</code> which allows to treat the
capacity of the <code>circular_buffer_space_optimized</code> the same way as in the
<code>circular_buffer</a></code>.
</p>
*/
typedef cb_details::capacity_control<size_type> capacity_type;
@@ -98,7 +123,7 @@ public:
#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
reference operator [] (size_type n) { return circular_buffer<T, Alloc>::operator[](n); }
return_value_type operator [] (size_type n) const { return circular_buffer<T, Alloc>::operator[](n); }
const_reference operator [] (size_type n) const { return circular_buffer<T, Alloc>::operator[](n); }
#else
using circular_buffer<T, Alloc>::operator[];
#endif
@@ -125,7 +150,7 @@ public:
Constant (in the size of the <code>circular_buffer_space_optimized</code>).
\sa <code>empty()</code>
*/
bool full() const { return m_capacity_ctrl == size(); }
bool full() const BOOST_NOEXCEPT { return m_capacity_ctrl == size(); }
/*! \brief Get the maximum number of elements which can be inserted into the
<code>circular_buffer_space_optimized</code> without overwriting any of already stored elements.
@@ -139,7 +164,7 @@ public:
Constant (in the size of the <code>circular_buffer_space_optimized</code>).
\sa <code>capacity()</code>, <code>size()</code>, <code>max_size()</code>
*/
size_type reserve() const { return m_capacity_ctrl - size(); }
size_type reserve() const BOOST_NOEXCEPT { return m_capacity_ctrl - size(); }
//! Get the capacity of the <code>circular_buffer_space_optimized</code>.
/*!
@@ -155,7 +180,7 @@ public:
\sa <code>reserve()</code>, <code>size()</code>, <code>max_size()</code>,
<code>set_capacity(const capacity_type&)</code>
*/
const capacity_type& capacity() const { return m_capacity_ctrl; }
const capacity_type& capacity() const BOOST_NOEXCEPT { return m_capacity_ctrl; }
#if defined(BOOST_CB_TEST)
@@ -164,7 +189,7 @@ public:
\note This method is not intended to be used directly by the user.
It is defined only for testing purposes.
*/
size_type internal_capacity() const { return circular_buffer<T, Alloc>::capacity(); }
size_type internal_capacity() const BOOST_NOEXCEPT { return circular_buffer<T, Alloc>::capacity(); }
#endif // #if defined(BOOST_CB_TEST)
@@ -178,9 +203,9 @@ public:
than the new capacity then the amount of allocated memory in the internal buffer may be accommodated as
necessary but it will never drop below <code>capacity_ctrl.min_capacity()</code>.
\param capacity_ctrl The new capacity controller.
\throws "An allocation error" if memory is exhausted (<code>std::bad_alloc</code> if the standard allocator is
\throws "An allocation error" if memory is exhausted, (<code>std::bad_alloc</code> if the standard allocator is
used).
\throws Whatever <code>T::T(const T&)</code> throws.
Whatever <code>T::T(const T&)</code> throws or nothing if <code>T::T(T&&)</code> is noexcept.
\par Exception Safety
Strong.
\par Iterator Invalidation
@@ -189,9 +214,9 @@ public:
\par Complexity
Linear (in <code>min[size(), capacity_ctrl.%capacity()]</code>).
\note To explicitly clear the extra allocated memory use the <b>shrink-to-fit</b> technique:<br><br>
<code>boost::%circular_buffer_space_optimized\<int\> cb(1000);<br>
<code>%boost::%circular_buffer_space_optimized\<int\> cb(1000);<br>
...<br>
boost::%circular_buffer_space_optimized\<int\>(cb).swap(cb);</code><br><br>
%boost::%circular_buffer_space_optimized\<int\>(cb).swap(cb);</code><br><br>
For more information about the shrink-to-fit technique in STL see
<a href="http://www.gotw.ca/gotw/054.htm">http://www.gotw.ca/gotw/054.htm</a>.
\sa <code>rset_capacity(const capacity_type&)</code>,
@@ -222,7 +247,7 @@ public:
the requested size. (See the <i>Effect</i>.)
\throws "An allocation error" if memory is exhausted (<code>std::bad_alloc</code> if the standard allocator is
used).
\throws Whatever <code>T::T(const T&)</code> throws.
Whatever <code>T::T(const T&)</code> throws.
\par Exception Safety
Basic.
\par Iterator Invalidation
@@ -257,7 +282,7 @@ public:
\param capacity_ctrl The new capacity controller.
\throws "An allocation error" if memory is exhausted (<code>std::bad_alloc</code> if the standard allocator is
used).
\throws Whatever <code>T::T(const T&)</code> throws.
Whatever <code>T::T(const T&)</code> throws or nothing if <code>T::T(T&&)</code> is noexcept.
\par Exception Safety
Strong.
\par Iterator Invalidation
@@ -293,7 +318,7 @@ public:
the requested size. (See the <i>Effect</i>.)
\throws "An allocation error" if memory is exhausted (<code>std::bad_alloc</code> if the standard allocator is
used).
\throws Whatever <code>T::T(const T&)</code> throws.
Whatever <code>T::T(const T&)</code> throws.
\par Exception Safety
Basic.
\par Iterator Invalidation
@@ -324,7 +349,7 @@ public:
\warning Since Boost version 1.36 the behaviour of this constructor has changed. Now it creates a space
optimized circular buffer with zero capacity.
*/
explicit circular_buffer_space_optimized(const allocator_type& alloc = allocator_type())
explicit circular_buffer_space_optimized(const allocator_type& alloc = allocator_type()) BOOST_NOEXCEPT
: circular_buffer<T, Alloc>(0, alloc)
, m_capacity_ctrl(0) {}
@@ -382,7 +407,7 @@ public:
\param alloc The allocator.
\throws "An allocation error" if memory is exhausted (<code>std::bad_alloc</code> if the standard allocator is
used).
\throws Whatever <code>T::T(const T&)</code> throws.
Whatever <code>T::T(const T&)</code> throws.
\par Complexity
Linear (in the <code>n</code>).
*/
@@ -391,31 +416,6 @@ public:
: circular_buffer<T, Alloc>(init_capacity(capacity_ctrl, n), n, item, alloc)
, m_capacity_ctrl(capacity_ctrl) {}
#if BOOST_WORKAROUND(BOOST_MSVC, < 1300)
/*! \cond */
circular_buffer_space_optimized(const circular_buffer_space_optimized<T, Alloc>& cb)
: circular_buffer<T, Alloc>(cb.begin(), cb.end())
, m_capacity_ctrl(cb.m_capacity_ctrl) {}
template <class InputIterator>
circular_buffer_space_optimized(InputIterator first, InputIterator last)
: circular_buffer<T, Alloc>(first, last)
, m_capacity_ctrl(circular_buffer<T, Alloc>::capacity()) {}
template <class InputIterator>
circular_buffer_space_optimized(capacity_type capacity_ctrl, InputIterator first, InputIterator last)
: circular_buffer<T, Alloc>(
init_capacity(capacity_ctrl, first, last, is_integral<InputIterator>()),
first, last)
, m_capacity_ctrl(capacity_ctrl) {
reduce_capacity(
is_same< BOOST_DEDUCED_TYPENAME BOOST_ITERATOR_CATEGORY<InputIterator>::type, std::input_iterator_tag >());
}
/*! \endcond */
#else
//! The copy constructor.
/*!
Creates a copy of the specified <code>circular_buffer_space_optimized</code>.
@@ -424,7 +424,7 @@ public:
\param cb The <code>circular_buffer_space_optimized</code> to be copied.
\throws "An allocation error" if memory is exhausted (<code>std::bad_alloc</code> if the standard allocator is
used).
\throws Whatever <code>T::T(const T&)</code> throws.
Whatever <code>T::T(const T&)</code> throws.
\par Complexity
Linear (in the size of <code>cb</code>).
*/
@@ -432,6 +432,23 @@ public:
: circular_buffer<T, Alloc>(cb.begin(), cb.end(), cb.get_allocator())
, m_capacity_ctrl(cb.m_capacity_ctrl) {}
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
//! The move constructor.
/*! \brief Move constructs a <code>circular_buffer_space_optimized</code> from <code>cb</code>,
leaving <code>cb</code> empty.
\pre C++ compiler with rvalue references support.
\post <code>cb.empty()</code>
\param cb <code>circular_buffer</code> to 'steal' value from.
\throws Nothing.
\par Constant.
*/
circular_buffer_space_optimized(circular_buffer_space_optimized<T, Alloc>&& cb) BOOST_NOEXCEPT
: circular_buffer<T, Alloc>()
, m_capacity_ctrl(0) {
cb.swap(*this);
}
#endif // BOOST_NO_CXX11_RVALUE_REFERENCES
//! Create a full space optimized circular buffer filled with a copy of the range.
/*!
\pre Valid range <code>[first, last)</code>.<br>
@@ -446,7 +463,8 @@ public:
\param alloc The allocator.
\throws "An allocation error" if memory is exhausted (<code>std::bad_alloc</code> if the standard allocator is
used).
\throws Whatever <code>T::T(const T&)</code> throws.
Whatever <code>T::T(const T&)</code> throws or nothing if <code>T::T(T&&)</code> is noexcept
and <code>InputIterator</code> is a move iterator.
\par Complexity
Linear (in the <code>std::distance(first, last)</code>).
*/
@@ -477,7 +495,7 @@ public:
\param alloc The allocator.
\throws "An allocation error" if memory is exhausted (<code>std::bad_alloc</code> if the standard allocator is
used).
\throws Whatever <code>T::T(const T&)</code> throws.
Whatever <code>T::T(const T&)</code> throws.
\par Complexity
Linear (in <code>std::distance(first, last)</code>; in
<code>min[capacity_ctrl.%capacity(), std::distance(first, last)]</code> if the <code>InputIterator</code>
@@ -491,11 +509,9 @@ public:
first, last, alloc)
, m_capacity_ctrl(capacity_ctrl) {
reduce_capacity(
is_same< BOOST_DEDUCED_TYPENAME BOOST_ITERATOR_CATEGORY<InputIterator>::type, std::input_iterator_tag >());
is_same< BOOST_DEDUCED_TYPENAME iterator_category<InputIterator>::type, std::input_iterator_tag >());
}
#endif // #if BOOST_WORKAROUND(BOOST_MSVC, < 1300)
#if defined(BOOST_CB_NEVER_DEFINED)
// This section will never be compiled - the default destructor will be generated instead.
// Declared only for documentation purpose.
@@ -513,6 +529,12 @@ public:
*/
~circular_buffer_space_optimized();
//! no-comment
void erase_begin(size_type n);
//! no-comment
void erase_end(size_type n);
#endif // #if defined(BOOST_CB_NEVER_DEFINED)
//! The assign operator.
@@ -546,6 +568,24 @@ public:
return *this;
}
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
/*! \brief Move assigns content of <code>cb</code> to <code>*this</code>, leaving <code>cb</code> empty.
\pre C++ compiler with rvalue references support.
\post <code>cb.empty()</code>
\param cb <code>circular_buffer</code> to 'steal' value from.
\throws Nothing.
\par Complexity
Constant.
*/
circular_buffer_space_optimized<T, Alloc>& operator = (circular_buffer_space_optimized<T, Alloc>&& cb) BOOST_NOEXCEPT {
cb.swap(*this); // now `this` holds `cb`
circular_buffer<T, Alloc>(get_allocator()) // temprary that holds initial `cb` allocator
.swap(cb); // makes `cb` empty
return *this;
}
#endif // BOOST_NO_CXX11_RVALUE_REFERENCES
//! Assign <code>n</code> items into the space optimized circular buffer.
/*!
The content of the <code>circular_buffer_space_optimized</code> will be removed and replaced with
@@ -557,7 +597,7 @@ public:
\param item The element the <code>circular_buffer_space_optimized</code> will be filled with.
\throws "An allocation error" if memory is exhausted (<code>std::bad_alloc</code> if the standard allocator is
used).
\throws Whatever <code>T::T(const T&)</code> throws.
Whatever <code>T::T(const T&)</code> throws.
\par Exception Safety
Basic.
\par Iterator Invalidation
@@ -565,7 +605,8 @@ public:
equal to <code>end()</code>).
\par Complexity
Linear (in the <code>n</code>).
\sa <code>operator=</code>, <code>\link assign(capacity_type, size_type, param_value_type)
\sa <code>\link operator=(const circular_buffer_space_optimized&) operator=\endlink</code>,
<code>\link assign(capacity_type, size_type, param_value_type)
assign(capacity_type, size_type, const_reference)\endlink</code>,
<code>assign(InputIterator, InputIterator)</code>,
<code>assign(capacity_type, InputIterator, InputIterator)</code>
@@ -589,7 +630,7 @@ public:
\param item The element the <code>circular_buffer_space_optimized</code> will be filled with.
\throws "An allocation error" if memory is exhausted (<code>std::bad_alloc</code> if the standard allocator is
used).
\throws Whatever <code>T::T(const T&)</code> throws.
Whatever <code>T::T(const T&)</code> throws.
\par Exception Safety
Basic.
\par Iterator Invalidation
@@ -597,8 +638,9 @@ public:
equal to <code>end()</code>).
\par Complexity
Linear (in the <code>n</code>).
\sa <code>operator=</code>, <code>\link assign(size_type, param_value_type)
assign(size_type, const_reference)\endlink</code>, <code>assign(InputIterator, InputIterator)</code>,
\sa <code>\link operator=(const circular_buffer_space_optimized&) operator=\endlink</code>,
<code>\link assign(size_type, param_value_type) assign(size_type, const_reference)\endlink</code>,
<code>assign(InputIterator, InputIterator)</code>,
<code>assign(capacity_type, InputIterator, InputIterator)</code>
*/
void assign(capacity_type capacity_ctrl, size_type n, param_value_type item) {
@@ -622,7 +664,8 @@ public:
\param last The end of the range to be copied.
\throws "An allocation error" if memory is exhausted (<code>std::bad_alloc</code> if the standard allocator is
used).
\throws Whatever <code>T::T(const T&)</code> throws.
Whatever <code>T::T(const T&)</code> throws or nothing if <code>T::T(T&&)</code> is noexcept and
<code>InputIterator</code> is a move iterator.
\par Exception Safety
Basic.
\par Iterator Invalidation
@@ -630,8 +673,8 @@ public:
equal to <code>end()</code>).
\par Complexity
Linear (in the <code>std::distance(first, last)</code>).
\sa <code>operator=</code>, <code>\link assign(size_type, param_value_type)
assign(size_type, const_reference)\endlink</code>,
\sa <code>\link operator=(const circular_buffer_space_optimized&) operator=\endlink</code>,
<code>\link assign(size_type, param_value_type) assign(size_type, const_reference)\endlink</code>,
<code>\link assign(capacity_type, size_type, param_value_type)
assign(capacity_type, size_type, const_reference)\endlink</code>,
<code>assign(capacity_type, InputIterator, InputIterator)</code>
@@ -662,7 +705,8 @@ public:
\param last The end of the range to be copied.
\throws "An allocation error" if memory is exhausted (<code>std::bad_alloc</code> if the standard allocator is
used).
\throws Whatever <code>T::T(const T&)</code> throws.
Whatever <code>T::T(const T&)</code> throws or nothing if <code>T::T(T&&)</code> is noexcept and
<code>InputIterator</code> is a move iterator.
\par Exception Safety
Basic.
\par Iterator Invalidation
@@ -672,8 +716,8 @@ public:
Linear (in <code>std::distance(first, last)</code>; in
<code>min[capacity_ctrl.%capacity(), std::distance(first, last)]</code> if the <code>InputIterator</code>
is a <a href="http://www.sgi.com/tech/stl/RandomAccessIterator.html">RandomAccessIterator</a>).
\sa <code>operator=</code>, <code>\link assign(size_type, param_value_type)
assign(size_type, const_reference)\endlink</code>,
\sa <code>\link operator=(const circular_buffer_space_optimized&) operator=\endlink</code>,
<code>\link assign(size_type, param_value_type) assign(size_type, const_reference)\endlink</code>,
<code>\link assign(capacity_type, size_type, param_value_type)
assign(capacity_type, size_type, const_reference)\endlink</code>,
<code>assign(InputIterator, InputIterator)</code>
@@ -684,7 +728,7 @@ public:
circular_buffer<T, Alloc>::assign(capacity_ctrl, first, last);
}
//! Swap the contents of two space optimized circular buffers.
//! Swap the contents of two space-optimized circular-buffers.
/*!
\post <code>this</code> contains elements of <code>cb</code> and vice versa; the capacity and the amount of
allocated memory in the internal buffer of <code>this</code> equal to the capacity and the amount of
@@ -696,14 +740,18 @@ public:
\par Iterator Invalidation
Invalidates all iterators of both <code>circular_buffer_space_optimized</code> containers. (On the other
hand the iterators still point to the same elements but within another container. If you want to rely on
this feature you have to turn the <a href="circular_buffer.html#debug">Debug Support</a> off otherwise an
assertion will report an error if such invalidated iterator is used.)
this feature you have to turn the __debug_support off,
otherwise an assertion will report an error if such invalidated iterator is used.)
\par Complexity
Constant (in the size of the <code>circular_buffer_space_optimized</code>).
\sa <code>\link swap(circular_buffer<T, Alloc>&, circular_buffer<T, Alloc>&)
swap(circular_buffer_space_optimized<T, Alloc>&, circular_buffer_space_optimized<T, Alloc>&)\endlink</code>
\sa <code>swap(circular_buffer<T, Alloc>&, circular_buffer<T, Alloc>&)</code>,
<code>swap(circular_buffer_space_optimized<T, Alloc>&, circular_buffer_space_optimized<T, Alloc>&)</code>
*/
void swap(circular_buffer_space_optimized<T, Alloc>& cb) {
// Note link does not work right. Asked on Doxygen forum for advice 23 May 2103.
void swap(circular_buffer_space_optimized<T, Alloc>& cb) BOOST_NOEXCEPT {
std::swap(m_capacity_ctrl, cb.m_capacity_ctrl);
circular_buffer<T, Alloc>::swap(cb);
}
@@ -717,7 +765,7 @@ public:
\param item The element to be inserted.
\throws "An allocation error" if memory is exhausted (<code>std::bad_alloc</code> if the standard allocator is
used).
\throws Whatever <code>T::T(const T&)</code> throws.
Whatever <code>T::T(const T&)</code> throws.
\par Exception Safety
Basic.
\par Iterator Invalidation
@@ -728,11 +776,60 @@ public:
\sa <code>\link push_front() push_front(const_reference)\endlink</code>, <code>pop_back()</code>,
<code>pop_front()</code>
*/
void push_back(param_value_type item = value_type()) {
void push_back(param_value_type item) {
check_low_capacity();
circular_buffer<T, Alloc>::push_back(item);
}
//! Insert a new element at the end of the space optimized circular buffer.
/*!
\post if <code>capacity().%capacity() > 0</code> then <code>back() == item</code><br>
If the <code>circular_buffer_space_optimized</code> is full, the first element will be removed. If the
capacity is <code>0</code>, nothing will be inserted.<br><br>
The amount of allocated memory in the internal buffer may be predictively increased.
\param item The element to be inserted.
\throws "An allocation error" if memory is exhausted (<code>std::bad_alloc</code> if the standard allocator is
used).
\par Exception Safety
Basic.
\par Iterator Invalidation
Invalidates all iterators pointing to the <code>circular_buffer_space_optimized</code> (except iterators
equal to <code>end()</code>).
\par Complexity
Linear (in the size of the <code>circular_buffer_space_optimized</code>).
\sa <code>\link push_front() push_front(const_reference)\endlink</code>, <code>pop_back()</code>,
<code>pop_front()</code>
*/
void push_back(rvalue_type item) {
check_low_capacity();
circular_buffer<T, Alloc>::push_back(boost::move(item));
}
//! Insert a new element at the end of the space optimized circular buffer.
/*!
\post if <code>capacity().%capacity() > 0</code> then <code>back() == item</code><br>
If the <code>circular_buffer_space_optimized</code> is full, the first element will be removed. If the
capacity is <code>0</code>, nothing will be inserted.<br><br>
The amount of allocated memory in the internal buffer may be predictively increased.
\throws "An allocation error" if memory is exhausted (<code>std::bad_alloc</code> if the standard allocator is
used).
Whatever <code>T::T()</code> throws.
Whatever <code>T::T(const T&)</code> throws or nothing if <code>T::T(T&&)</code> is noexcept.
\par Exception Safety
Basic.
\par Iterator Invalidation
Invalidates all iterators pointing to the <code>circular_buffer_space_optimized</code> (except iterators
equal to <code>end()</code>).
\par Complexity
Linear (in the size of the <code>circular_buffer_space_optimized</code>).
\sa <code>\link push_front() push_front(const_reference)\endlink</code>, <code>pop_back()</code>,
<code>pop_front()</code>
*/
void push_back() {
check_low_capacity();
circular_buffer<T, Alloc>::push_back();
}
//! Insert a new element at the beginning of the space optimized circular buffer.
/*!
\post if <code>capacity().%capacity() > 0</code> then <code>front() == item</code><br>
@@ -742,7 +839,7 @@ public:
\param item The element to be inserted.
\throws "An allocation error" if memory is exhausted (<code>std::bad_alloc</code> if the standard allocator is
used).
\throws Whatever <code>T::T(const T&)</code> throws.
Whatever <code>T::T(const T&)</code> throws.
\par Exception Safety
Basic.
\par Iterator Invalidation
@@ -753,11 +850,61 @@ public:
\sa <code>\link push_back() push_back(const_reference)\endlink</code>, <code>pop_back()</code>,
<code>pop_front()</code>
*/
void push_front(param_value_type item = value_type()) {
void push_front(param_value_type item) {
check_low_capacity();
circular_buffer<T, Alloc>::push_front(item);
}
//! Insert a new element at the beginning of the space optimized circular buffer.
/*!
\post if <code>capacity().%capacity() > 0</code> then <code>front() == item</code><br>
If the <code>circular_buffer_space_optimized</code> is full, the last element will be removed. If the
capacity is <code>0</code>, nothing will be inserted.<br><br>
The amount of allocated memory in the internal buffer may be predictively increased.
\param item The element to be inserted.
\throws "An allocation error" if memory is exhausted (<code>std::bad_alloc</code> if the standard allocator is
used).
Whatever <code>T::T(const T&)</code> throws or nothing if <code>T::T(T&&)</code> is noexcept.
\par Exception Safety
Basic.
\par Iterator Invalidation
Invalidates all iterators pointing to the <code>circular_buffer_space_optimized</code> (except iterators
equal to <code>end()</code>).
\par Complexity
Linear (in the size of the <code>circular_buffer_space_optimized</code>).
\sa <code>\link push_back() push_back(const_reference)\endlink</code>, <code>pop_back()</code>,
<code>pop_front()</code>
*/
void push_front(rvalue_type item) {
check_low_capacity();
circular_buffer<T, Alloc>::push_front(boost::move(item));
}
//! Insert a new element at the beginning of the space optimized circular buffer.
/*!
\post if <code>capacity().%capacity() > 0</code> then <code>front() == item</code><br>
If the <code>circular_buffer_space_optimized</code> is full, the last element will be removed. If the
capacity is <code>0</code>, nothing will be inserted.<br><br>
The amount of allocated memory in the internal buffer may be predictively increased.
\throws "An allocation error" if memory is exhausted (<code>std::bad_alloc</code> if the standard allocator is
used).
Whatever <code>T::T()</code> throws.
Whatever <code>T::T(const T&)</code> throws or nothing if <code>T::T(T&&)</code> is noexcept.
\par Exception Safety
Basic.
\par Iterator Invalidation
Invalidates all iterators pointing to the <code>circular_buffer_space_optimized</code> (except iterators
equal to <code>end()</code>).
\par Complexity
Linear (in the size of the <code>circular_buffer_space_optimized</code>).
\sa <code>\link push_back() push_back(const_reference)\endlink</code>, <code>pop_back()</code>,
<code>pop_front()</code>
*/
void push_front() {
check_low_capacity();
circular_buffer<T, Alloc>::push_front();
}
//! Remove the last element from the space optimized circular buffer.
/*!
\pre <code>!empty()</code>
@@ -818,8 +965,8 @@ public:
the <i>Effect</i>.)
\throws "An allocation error" if memory is exhausted (<code>std::bad_alloc</code> if the standard allocator is
used).
\throws Whatever <code>T::T(const T&)</code> throws.
\throws Whatever <code>T::operator = (const T&)</code> throws.
Whatever <code>T::T(const T&)</code> throws.
Whatever <code>T::operator = (const T&)</code> throws.
\par Exception Safety
Basic.
\par Iterator Invalidation
@@ -835,12 +982,88 @@ public:
rinsert(iterator, size_type, value_type)\endlink</code>,
<code>rinsert(iterator, InputIterator, InputIterator)</code>
*/
iterator insert(iterator pos, param_value_type item = value_type()) {
iterator insert(iterator pos, param_value_type item) {
size_type index = pos - begin();
check_low_capacity();
return circular_buffer<T, Alloc>::insert(begin() + index, item);
}
//! Insert an element at the specified position.
/*!
\pre <code>pos</code> is a valid iterator pointing to the <code>circular_buffer_space_optimized</code> or its
end.
\post The <code>item</code> will be inserted at the position <code>pos</code>.<br>
If the <code>circular_buffer_space_optimized</code> is full, the first element will be overwritten. If
the <code>circular_buffer_space_optimized</code> is full and the <code>pos</code> points to
<code>begin()</code>, then the <code>item</code> will not be inserted. If the capacity is <code>0</code>,
nothing will be inserted.<br><br>
The amount of allocated memory in the internal buffer may be predictively increased.
\param pos An iterator specifying the position where the <code>item</code> will be inserted.
\param item The element to be inserted.
\return Iterator to the inserted element or <code>begin()</code> if the <code>item</code> is not inserted. (See
the <i>Effect</i>.)
\throws "An allocation error" if memory is exhausted (<code>std::bad_alloc</code> if the standard allocator is
used).
Whatever <code>T::T(const T&)</code> throws or nothing if <code>T::T(T&&)</code> is noexcept.
\par Exception Safety
Basic.
\par Iterator Invalidation
Invalidates all iterators pointing to the <code>circular_buffer_space_optimized</code> (except iterators
equal to <code>end()</code>).
\par Complexity
Linear (in the size of the <code>circular_buffer_space_optimized</code>).
\sa <code>\link insert(iterator, size_type, param_value_type)
insert(iterator, size_type, value_type)\endlink</code>,
<code>insert(iterator, InputIterator, InputIterator)</code>,
<code>\link rinsert(iterator, param_value_type) rinsert(iterator, value_type)\endlink</code>,
<code>\link rinsert(iterator, size_type, param_value_type)
rinsert(iterator, size_type, value_type)\endlink</code>,
<code>rinsert(iterator, InputIterator, InputIterator)</code>
*/
iterator insert(iterator pos, rvalue_type item) {
size_type index = pos - begin();
check_low_capacity();
return circular_buffer<T, Alloc>::insert(begin() + index, boost::move(item));
}
//! Insert an element at the specified position.
/*!
\pre <code>pos</code> is a valid iterator pointing to the <code>circular_buffer_space_optimized</code> or its
end.
\post The <code>item</code> will be inserted at the position <code>pos</code>.<br>
If the <code>circular_buffer_space_optimized</code> is full, the first element will be overwritten. If
the <code>circular_buffer_space_optimized</code> is full and the <code>pos</code> points to
<code>begin()</code>, then the <code>item</code> will not be inserted. If the capacity is <code>0</code>,
nothing will be inserted.<br><br>
The amount of allocated memory in the internal buffer may be predictively increased.
\param pos An iterator specifying the position where the <code>item</code> will be inserted.
\return Iterator to the inserted element or <code>begin()</code> if the <code>item</code> is not inserted. (See
the <i>Effect</i>.)
\throws "An allocation error" if memory is exhausted (<code>std::bad_alloc</code> if the standard allocator is
used).
Whatever <code>T::T()</code> throws.
Whatever <code>T::T(const T&)</code> throws or nothing if <code>T::T(T&&)</code> is noexcept.
\par Exception Safety
Basic.
\par Iterator Invalidation
Invalidates all iterators pointing to the <code>circular_buffer_space_optimized</code> (except iterators
equal to <code>end()</code>).
\par Complexity
Linear (in the size of the <code>circular_buffer_space_optimized</code>).
\sa <code>\link insert(iterator, size_type, param_value_type)
insert(iterator, size_type, value_type)\endlink</code>,
<code>insert(iterator, InputIterator, InputIterator)</code>,
<code>\link rinsert(iterator, param_value_type) rinsert(iterator, value_type)\endlink</code>,
<code>\link rinsert(iterator, size_type, param_value_type)
rinsert(iterator, size_type, value_type)\endlink</code>,
<code>rinsert(iterator, InputIterator, InputIterator)</code>
*/
iterator insert(iterator pos) {
size_type index = pos - begin();
check_low_capacity();
return circular_buffer<T, Alloc>::insert(begin() + index);
}
//! Insert <code>n</code> copies of the <code>item</code> at the specified position.
/*!
\pre <code>pos</code> is a valid iterator pointing to the <code>circular_buffer_space_optimized</code> or its
@@ -855,8 +1078,8 @@ public:
\param item The element whose copies will be inserted.
\throws "An allocation error" if memory is exhausted (<code>std::bad_alloc</code> if the standard allocator is
used).
\throws Whatever <code>T::T(const T&)</code> throws.
\throws Whatever <code>T::operator = (const T&)</code> throws.
Whatever <code>T::T(const T&)</code> throws.
Whatever <code>T::operator = (const T&)</code> throws.
\par Exception Safety
Basic.
\par Iterator Invalidation
@@ -868,7 +1091,7 @@ public:
Consider a <code>circular_buffer_space_optimized</code> with the capacity of 6 and the size of 4. Its
internal buffer may look like the one below.<br><br>
<code>|1|2|3|4| | |</code><br>
<code>p ---^</code><br><br>After inserting 5 elements at the position <code>p</code>:<br><br>
<code>p ___^</code><br><br>After inserting 5 elements at the position <code>p</code>:<br><br>
<code>insert(p, (size_t)5, 0);</code><br><br>actually only 4 elements get inserted and elements
<code>1</code> and <code>2</code> are overwritten. This is due to the fact the insert operation preserves
the capacity. After insertion the internal buffer looks like this:<br><br><code>|0|0|0|0|3|4|</code><br>
@@ -903,8 +1126,7 @@ public:
\param last The end of the range to be inserted.
\throws "An allocation error" if memory is exhausted (<code>std::bad_alloc</code> if the standard allocator is
used).
\throws Whatever <code>T::T(const T&)</code> throws.
\throws Whatever <code>T::operator = (const T&)</code> throws.
Whatever <code>T::T(const T&)</code> throws or nothing if <code>T::T(T&&)</code> is noexcept.
\par Exception Safety
Basic.
\par Iterator Invalidation
@@ -919,7 +1141,7 @@ public:
Consider a <code>circular_buffer_space_optimized</code> with the capacity of 6 and the size of 4. Its
internal buffer may look like the one below.<br><br>
<code>|1|2|3|4| | |</code><br>
<code>p ---^</code><br><br>After inserting a range of elements at the position <code>p</code>:<br><br>
<code>p ___^</code><br><br>After inserting a range of elements at the position <code>p</code>:<br><br>
<code>int array[] = { 5, 6, 7, 8, 9 };</code><br><code>insert(p, array, array + 5);</code><br><br>
actually only elements <code>6</code>, <code>7</code>, <code>8</code> and <code>9</code> from the
specified range get inserted and elements <code>1</code> and <code>2</code> are overwritten. This is due
@@ -954,8 +1176,8 @@ public:
the <i>Effect</i>.)
\throws "An allocation error" if memory is exhausted (<code>std::bad_alloc</code> if the standard allocator is
used).
\throws Whatever <code>T::T(const T&)</code> throws.
\throws Whatever <code>T::operator = (const T&)</code> throws.
Whatever <code>T::T(const T&)</code> throws.
Whatever <code>T::operator = (const T&)</code> throws.
\par Exception Safety
Basic.
\par Iterator Invalidation
@@ -971,12 +1193,88 @@ public:
insert(iterator, size_type, value_type)\endlink</code>,
<code>insert(iterator, InputIterator, InputIterator)</code>
*/
iterator rinsert(iterator pos, param_value_type item = value_type()) {
iterator rinsert(iterator pos, param_value_type item) {
size_type index = pos - begin();
check_low_capacity();
return circular_buffer<T, Alloc>::rinsert(begin() + index, item);
}
//! Insert an element before the specified position.
/*!
\pre <code>pos</code> is a valid iterator pointing to the <code>circular_buffer_space_optimized</code> or its
end.
\post The <code>item</code> will be inserted before the position <code>pos</code>.<br>
If the <code>circular_buffer_space_optimized</code> is full, the last element will be overwritten. If the
<code>circular_buffer_space_optimized</code> is full and the <code>pos</code> points to
<code>end()</code>, then the <code>item</code> will not be inserted. If the capacity is <code>0</code>,
nothing will be inserted.<br><br>
The amount of allocated memory in the internal buffer may be predictively increased.
\param pos An iterator specifying the position before which the <code>item</code> will be inserted.
\param item The element to be inserted.
\return Iterator to the inserted element or <code>end()</code> if the <code>item</code> is not inserted. (See
the <i>Effect</i>.)
\throws "An allocation error" if memory is exhausted (<code>std::bad_alloc</code> if the standard allocator is
used).
Whatever <code>T::T(const T&)</code> throws or nothing if <code>T::T(T&&)</code> is noexcept.
\par Exception Safety
Basic.
\par Iterator Invalidation
Invalidates all iterators pointing to the <code>circular_buffer_space_optimized</code> (except iterators
equal to <code>end()</code>).
\par Complexity
Linear (in the size of the <code>circular_buffer_space_optimized</code>).
\sa <code>\link rinsert(iterator, size_type, param_value_type)
rinsert(iterator, size_type, value_type)\endlink</code>,
<code>rinsert(iterator, InputIterator, InputIterator)</code>,
<code>\link insert(iterator, param_value_type) insert(iterator, value_type)\endlink</code>,
<code>\link insert(iterator, size_type, param_value_type)
insert(iterator, size_type, value_type)\endlink</code>,
<code>insert(iterator, InputIterator, InputIterator)</code>
*/
iterator rinsert(iterator pos, rvalue_type item) {
size_type index = pos - begin();
check_low_capacity();
return circular_buffer<T, Alloc>::rinsert(begin() + index, boost::move(item));
}
//! Insert an element before the specified position.
/*!
\pre <code>pos</code> is a valid iterator pointing to the <code>circular_buffer_space_optimized</code> or its
end.
\post The <code>item</code> will be inserted before the position <code>pos</code>.<br>
If the <code>circular_buffer_space_optimized</code> is full, the last element will be overwritten. If the
<code>circular_buffer_space_optimized</code> is full and the <code>pos</code> points to
<code>end()</code>, then the <code>item</code> will not be inserted. If the capacity is <code>0</code>,
nothing will be inserted.<br><br>
The amount of allocated memory in the internal buffer may be predictively increased.
\param pos An iterator specifying the position before which the <code>item</code> will be inserted.
\return Iterator to the inserted element or <code>end()</code> if the <code>item</code> is not inserted. (See
the <i>Effect</i>.)
\throws "An allocation error" if memory is exhausted (<code>std::bad_alloc</code> if the standard allocator is
used).
Whatever <code>T::T()</code> throws.
Whatever <code>T::T(const T&)</code> throws or nothing if <code>T::T(T&&)</code> is noexcept.
\par Exception Safety
Basic.
\par Iterator Invalidation
Invalidates all iterators pointing to the <code>circular_buffer_space_optimized</code> (except iterators
equal to <code>end()</code>).
\par Complexity
Linear (in the size of the <code>circular_buffer_space_optimized</code>).
\sa <code>\link rinsert(iterator, size_type, param_value_type)
rinsert(iterator, size_type, value_type)\endlink</code>,
<code>rinsert(iterator, InputIterator, InputIterator)</code>,
<code>\link insert(iterator, param_value_type) insert(iterator, value_type)\endlink</code>,
<code>\link insert(iterator, size_type, param_value_type)
insert(iterator, size_type, value_type)\endlink</code>,
<code>insert(iterator, InputIterator, InputIterator)</code>
*/
iterator rinsert(iterator pos) {
size_type index = pos - begin();
check_low_capacity();
return circular_buffer<T, Alloc>::rinsert(begin() + index);
}
//! Insert <code>n</code> copies of the <code>item</code> before the specified position.
/*!
\pre <code>pos</code> is a valid iterator pointing to the <code>circular_buffer_space_optimized</code> or its
@@ -991,8 +1289,8 @@ public:
\param item The element whose copies will be inserted.
\throws "An allocation error" if memory is exhausted (<code>std::bad_alloc</code> if the standard allocator is
used).
\throws Whatever <code>T::T(const T&)</code> throws.
\throws Whatever <code>T::operator = (const T&)</code> throws.
Whatever <code>T::T(const T&)</code> throws.
Whatever <code>T::operator = (const T&)</code> throws.
\par Exception Safety
Basic.
\par Iterator Invalidation
@@ -1004,7 +1302,7 @@ public:
Consider a <code>circular_buffer_space_optimized</code> with the capacity of 6 and the size of 4. Its
internal buffer may look like the one below.<br><br>
<code>|1|2|3|4| | |</code><br>
<code>p ---^</code><br><br>After inserting 5 elements before the position <code>p</code>:<br><br>
<code>p ___^</code><br><br>After inserting 5 elements before the position <code>p</code>:<br><br>
<code>rinsert(p, (size_t)5, 0);</code><br><br>actually only 4 elements get inserted and elements
<code>3</code> and <code>4</code> are overwritten. This is due to the fact the rinsert operation preserves
the capacity. After insertion the internal buffer looks like this:<br><br><code>|1|2|0|0|0|0|</code><br>
@@ -1040,8 +1338,8 @@ public:
\param last The end of the range to be inserted.
\throws "An allocation error" if memory is exhausted (<code>std::bad_alloc</code> if the standard allocator is
used).
\throws Whatever <code>T::T(const T&)</code> throws.
\throws Whatever <code>T::operator = (const T&)</code> throws.
Whatever <code>T::T(const T&)</code> throws.
Whatever <code>T::operator = (const T&)</code> throws.
\par Exception Safety
Basic.
\par Iterator Invalidation
@@ -1056,7 +1354,7 @@ public:
Consider a <code>circular_buffer_space_optimized</code> with the capacity of 6 and the size of 4. Its
internal buffer may look like the one below.<br><br>
<code>|1|2|3|4| | |</code><br>
<code>p ---^</code><br><br>After inserting a range of elements before the position <code>p</code>:<br><br>
<code>p ___^</code><br><br>After inserting a range of elements before the position <code>p</code>:<br><br>
<code>int array[] = { 5, 6, 7, 8, 9 };</code><br><code>insert(p, array, array + 5);</code><br><br>
actually only elements <code>5</code>, <code>6</code>, <code>7</code> and <code>8</code> from the
specified range get inserted and elements <code>3</code> and <code>4</code> are overwritten. This is due
@@ -1086,7 +1384,8 @@ public:
element exists.
\throws "An allocation error" if memory is exhausted (<code>std::bad_alloc</code> if the standard allocator is
used).
\throws Whatever <code>T::operator = (const T&)</code> throws.
Whatever <code>T::operator = (const T&)</code> throws or
nothing if <code>T::operator = (T&&)</code> is noexcept.
\par Exception Safety
Basic.
\par Iterator Invalidation
@@ -1116,7 +1415,8 @@ public:
element exists.
\throws "An allocation error" if memory is exhausted (<code>std::bad_alloc</code> if the standard allocator is
used).
\throws Whatever <code>T::operator = (const T&)</code> throws.
Whatever <code>T::operator = (const T&)</code> throws or
nothing if <code>T::operator = (T&&)</code> is noexcept.
\par Exception Safety
Basic.
\par Iterator Invalidation
@@ -1145,7 +1445,8 @@ public:
such element exists.
\throws "An allocation error" if memory is exhausted (<code>std::bad_alloc</code> if the standard allocator is
used).
\throws Whatever <code>T::operator = (const T&)</code> throws.
Whatever <code>T::operator = (const T&)</code> throws or
nothing if <code>T::operator = (T&&)</code> is noexcept.
\par Exception Safety
Basic.
\par Iterator Invalidation
@@ -1154,7 +1455,7 @@ public:
\par Complexity
Linear (in the size of the <code>circular_buffer_space_optimized</code>).
\note Basically there is no difference between <code>erase(iterator)</code> and this method. It is implemented
only for consistency with the base <code><a href="circular_buffer.html">circular_buffer</a></code>.
only for consistency with the base <code>circular_buffer</code>.
\sa <code>erase(iterator)</code>, <code>erase(iterator, iterator)</code>,
<code>rerase(iterator, iterator)</code>, <code>clear()</code>
*/
@@ -1177,7 +1478,8 @@ public:
such element exists.
\throws "An allocation error" if memory is exhausted (<code>std::bad_alloc</code> if the standard allocator is
used).
\throws Whatever <code>T::operator = (const T&)</code> throws.
Whatever <code>T::operator = (const T&)</code> throws or
nothing if <code>T::operator = (T&&)</code> is noexcept.
\par Exception Safety
Basic.
\par Iterator Invalidation
@@ -1187,7 +1489,7 @@ public:
Linear (in the size of the <code>circular_buffer_space_optimized</code>).
\note Basically there is no difference between <code>erase(iterator, iterator)</code> and this method. It is
implemented only for consistency with the base
<code><a href="circular_buffer.html">circular_buffer</a></code>.
<code><circular_buffer</code>.
\sa <code>erase(iterator)</code>, <code>erase(iterator, iterator)</code>, <code>rerase(iterator)</code>,
<code>clear()</code>
*/
@@ -1252,11 +1554,7 @@ private:
ensure_reserve(new_capacity, new_size));
}
#if BOOST_CB_ENABLE_DEBUG
# if BOOST_WORKAROUND(__DECCXX_VER, BOOST_TESTED_AT(70190006))
this->invalidate_iterators_except(end());
# else
invalidate_iterators_except(end());
# endif
#endif
}
@@ -1276,11 +1574,7 @@ private:
circular_buffer<T, Alloc>::set_capacity(
ensure_reserve(new_capacity, size()));
#if BOOST_CB_ENABLE_DEBUG
# if BOOST_WORKAROUND(__DECCXX_VER, BOOST_TESTED_AT(70190006))
this->invalidate_iterators_except(end());
# else
invalidate_iterators_except(end());
# endif
#endif
}
@@ -1300,7 +1594,7 @@ private:
//! Specialized method for determining the initial capacity.
template <class IntegralType>
static size_type init_capacity(const capacity_type& capacity_ctrl, IntegralType n, IntegralType item,
static size_type init_capacity(const capacity_type& capacity_ctrl, IntegralType n, IntegralType,
const true_type&) {
return init_capacity(capacity_ctrl, static_cast<size_type>(n));
}
@@ -1311,16 +1605,16 @@ private:
const false_type&) {
BOOST_CB_IS_CONVERTIBLE(Iterator, value_type); // check for invalid iterator type
#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x581))
return init_capacity(capacity_ctrl, first, last, BOOST_ITERATOR_CATEGORY<Iterator>::type());
return init_capacity(capacity_ctrl, first, last, iterator_category<Iterator>::type());
#else
return init_capacity(
capacity_ctrl, first, last, BOOST_DEDUCED_TYPENAME BOOST_ITERATOR_CATEGORY<Iterator>::type());
capacity_ctrl, first, last, BOOST_DEDUCED_TYPENAME iterator_category<Iterator>::type());
#endif
}
//! Specialized method for determining the initial capacity.
template <class InputIterator>
static size_type init_capacity(const capacity_type& capacity_ctrl, InputIterator first, InputIterator last,
static size_type init_capacity(const capacity_type& capacity_ctrl, InputIterator, InputIterator,
const std::input_iterator_tag&) {
return capacity_ctrl.capacity();
}
@@ -1414,7 +1708,7 @@ inline bool operator >= (const circular_buffer_space_optimized<T, Alloc>& lhs,
//! Swap the contents of two space optimized circular buffers.
template <class T, class Alloc>
inline void swap(circular_buffer_space_optimized<T, Alloc>& lhs,
circular_buffer_space_optimized<T, Alloc>& rhs) {
circular_buffer_space_optimized<T, Alloc>& rhs) BOOST_NOEXCEPT {
lhs.swap(rhs);
}

View File

@@ -11,7 +11,7 @@
#if !defined(BOOST_CIRCULAR_BUFFER_FWD_HPP)
#define BOOST_CIRCULAR_BUFFER_FWD_HPP
#if defined(_MSC_VER) && _MSC_VER >= 1200
#if defined(_MSC_VER)
#pragma once
#endif

View File

@@ -2,16 +2,17 @@
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="refresh" content="0; URL=doc/circular_buffer.html">
<meta http-equiv="refresh" content="0; URL=../../doc/html/circular_buffer.html">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>
Redirection
</title>
</head>
<body>
Automatic redirection failed, please go to <a href="doc/circular_buffer.html">circular_buffer.html</a>.
Automatic redirection failed, please go to
<a href="../../doc/html/circular_buffer.html"> ../../doc/html/circular_buffer.html</a>.
<p>
<small>Copyright © 2003-2008 Jan Gaspar</small>
<small>Copyright © 2003-2008 Jan Gaspar, 2013 Paul A. Bristow</small>
</p>
<p>
<small>Use, modification, and distribution is subject to the Boost Software License, Version 1.0.<br>
@@ -20,3 +21,5 @@
</p>
</body>
</html>

14
meta/libraries.json Normal file
View File

@@ -0,0 +1,14 @@
{
"key": "circular_buffer",
"name": "Circular Buffer",
"authors": [
"Jan Gaspar"
],
"description": "A STL compliant container also known as ring or cyclic buffer.",
"category": [
"Containers"
],
"maintainers": [
"Jan Gaspar <jano_gaspar -at- yahoo.com>"
]
}

View File

@@ -1 +0,0 @@
boost_module (circular_buffer DEPENDS config thread)

View File

@@ -1,13 +0,0 @@
#
# Copyright Troy D. Straszheim
#
# Distributed under the Boost Software License, Version 1.0.
# See http://www.boost.org/LICENSE_1_0.txt
#
boost_additional_test_dependencies(circular_buffer BOOST_DEPENDS test )
boost_test_run(base_test SINGLE_THREADED)
boost_test_run(space_optimized_test SINGLE_THREADED)
boost_test_run(soft_iterator_invalidation SINGLE_THREADED)
boost_test_compile(bounded_buffer_comparison)

View File

@@ -6,7 +6,7 @@
# accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)
# Added warning supression Paul A. Bristow 25 Nov 2008
# Added warning suppression Paul A. Bristow 25 Nov 2008
# Bring in rules for testing.
import testing ;
@@ -22,8 +22,11 @@ project
;
test-suite "circular_buffer"
: [ run base_test.cpp : <threading>single : ]
[ run space_optimized_test.cpp : <threading>single : ]
[ run soft_iterator_invalidation.cpp : <threading>single : ]
: [ run base_test.cpp : : : <threading>single : ]
[ run space_optimized_test.cpp : : : <threading>single : ]
[ run base_test.cpp : : : <threading>single <define>"BOOST_CB_ENABLE_DEBUG=1" : base_test_dbg ]
[ run space_optimized_test.cpp : : : <threading>single <define>"BOOST_CB_ENABLE_DEBUG=1" : space_optimized_test_dbg ]
[ run soft_iterator_invalidation.cpp : : : <threading>single : ]
[ run constant_erase_test.cpp : : : <threading>single : ]
[ compile bounded_buffer_comparison.cpp : <threading>multi : ]
;

View File

@@ -1,6 +1,7 @@
// Test of the base circular buffer container.
// Copyright (c) 2003-2008 Jan Gaspar
// Copyright (c) 2013 Antony Polukhin
// Use, modification, and distribution is subject to the Boost Software
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
@@ -192,7 +193,7 @@ void iterator_comparison_test() {
void iterator_invalidation_test() {
#if !defined(NDEBUG) && !defined(BOOST_CB_DISABLE_DEBUG)
#if BOOST_CB_ENABLE_DEBUG
circular_buffer<MyInteger>::iterator it1;
circular_buffer<MyInteger>::const_iterator it2;
@@ -562,7 +563,7 @@ void iterator_invalidation_test() {
BOOST_CHECK(it3.is_valid(&cb16));
BOOST_CHECK(!it4.is_valid(&cb16));
#endif // #if !defined(NDEBUG) && !defined(BOOST_CB_DISABLE_DEBUG)
#endif // #if BOOST_CB_ENABLE_DEBUG
}
// basic exception safety test (it is useful to use any memory-leak detection tool)
@@ -738,6 +739,107 @@ void exception_safety_test() {
#endif // #if !defined(BOOST_NO_EXCEPTIONS)
}
void move_container_values_except() {
move_container_values_impl<noncopyable_movable_except_t>();
}
template <class T>
void move_container_values_resetting_impl() {
typedef T noncopyable_movable_test_t;
CB_CONTAINER<noncopyable_movable_test_t> cb1(1);
noncopyable_movable_test_t var;
cb1.push_back();
cb1.push_back(boost::move(var));
BOOST_CHECK(!cb1.back().is_moved());
BOOST_CHECK(var.is_moved());
BOOST_CHECK(cb1.size() == 1);
var = boost::move(cb1.back());
BOOST_CHECK(cb1.back().is_moved());
cb1.push_front(boost::move(var));
BOOST_CHECK(!cb1.front().is_moved());
BOOST_CHECK(var.is_moved());
BOOST_CHECK(cb1.size() == 1);
var = boost::move(cb1.back());
BOOST_CHECK(cb1.back().is_moved());
cb1.push_back();
BOOST_CHECK(!cb1.back().is_moved());
BOOST_CHECK(cb1.size() == 1);
var = boost::move(cb1.back());
BOOST_CHECK(cb1.back().is_moved());
cb1.push_front();
BOOST_CHECK(!cb1.front().is_moved());
BOOST_CHECK(cb1.size() == 1);
var = boost::move(cb1.back());
BOOST_CHECK(cb1.back().is_moved());
cb1.insert(cb1.begin());
// If the circular_buffer is full and the pos points to begin(),
// then the item will not be inserted.
BOOST_CHECK(cb1.front().is_moved());
BOOST_CHECK(cb1.size() == 1);
var = boost::move(cb1.back());
BOOST_CHECK(cb1.back().is_moved());
cb1.insert(cb1.begin(), boost::move(var));
// If the circular_buffer is full and the pos points to begin(),
// then the item will not be inserted.
BOOST_CHECK(cb1.front().is_moved());
BOOST_CHECK(cb1.size() == 1);
var = boost::move(cb1.back());
BOOST_CHECK(cb1.back().is_moved());
cb1.rinsert(cb1.begin());
BOOST_CHECK(!cb1.back().is_moved());
BOOST_CHECK(cb1.size() == 1);
var = boost::move(cb1.back());
BOOST_CHECK(cb1.back().is_moved());
var.reinit();
cb1.rinsert(cb1.begin(), boost::move(var));
BOOST_CHECK(!cb1.back().is_moved());
BOOST_CHECK(cb1.size() == 1);
var = boost::move(cb1.back());
BOOST_CHECK(cb1.back().is_moved());
cb1.rinsert(cb1.end());
BOOST_CHECK(cb1.back().is_moved());
BOOST_CHECK(cb1.size() == 1);
var = boost::move(cb1.back());
BOOST_CHECK(cb1.back().is_moved());
var.reinit();
cb1.rinsert(cb1.end(), boost::move(var));
BOOST_CHECK(cb1.back().is_moved());
BOOST_CHECK(cb1.size() == 1);
var = boost::move(cb1.back());
BOOST_CHECK(cb1.back().is_moved());
cb1.push_back();
BOOST_CHECK(!cb1[0].is_moved());
const int val = cb1[0].value();
cb1.linearize();
BOOST_CHECK(!cb1[0].is_moved());
BOOST_CHECK(cb1[0].value() == val);
cb1.rotate(cb1.begin());
BOOST_CHECK(!cb1[0].is_moved());
BOOST_CHECK(cb1[0].value() == val);
}
void move_container_values_resetting_except() {
move_container_values_resetting_impl<noncopyable_movable_except_t>();
}
void move_container_values_resetting_noexcept() {
move_container_values_resetting_impl<noncopyable_movable_noexcept_t>();
}
// test main
test_suite* init_unit_test_suite(int /*argc*/, char* /*argv*/[]) {
@@ -755,6 +857,9 @@ test_suite* init_unit_test_suite(int /*argc*/, char* /*argv*/[]) {
tests->add(BOOST_TEST_CASE(&iterator_comparison_test));
tests->add(BOOST_TEST_CASE(&iterator_invalidation_test));
tests->add(BOOST_TEST_CASE(&exception_safety_test));
tests->add(BOOST_TEST_CASE(&move_container_values_except));
tests->add(BOOST_TEST_CASE(&move_container_values_resetting_except));
tests->add(BOOST_TEST_CASE(&move_container_values_resetting_noexcept));
return tests;
}

View File

@@ -1,16 +1,15 @@
// 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)
#define BOOST_CB_DISABLE_DEBUG
#include <boost/circular_buffer.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/thread/condition.hpp>
#include <boost/thread/condition_variable.hpp>
#include <boost/thread/thread.hpp>
#include <boost/call_traits.hpp>
#include <boost/progress.hpp>
@@ -35,7 +34,7 @@ public:
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);
boost::unique_lock<boost::mutex> 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;
@@ -44,7 +43,7 @@ public:
}
void pop_back(value_type* pItem) {
boost::mutex::scoped_lock lock(m_mutex);
boost::unique_lock<boost::mutex> 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();
@@ -61,8 +60,8 @@ private:
size_type m_unread;
container_type m_container;
boost::mutex m_mutex;
boost::condition m_not_empty;
boost::condition m_not_full;
boost::condition_variable m_not_empty;
boost::condition_variable m_not_full;
};
template <class T>
@@ -77,7 +76,7 @@ public:
explicit bounded_buffer_space_optimized(size_type capacity) : m_container(capacity) {}
void push_front(param_type item) {
boost::mutex::scoped_lock lock(m_mutex);
boost::unique_lock<boost::mutex> 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();
@@ -85,7 +84,7 @@ public:
}
void pop_back(value_type* pItem) {
boost::mutex::scoped_lock lock(m_mutex);
boost::unique_lock<boost::mutex> 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();
@@ -103,8 +102,8 @@ private:
container_type m_container;
boost::mutex m_mutex;
boost::condition m_not_empty;
boost::condition m_not_full;
boost::condition_variable m_not_empty;
boost::condition_variable m_not_full;
};
template <class T>
@@ -119,7 +118,7 @@ public:
explicit bounded_buffer_deque_based(size_type capacity) : m_capacity(capacity) {}
void push_front(param_type item) {
boost::mutex::scoped_lock lock(m_mutex);
boost::unique_lock<boost::mutex> 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();
@@ -127,7 +126,7 @@ public:
}
void pop_back(value_type* pItem) {
boost::mutex::scoped_lock lock(m_mutex);
boost::unique_lock<boost::mutex> 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();
@@ -146,8 +145,8 @@ private:
const size_type m_capacity;
container_type m_container;
boost::mutex m_mutex;
boost::condition m_not_empty;
boost::condition m_not_full;
boost::condition_variable m_not_empty;
boost::condition_variable m_not_full;
};
template <class T>
@@ -162,7 +161,7 @@ public:
explicit bounded_buffer_list_based(size_type capacity) : m_capacity(capacity) {}
void push_front(param_type item) {
boost::mutex::scoped_lock lock(m_mutex);
boost::unique_lock<boost::mutex> 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();
@@ -170,7 +169,7 @@ public:
}
void pop_back(value_type* pItem) {
boost::mutex::scoped_lock lock(m_mutex);
boost::unique_lock<boost::mutex> 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();
@@ -189,8 +188,8 @@ private:
const size_type m_capacity;
container_type m_container;
boost::mutex m_mutex;
boost::condition m_not_empty;
boost::condition m_not_full;
boost::condition_variable m_not_empty;
boost::condition_variable m_not_full;
};
template<class Buffer>
@@ -291,3 +290,27 @@ int main(int /*argc*/, char* /*argv*/[]) {
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]
*/

View File

@@ -1,12 +1,19 @@
// Common tests for the circular buffer and its adaptor.
// Copyright (c) 2003-2008 Jan Gaspar
// Copyright (c) 2013 Antony Polukhin
// Copyright (c) 2014 Glen Fernandes // C++11 allocator model support.
// 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)
void generic_test(CB_CONTAINER<MyInteger>& cb) {
#include <boost/type_traits/is_nothrow_move_constructible.hpp>
#include <boost/type_traits/is_nothrow_move_assignable.hpp>
#include <boost/type_traits/has_nothrow_constructor.hpp>
template <class Alloc>
void generic_test(CB_CONTAINER<MyInteger, Alloc>& cb) {
vector<int> v;
v.push_back(11);
@@ -144,6 +151,97 @@ void size_test() {
generic_test(cb2);
}
template<class T>
class my_allocator {
typedef std::allocator<T> base_t;
base_t base_;
public:
typedef T value_type;
typedef value_type& reference;
typedef const value_type& const_reference;
typedef typename base_t::size_type size_type;
typedef typename base_t::difference_type difference_type;
private:
template<class U>
struct const_pointer_;
template<class U>
struct pointer_ {
pointer_(){}
pointer_(void* p) : hidden_ptr_((U*)p) {}
difference_type operator-(const const_pointer_<U>& rhs) const { return hidden_ptr_ - rhs.hidden_ptr_; }
difference_type operator-(pointer_ rhs) const { return hidden_ptr_ - rhs.hidden_ptr_; }
pointer_ operator-(size_type rhs) const { return hidden_ptr_ - rhs; }
bool operator == (pointer_ rhs) const { return hidden_ptr_ == rhs.hidden_ptr_; }
bool operator != (pointer_ rhs) const { return hidden_ptr_ != rhs.hidden_ptr_; }
bool operator < (pointer_ rhs) const { return hidden_ptr_ < rhs.hidden_ptr_; }
bool operator >= (pointer_ rhs) const { return hidden_ptr_ >= rhs.hidden_ptr_; }
pointer_& operator++() { ++hidden_ptr_; return *this; }
pointer_& operator--() { --hidden_ptr_; return *this; }
pointer_& operator+=(size_type s) { hidden_ptr_ += s; return *this; }
pointer_ operator+(size_type s) const { return hidden_ptr_ + s; }
pointer_ operator++(int) { pointer_ p = *this; ++hidden_ptr_; return p; }
pointer_ operator--(int) { pointer_ p = *this; --hidden_ptr_; return p; }
U& operator*() const { return *hidden_ptr_; }
U* hidden_ptr_;
};
template<class U>
struct const_pointer_ {
const_pointer_(){}
const_pointer_(pointer_<U> p) : hidden_ptr_(p.hidden_ptr_) {}
const_pointer_(const void* p) : hidden_ptr_((const U*)p) {}
difference_type operator-(pointer_<U> rhs) const { return hidden_ptr_ - rhs.hidden_ptr_; }
difference_type operator-(const_pointer_ rhs) const { return hidden_ptr_ - rhs.hidden_ptr_; }
const_pointer_ operator-(size_type rhs) const { return hidden_ptr_ - rhs; }
bool operator == (const_pointer_ rhs) const { return hidden_ptr_ == rhs.hidden_ptr_; }
bool operator != (const_pointer_ rhs) const { return hidden_ptr_ != rhs.hidden_ptr_; }
bool operator < (const_pointer_ rhs) const { return hidden_ptr_ < rhs.hidden_ptr_; }
bool operator >= (const_pointer_ rhs) const { return hidden_ptr_ >= rhs.hidden_ptr_; }
const_pointer_& operator++() { ++hidden_ptr_; return *this; }
const_pointer_& operator--() { --hidden_ptr_; return *this; }
const_pointer_& operator+=(size_type s) { hidden_ptr_ += s; return hidden_ptr_; }
const_pointer_ operator+(size_type s) const { return hidden_ptr_ + s; }
const_pointer_ operator++(int) { const_pointer_ p = *this; ++hidden_ptr_; return p; }
const_pointer_ operator--(int) { const_pointer_ p = *this; --hidden_ptr_; return p; }
const U& operator*() const { return *hidden_ptr_; }
const U* hidden_ptr_;
};
public:
typedef pointer_<T> pointer;
typedef const_pointer_<T> const_pointer;
template<class T2>
struct rebind
{
typedef my_allocator<T2> other;
};
size_type max_size() const
{ return base_.max_size(); }
pointer allocate(size_type count, const void* hint = 0) {
return pointer(base_.allocate(count, hint));
}
void deallocate(const pointer &ptr, size_type s)
{ base_.deallocate(ptr.hidden_ptr_, s); }
template<class P>
void construct(const pointer &ptr, BOOST_FWD_REF(P) p)
{ ::new(ptr.hidden_ptr_) value_type(::boost::forward<P>(p)); }
void destroy(const pointer &ptr)
{ (*ptr.hidden_ptr_).~value_type(); }
};
void allocator_test() {
CB_CONTAINER<MyInteger> cb1(10, 0);
@@ -154,8 +252,40 @@ void allocator_test() {
alloc.max_size();
generic_test(cb1);
CB_CONTAINER<MyInteger, my_allocator<MyInteger> > cb_a(10, 0);
generic_test(cb_a);
}
#if !defined(BOOST_NO_CXX11_ALLOCATOR)
template<class T>
class cxx11_allocator {
public:
typedef T value_type;
cxx11_allocator() {
}
template<class U>
cxx11_allocator(const cxx11_allocator<U> &) {
}
T* allocate(std::size_t n) {
return static_cast<T*>(::operator new(n * sizeof(T)));
}
void deallocate(T * p, std::size_t n) {
::operator delete( p );
}
};
void cxx11_allocator_test() {
CB_CONTAINER<MyInteger, cxx11_allocator<MyInteger> > cb(10, 0);
generic_test(cb);
}
#endif
void begin_and_end_test() {
vector<int> v;
@@ -1949,6 +2079,355 @@ void rotate_test() {
int MyInteger::ms_exception_trigger = 0;
int InstanceCounter::ms_count = 0;
void move_container_on_cpp11() {
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
CB_CONTAINER<MyInteger> cb1(10);
cb1.push_back(1);
cb1.push_back(2);
cb1.push_back(3);
cb1.push_back(4);
cb1.push_back(5);
cb1.push_back(6);
// Checking move constructor
CB_CONTAINER<MyInteger> cb2(static_cast<CB_CONTAINER<MyInteger>&& >(cb1));
CB_CONTAINER<MyInteger>::iterator it2 = cb2.begin() + 1;
BOOST_CHECK(cb1.empty());
BOOST_CHECK(!cb2.empty());
BOOST_CHECK(it2[0] == 2);
BOOST_CHECK(it2[-1] == 1);
BOOST_CHECK(it2[2] == 4);
// Checking move assignment
cb1 = static_cast<CB_CONTAINER<MyInteger>&& >(cb2);
CB_CONTAINER<MyInteger>::iterator it1 = cb1.begin() + 1;
BOOST_CHECK(!cb1.empty());
BOOST_CHECK(cb2.empty());
BOOST_CHECK(it1[0] == 2);
BOOST_CHECK(it1[-1] == 1);
BOOST_CHECK(it1[2] == 4);
#endif
}
struct noncopyable_movable_except_t
{
private:
BOOST_MOVABLE_BUT_NOT_COPYABLE(noncopyable_movable_except_t)
bool is_moved_;
int value_;
public:
static int next_value;
explicit noncopyable_movable_except_t()
: is_moved_(false)
, value_(next_value ++)
{}
noncopyable_movable_except_t(BOOST_RV_REF(noncopyable_movable_except_t) x) {
is_moved_ = x.is_moved_;
value_ = x.value_;
x.is_moved_ = true;
}
noncopyable_movable_except_t& operator=(BOOST_RV_REF(noncopyable_movable_except_t) x) {
is_moved_ = x.is_moved_;
value_ = x.value_;
x.is_moved_ = true;
return *this;
}
bool is_moved() const {
return is_moved_;
}
int value() const {
return value_;
}
void reinit() { is_moved_ = false; value_ = next_value ++; }
};
struct noncopyable_movable_noexcept_t
{
private:
BOOST_MOVABLE_BUT_NOT_COPYABLE(noncopyable_movable_noexcept_t)
bool is_moved_;
int value_;
public:
static int next_value;
explicit noncopyable_movable_noexcept_t()
: is_moved_(false)
, value_(next_value ++)
{}
noncopyable_movable_noexcept_t(BOOST_RV_REF(noncopyable_movable_noexcept_t) x) BOOST_NOEXCEPT {
is_moved_ = x.is_moved_;
value_ = x.value_;
x.is_moved_ = true;
}
noncopyable_movable_noexcept_t& operator=(BOOST_RV_REF(noncopyable_movable_noexcept_t) x) BOOST_NOEXCEPT {
is_moved_ = x.is_moved_;
value_ = x.value_;
x.is_moved_ = true;
return *this;
}
bool is_moved() const {
return is_moved_;
}
int value() const {
return value_;
}
void reinit() { is_moved_ = false; value_ = next_value ++; }
};
#ifdef BOOST_NO_CXX11_NOEXCEPT
namespace boost {
template <>
struct is_nothrow_move_constructible<noncopyable_movable_noexcept_t>
: boost::true_type
{};
}
#endif
int noncopyable_movable_noexcept_t::next_value = 1;
int noncopyable_movable_except_t::next_value = 1;
template <class T>
void move_container_values_impl() {
typedef T noncopyable_movable_test_t;
noncopyable_movable_test_t::next_value = 1;
CB_CONTAINER<noncopyable_movable_test_t> cb1(40);
noncopyable_movable_test_t var;
cb1.push_back(boost::move(var));
BOOST_CHECK(!cb1.back().is_moved());
BOOST_CHECK(cb1.back().value() == 1);
BOOST_CHECK(var.is_moved());
BOOST_CHECK(cb1.size() == 1);
var.reinit();
cb1.push_front(boost::move(var));
BOOST_CHECK(!cb1.front().is_moved());
BOOST_CHECK(cb1.front().value() == 2);
BOOST_CHECK(var.is_moved());
BOOST_CHECK(cb1.size() == 2);
cb1.push_back();
BOOST_CHECK(!cb1.back().is_moved());
BOOST_CHECK(cb1.back().value() == 3);
BOOST_CHECK(cb1.size() == 3);
cb1.push_front();
BOOST_CHECK(!cb1.front().is_moved());
BOOST_CHECK(cb1.front().value() == 4);
BOOST_CHECK(cb1.size() == 4);
cb1.insert(cb1.begin());
BOOST_CHECK(!cb1.front().is_moved());
BOOST_CHECK(cb1.front().value() == 5);
BOOST_CHECK(cb1.size() == 5);
var.reinit();
cb1.insert(cb1.begin(), boost::move(var));
BOOST_CHECK(!cb1.front().is_moved());
BOOST_CHECK(cb1.front().value() == 6);
BOOST_CHECK(cb1.size() == 6);
cb1.rinsert(cb1.begin());
BOOST_CHECK(!cb1.front().is_moved());
BOOST_CHECK(cb1.front().value() == 7);
BOOST_CHECK(cb1.size() == 7);
var.reinit();
cb1.rinsert(cb1.begin(), boost::move(var));
BOOST_CHECK(!cb1.front().is_moved());
BOOST_CHECK(cb1.front().value() == 8);
BOOST_CHECK(cb1.size() == 8);
BOOST_CHECK(cb1[0].value() == 8);
BOOST_CHECK(cb1[1].value() == 7);
BOOST_CHECK(cb1[2].value() == 6);
BOOST_CHECK(cb1[3].value() == 5);
BOOST_CHECK(cb1[4].value() == 4);
BOOST_CHECK(cb1[5].value() == 2);
BOOST_CHECK(cb1[6].value() == 1);
BOOST_CHECK(cb1[7].value() == 3);
cb1.rotate(cb1.begin() + 2);
BOOST_CHECK(cb1[0].value() == 6);
BOOST_CHECK(cb1[1].value() == 5);
BOOST_CHECK(cb1[2].value() == 4);
BOOST_CHECK(cb1[3].value() == 2);
BOOST_CHECK(cb1[4].value() == 1);
BOOST_CHECK(cb1[5].value() == 3);
BOOST_CHECK(cb1[6].value() == 8);
BOOST_CHECK(cb1[7].value() == 7);
BOOST_CHECK(!cb1[0].is_moved());
BOOST_CHECK(!cb1[1].is_moved());
BOOST_CHECK(!cb1[2].is_moved());
BOOST_CHECK(!cb1[3].is_moved());
BOOST_CHECK(!cb1[4].is_moved());
BOOST_CHECK(!cb1[5].is_moved());
BOOST_CHECK(!cb1[6].is_moved());
BOOST_CHECK(!cb1[7].is_moved());
cb1.linearize();
BOOST_CHECK(!cb1[0].is_moved());
BOOST_CHECK(!cb1[1].is_moved());
BOOST_CHECK(!cb1[2].is_moved());
BOOST_CHECK(!cb1[3].is_moved());
BOOST_CHECK(!cb1[4].is_moved());
BOOST_CHECK(!cb1[5].is_moved());
BOOST_CHECK(!cb1[6].is_moved());
BOOST_CHECK(!cb1[7].is_moved());
BOOST_CHECK(cb1[0].value() == 6);
BOOST_CHECK(cb1[1].value() == 5);
BOOST_CHECK(cb1[2].value() == 4);
BOOST_CHECK(cb1[3].value() == 2);
BOOST_CHECK(cb1[4].value() == 1);
BOOST_CHECK(cb1[5].value() == 3);
BOOST_CHECK(cb1[6].value() == 8);
BOOST_CHECK(cb1[7].value() == 7);
cb1.erase(cb1.begin());
BOOST_CHECK(!cb1[0].is_moved());
BOOST_CHECK(!cb1[1].is_moved());
BOOST_CHECK(!cb1[2].is_moved());
BOOST_CHECK(!cb1[3].is_moved());
BOOST_CHECK(!cb1[4].is_moved());
BOOST_CHECK(!cb1[5].is_moved());
BOOST_CHECK(!cb1[6].is_moved());
BOOST_CHECK(cb1[0].value() == 5);
BOOST_CHECK(cb1[1].value() == 4);
BOOST_CHECK(cb1[2].value() == 2);
BOOST_CHECK(cb1[3].value() == 1);
BOOST_CHECK(cb1[4].value() == 3);
BOOST_CHECK(cb1[5].value() == 8);
BOOST_CHECK(cb1[6].value() == 7);
cb1.rerase(cb1.begin());
BOOST_CHECK(!cb1[0].is_moved());
BOOST_CHECK(!cb1[1].is_moved());
BOOST_CHECK(!cb1[2].is_moved());
BOOST_CHECK(!cb1[3].is_moved());
BOOST_CHECK(!cb1[4].is_moved());
BOOST_CHECK(!cb1[5].is_moved());
BOOST_CHECK(cb1[0].value() == 4);
BOOST_CHECK(cb1[1].value() == 2);
BOOST_CHECK(cb1[2].value() == 1);
BOOST_CHECK(cb1[3].value() == 3);
BOOST_CHECK(cb1[4].value() == 8);
BOOST_CHECK(cb1[5].value() == 7);
cb1.erase(cb1.begin(), cb1.begin() + 1);
BOOST_CHECK(!cb1[0].is_moved());
BOOST_CHECK(!cb1[1].is_moved());
BOOST_CHECK(!cb1[2].is_moved());
BOOST_CHECK(!cb1[3].is_moved());
BOOST_CHECK(!cb1[4].is_moved());
BOOST_CHECK(cb1[0].value() == 2);
BOOST_CHECK(cb1[1].value() == 1);
BOOST_CHECK(cb1[2].value() == 3);
BOOST_CHECK(cb1[3].value() == 8);
BOOST_CHECK(cb1[4].value() == 7);
cb1.rerase(cb1.begin(), cb1.begin() + 1);
BOOST_CHECK(!cb1[0].is_moved());
BOOST_CHECK(!cb1[1].is_moved());
BOOST_CHECK(!cb1[2].is_moved());
BOOST_CHECK(!cb1[3].is_moved());
BOOST_CHECK(cb1[0].value() == 1);
BOOST_CHECK(cb1[1].value() == 3);
BOOST_CHECK(cb1[2].value() == 8);
BOOST_CHECK(cb1[3].value() == 7);
}
void move_container_values_noexcept() {
move_container_values_impl<noncopyable_movable_noexcept_t>();
typedef noncopyable_movable_noexcept_t noncopyable_movable_test_t;
noncopyable_movable_test_t::next_value = 1;
CB_CONTAINER<noncopyable_movable_test_t> cb1(40);
cb1.push_back();
cb1.push_back();
cb1.push_back();
cb1.push_back();
cb1.push_back();
cb1.push_back();
cb1.push_back();
cb1.push_back();
cb1.set_capacity(100);
BOOST_CHECK(!cb1[0].is_moved());
BOOST_CHECK(!cb1[1].is_moved());
BOOST_CHECK(!cb1[2].is_moved());
BOOST_CHECK(!cb1[3].is_moved());
BOOST_CHECK(!cb1[4].is_moved());
BOOST_CHECK(!cb1[5].is_moved());
BOOST_CHECK(!cb1[6].is_moved());
BOOST_CHECK(!cb1[7].is_moved());
BOOST_CHECK(cb1[0].value() == 1);
BOOST_CHECK(cb1[1].value() == 2);
BOOST_CHECK(cb1[2].value() == 3);
BOOST_CHECK(cb1[3].value() == 4);
BOOST_CHECK(cb1[4].value() == 5);
BOOST_CHECK(cb1[5].value() == 6);
BOOST_CHECK(cb1[6].value() == 7);
BOOST_CHECK(cb1[7].value() == 8);
cb1.rset_capacity(101);
BOOST_CHECK(!cb1[0].is_moved());
BOOST_CHECK(!cb1[1].is_moved());
BOOST_CHECK(!cb1[2].is_moved());
BOOST_CHECK(!cb1[3].is_moved());
BOOST_CHECK(!cb1[4].is_moved());
BOOST_CHECK(!cb1[5].is_moved());
BOOST_CHECK(!cb1[6].is_moved());
BOOST_CHECK(!cb1[7].is_moved());
BOOST_CHECK(cb1[0].value() == 1);
BOOST_CHECK(cb1[1].value() == 2);
BOOST_CHECK(cb1[2].value() == 3);
BOOST_CHECK(cb1[3].value() == 4);
BOOST_CHECK(cb1[4].value() == 5);
BOOST_CHECK(cb1[5].value() == 6);
BOOST_CHECK(cb1[6].value() == 7);
BOOST_CHECK(cb1[7].value() == 8);
cb1.set_capacity(2);
BOOST_CHECK(!cb1[0].is_moved());
BOOST_CHECK(!cb1[1].is_moved());
BOOST_CHECK(cb1[0].value() == 1);
BOOST_CHECK(cb1[1].value() == 2);
cb1.rset_capacity(1);
BOOST_CHECK(!cb1[0].is_moved());
BOOST_CHECK(cb1[0].value() == 2);
}
void check_containers_exception_specifications() {
#ifndef BOOST_NO_CXX11_NOEXCEPT
#ifndef BOOST_CLANG
// Clang has an error in __has_nothrow_constructor implementation:
// http://llvm.org/bugs/show_bug.cgi?id=16627
BOOST_CHECK(boost::has_nothrow_constructor<CB_CONTAINER<int> >::value);
#endif
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
BOOST_CHECK(boost::is_nothrow_move_assignable<CB_CONTAINER<int> >::value);
BOOST_CHECK(boost::is_nothrow_move_constructible<CB_CONTAINER<int> >::value);
#endif
#endif // BOOST_NO_CXX11_NOEXCEPT
}
// add common tests into a test suite
void add_common_tests(test_suite* tests) {
tests->add(BOOST_TEST_CASE(&basic_test));
@@ -1994,4 +2473,11 @@ void add_common_tests(test_suite* tests) {
tests->add(BOOST_TEST_CASE(&element_destruction_test));
tests->add(BOOST_TEST_CASE(&const_methods_test));
tests->add(BOOST_TEST_CASE(&rotate_test));
tests->add(BOOST_TEST_CASE(&move_container_on_cpp11));
tests->add(BOOST_TEST_CASE(&move_container_values_noexcept));
tests->add(BOOST_TEST_CASE(&check_containers_exception_specifications));
#if !defined(BOOST_NO_CXX11_ALLOCATOR)
tests->add(BOOST_TEST_CASE(&cxx11_allocator_test));
#endif
}

View File

@@ -0,0 +1,185 @@
// Special tests for erase_begin, erase_end and clear methods.
// Copyright (c) 2009 Jan Gaspar
// 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 "test.hpp"
int MyInteger::ms_exception_trigger = 0;
int InstanceCounter::ms_count = 0;
void erase_begin_test() {
circular_buffer<int> cb1(5);
cb1.push_back(1);
cb1.push_back(2);
cb1.push_back(3);
cb1.push_back(4);
cb1.push_back(5);
cb1.push_back(6);
circular_buffer<int>::pointer p = &cb1[0];
cb1.erase_begin(2);
BOOST_CHECK(cb1.size() == 3);
BOOST_CHECK(cb1[0] == 4);
BOOST_CHECK(cb1[1] == 5);
BOOST_CHECK(cb1[2] == 6);
cb1.erase_begin(3);
BOOST_CHECK(cb1.empty());
BOOST_CHECK(*p == 2);
BOOST_CHECK(*(p + 1) == 3);
BOOST_CHECK(*(p + 2) == 4);
cb1.push_back(10);
cb1.push_back(11);
cb1.push_back(12);
BOOST_CHECK(cb1.size() == 3);
BOOST_CHECK(cb1[0] == 10);
BOOST_CHECK(cb1[1] == 11);
BOOST_CHECK(cb1[2] == 12);
circular_buffer<InstanceCounter> cb2(5, InstanceCounter());
BOOST_CHECK(cb2.size() == 5);
BOOST_CHECK(InstanceCounter::count() == 5);
cb2.erase_begin(2);
BOOST_CHECK(cb2.size() == 3);
BOOST_CHECK(InstanceCounter::count() == 3);
circular_buffer<MyInteger> cb3(5);
cb3.push_back(1);
cb3.push_back(2);
cb3.push_back(3);
cb3.push_back(4);
cb3.push_back(5);
cb3.push_back(6);
cb3.erase_begin(2);
BOOST_CHECK(cb3.size() == 3);
BOOST_CHECK(cb3[0] == 4);
BOOST_CHECK(cb3[1] == 5);
BOOST_CHECK(cb3[2] == 6);
}
void erase_end_test() {
circular_buffer<int> cb1(5);
cb1.push_back(1);
cb1.push_back(2);
cb1.push_back(3);
cb1.push_back(4);
cb1.push_back(5);
cb1.push_back(6);
circular_buffer<int>::pointer p = &cb1[3];
cb1.erase_end(2);
BOOST_CHECK(cb1.size() == 3);
BOOST_CHECK(cb1[0] == 2);
BOOST_CHECK(cb1[1] == 3);
BOOST_CHECK(cb1[2] ==4);
cb1.erase_end(3);
BOOST_CHECK(cb1.empty());
BOOST_CHECK(*p == 5);
BOOST_CHECK(*(p - 1) == 4);
BOOST_CHECK(*(p - 2) == 3);
cb1.push_back(10);
cb1.push_back(11);
cb1.push_back(12);
BOOST_CHECK(cb1.size() == 3);
BOOST_CHECK(cb1[0] == 10);
BOOST_CHECK(cb1[1] == 11);
BOOST_CHECK(cb1[2] == 12);
circular_buffer<InstanceCounter> cb2(5, InstanceCounter());
BOOST_CHECK(cb2.size() == 5);
BOOST_CHECK(InstanceCounter::count() == 5);
cb2.erase_end(2);
BOOST_CHECK(cb2.size() == 3);
BOOST_CHECK(InstanceCounter::count() == 3);
circular_buffer<MyInteger> cb3(5);
cb3.push_back(1);
cb3.push_back(2);
cb3.push_back(3);
cb3.push_back(4);
cb3.push_back(5);
cb3.push_back(6);
cb3.erase_end(2);
BOOST_CHECK(cb3.size() == 3);
BOOST_CHECK(cb3[0] == 2);
BOOST_CHECK(cb3[1] == 3);
BOOST_CHECK(cb3[2] == 4);
}
void clear_test() {
circular_buffer<int> cb1(5);
cb1.push_back(1);
cb1.push_back(2);
cb1.push_back(3);
cb1.push_back(4);
cb1.push_back(5);
cb1.push_back(6);
circular_buffer<int>::pointer p = &cb1[0];
cb1.clear();
BOOST_CHECK(cb1.empty());
BOOST_CHECK(*p == 2);
BOOST_CHECK(*(p + 1) == 3);
BOOST_CHECK(*(p + 2) == 4);
BOOST_CHECK(*(p + 3) == 5);
BOOST_CHECK(*(p - 1) == 6);
circular_buffer<InstanceCounter> cb2(5, InstanceCounter());
BOOST_CHECK(cb2.size() == 5);
BOOST_CHECK(InstanceCounter::count() == 5);
cb2.clear();
BOOST_CHECK(cb2.empty());
BOOST_CHECK(InstanceCounter::count() == 0);
circular_buffer<MyInteger> cb3(5);
cb3.push_back(1);
cb3.push_back(2);
cb3.push_back(3);
cb3.push_back(4);
cb3.push_back(5);
cb3.push_back(6);
cb3.clear();
BOOST_CHECK(cb3.empty());
}
// test main
test_suite* init_unit_test_suite(int /*argc*/, char* /*argv*/[]) {
test_suite* tests = BOOST_TEST_SUITE("Unit tests for erase_begin/end and clear methods of the circular_buffer.");
tests->add(BOOST_TEST_CASE(&erase_begin_test));
tests->add(BOOST_TEST_CASE(&erase_end_test));
tests->add(BOOST_TEST_CASE(&clear_test));
return tests;
}

View File

@@ -9,8 +9,6 @@
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#define BOOST_CB_DISABLE_DEBUG
#include "test.hpp"
// test of the example (introduced in the documentation)

View File

@@ -125,7 +125,7 @@ void shrink_to_fit_test() {
void iterator_invalidation_test() {
#if !defined(NDEBUG) && !defined(BOOST_CB_DISABLE_DEBUG)
#if BOOST_CB_ENABLE_DEBUG
cb_space_optimized cb1(10, 1);
cb1.push_back(2);
@@ -177,7 +177,7 @@ void iterator_invalidation_test() {
BOOST_CHECK(!it2.is_valid(&cb1));
BOOST_CHECK(!it3.is_valid(&cb1));
#endif // #if !defined(NDEBUG) && !defined(BOOST_CB_DISABLE_DEBUG)
#endif // #if BOOST_CB_ENABLE_DEBUG
}
// test main

View File

@@ -16,7 +16,7 @@
#define BOOST_CB_TEST
#include <boost/circular_buffer.hpp>
#include <boost/test/included/unit_test_framework.hpp>
#include <boost/test/included/unit_test.hpp>
#include <boost/iterator.hpp>
#include <iterator>
#include <numeric>