circular_buffer.qbk 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626
  1. [article Boost.Circular Buffer
  2. [quickbook 1.6]
  3. [id circular_buffer]
  4. [copyright 2003-2013 Jan Gaspar]
  5. [license
  6. Distributed under the Boost Software License, Version 1.0.
  7. (See accompanying file LICENSE_1_0.txt or copy at
  8. [@http://www.boost.org/LICENSE_1_0.txt])
  9. ]
  10. [authors [Gaspar, Jan]]
  11. [source-mode c++]
  12. ]
  13. [/ Links - by (most common) convention, prefixed with double underscore so not confused with other names.]
  14. [def __alert [$./images/alert.png]] [/ Examples of your own images (in doc/html/images/ .]
  15. [def __tip [$./images/tip.png]]
  16. [/ If you provide a file type like .png, you will probably find that the file is missing in the pdf version.]
  17. [/ This is because the default file type specified is .png in html, but .svg for pdf version.]
  18. [/ Some links to external sources.]
  19. [/ You often want to link more than once, so using a def ensures you always refer to the same location.]
  20. [def __boost [@http://www.boost.org/ Boost]] [/Boost.org]
  21. [def __boostroot [@boost: Boost root]] [/ Your boost root]
  22. [/Note the custom boost root url schema for linking to files within the Boost distribution.]
  23. [/Note It can't be used for images, nor for pdf, so not so useful.]
  24. [/def __boostlicense [@http://www.boost.org/LICENSE_1_0.txt Boost License]]
  25. [/ Or refer to your most recent version of Boost.]
  26. [def __boostlicense [@boost:/LICENSE_1_0.txt Boost License]]
  27. [def __boostbook [@http://www.boost.org/doc/html/boostbook.html BoostBook]]
  28. [def __boostbook_docs [@http://www.boost.org/doc/libs/1_53_0/doc/html/boostbook.html BoostBook documentation]]
  29. [def __quickbook [@http://www.boost.org/doc/tools/quickbook/index.html Quickbook]]
  30. [def __quickbook_syntax [@http://www.boost.org/doc/libs/1_53_0/doc/html/quickbook/ref.html Quickbook Syntax Compendium]]
  31. [def __docbook [@http://www.docbook.org/ DocBook]]
  32. [def __doxygen [@http://www.doxygen.org/ Doxygen]]
  33. [def __autoindex [@boost:/tools/auto_index/doc/html/index.html AutoIndex]]
  34. [def __pdf [@http://www.adobe.com/products/acrobat/adobepdf.html PDF]]
  35. [def __textpad [@http://www.textpad.com Textpad]]
  36. [def __emacs [@http://www.gnu.org/software/emacs/ GNU emacs]]
  37. [def __css [@http://en.wikipedia.org/wiki/Cascading_Style_Sheets Cascading Style Sheet]]
  38. [def __intro [link circular_buffer.intro Introduction]] [/Link to a Quickbook section (see below).]
  39. [def __docbook_params [@http://docbook.sourceforge.net/release/xsl/current/doc/ Docbook xsl:param format options]]
  40. [def __cb [classref boost::circular_buffer circular_buffer]]
  41. [def __cbso [classref boost::circular_buffer_space_optimized circular_buffer_space_optimized]]
  42. [def __min_capacity [memberref boost::circular_buffer_space_optimized::min_capacity() min_capacity]]
  43. [def __capacity_control [memberref boost::circular_buffer_space_optimized::capacity_control () capacity_control ]]
  44. [def __debug_support [link circular_buffer.implementation.debug_support debug support]]
  45. [include ../../../tools/auto_index/include/auto_index_helpers.qbk]
  46. [/ Must be first included file!]
  47. [note A printer-friendly PDF version of this manual is also available.]
  48. [section:intro Introduction]
  49. A Circular Buffer.
  50. [h2 Description]
  51. The term [@http://en.wikipedia.org/wiki/Circular_buffer circular buffer]
  52. (also called a ['ring] or ['cyclic buffer])
  53. refers to an area in memory which is used to store incoming data.
  54. When the buffer is filled,
  55. new data is written starting at the beginning of the buffer and overwriting the old.
  56. [classref boost::circular_buffer] is a STL compliant container.
  57. It is a kind of sequence similar to [@https://www.boost.org/sgi/stl/List.html std::list]
  58. or [@https://www.boost.org/sgi/stl/Deque.html std::deque].
  59. It supports random access iterators, constant time insert and erase operations
  60. at the beginning or the end of the buffer and interoperability with std algorithms.
  61. The __cb is especially designed to provide [*fixed capacity] storage.
  62. When its capacity is exhausted, newly inserted elements will cause elements
  63. to be overwritten, either at the beginning or end of the buffer
  64. (depending on what insert operation is used).
  65. The __cb only allocates memory when created,
  66. when the capacity is adjusted explicitly,
  67. or as necessary to accommodate resizing or assign operations.
  68. [$../../libs/circular_buffer/doc/images/circular_buffer.png]
  69. There is also a __cbso version available.
  70. [$../../libs/circular_buffer/doc/images/space_optimized.png]
  71. __cbso is an adaptation of the __cb
  72. which [*does not allocate memory all at once when created],
  73. instead it allocates memory as needed.
  74. The predictive memory allocation is similar to typical `std::vector` implementation.
  75. Memory is automatically freed as the size of the container decreases.
  76. The memory allocation process of the space-optimized circular buffer.
  77. The __min_capacity of the capacity controller represents
  78. the minimal guaranteed amount of allocated memory.
  79. The allocated memory will never drop under this value.
  80. The default value of the `min_capacity` is set to 0.
  81. The `min_capacity` can be set using the constructor parameter __capacity_control
  82. or the function `set_capacity`.
  83. The space-optimized version is, of course, a little slower.
  84. [endsect] [/section:intro Introduction]
  85. [section:example Circular_buffer example]
  86. Here is a simple example to introduce the class __cb.
  87. [import ../example/circular_buffer_example.cpp]
  88. [circular_buffer_example_1]
  89. This example shows construction, inserting elements, overwriting and popping.
  90. [circular_buffer_example_2]
  91. [/circular_buffer_example_output - there is no output for this example]
  92. You can see the full example code at [@boost:libs/circular_buffer/example/circular_buffer_example.cpp circular_buffer_example.cpp].
  93. The full annotated description is in the C++ Reference section.
  94. [endsect] [/section:example circular_buffer example]
  95. [section:rationale Rationale]
  96. The basic motivation behind the __cb was to create a container which would [*work seamlessly with STL].
  97. Additionally, the design of the __cb was guided by the following principles:
  98. * Maximum ['efficiency] for envisaged applications.
  99. * Suitable for ['general purpose use].
  100. * The behaviour of the buffer as ['intuitive] as possible.
  101. * Suitable for ['specialization] by means of adaptors. (The __cbso is such an example of the adaptor.)
  102. * Easy to ['debug]. (See Debug Support for details.)
  103. In order to achieve maximum efficiency, the __cb and __cbso store their elements in a
  104. [*contiguous region of memory], which then enables:
  105. * Use of fixed memory and no implicit or unexpected memory allocation.
  106. * Fast constant-time insertion and removal of elements from the front and back.
  107. * Fast constant-time random access of elements.
  108. * Suitability for real-time and performance critical applications.
  109. Possible applications of the circular buffer include:
  110. * Storage of the ['most recently received samples], overwriting the oldest as new samples arrive.
  111. * As an underlying container for a ['bounded buffer]
  112. (see the Bounded Buffer example, code at [@boost:libs/circular_buffer/example/circular_buffer_bound_example.cpp circular_buffer_bound_example.cpp]).
  113. * A kind of ['cache] storing a specified number of last inserted elements.
  114. * Efficient fixed capacity ['FIFO (First In, First Out)],
  115. * Efficient fixed capacity ['LIFO (Last In, First Out)] queue which removes the oldest (inserted as first) elements when full.
  116. [endsect] [/section:rationale Rationale]
  117. [section:implementation Implementation ]
  118. The following paragraphs describe issues that had to be considered during the implementation of the circular_buffer:
  119. [h3 Thread-Safety]
  120. The thread-safety of the __cb is the same as the thread-safety of containers in most STL implementations.
  121. This means the __cb is not fully thread-safe.
  122. The thread-safety is guaranteed only in the sense that simultaneous accesses
  123. to distinct instances of the __cb are safe,
  124. and simultaneous read accesses to a shared __cb are safe.
  125. If multiple threads access a single __cb,
  126. and at least one of the threads may potentially write,
  127. then the user is responsible for ensuring mutual exclusion between the threads during the container accesses.
  128. The mutual exclusion between the threads can be achieved by wrapping
  129. operations of the underlying __cb with a lock acquisition and release.
  130. (See the Bounded Buffer example code at [@boost:libs/circular_buffer/example/circular_buffer_bound_example.cpp circular_buffer_bound_example.cpp])
  131. [h3 Overwrite Operation]
  132. Overwrite operation occurs when an element is inserted into a full __cb -
  133. the old element is being overwritten by the new one.
  134. There was a discussion what exactly "overwriting of an element" means during the formal review.
  135. It may be either a destruction of the original element and
  136. a consequent inplace construction of a new element
  137. or it may be an assignment of a new element into an old one.
  138. The __cb implements assignment because it is more effective.
  139. From the point of business logic of a stored element,
  140. the destruction/construction operation and assignment usually mean the same.
  141. However, in very rare cases (if in any) they may differ.
  142. If there is a requirement for elements to be destructed/constructed instead of being assigned,
  143. consider implementing a wrapper of the element which would implement the assign operator,
  144. and store the wrappers instead.
  145. It is necessary to note that storing such wrappers has a drawback.
  146. The destruction/construction will be invoked on every assignment of the wrapper -
  147. not only when a wrapper is being overwritten (when the buffer is full)
  148. but also when the stored wrappers are being shifted
  149. (e.g. as a result of insertion into the middle of container).
  150. [h3 Writing to a Full Buffer]
  151. There are several options how to cope if a data source produces more data than can fit in the fixed-sized buffer:
  152. * Inform the data source to wait until there is room in the buffer (e.g. by throwing an overflow exception).
  153. * If the oldest data is the most important, ignore new data from the source until there is room in the buffer again.
  154. * If the latest data is the most important, write over the oldest data.
  155. * Let the producer to be responsible for checking the size of the buffer prior writing into it.
  156. It is apparent that the __cb implements the third option.
  157. But it may be less apparent it does not implement any other option -
  158. especially the first two.
  159. One can get an impression that the __cb should implement first three options
  160. and offer a mechanism of choosing among them. This impression is wrong.
  161. The __cb was designed and optimized to be circular
  162. (which means overwriting the oldest data when full).
  163. If such a controlling mechanism had been enabled,
  164. it would just complicate the matters
  165. and the usage of the __cb would be probably less straightforward.
  166. Moreover, the first two options (and the fourth option as well)
  167. do not require the buffer to be circular at all.
  168. If there is a need for the first or second option, consider implementing an adaptor of e.g. std::vector.
  169. In this case the __cb is not suitable for adapting, because,
  170. contrary to std::vector, it bears an overhead for its circular behaviour.
  171. [h3 Reading/Removing from an Empty Buffer]
  172. When reading or removing an element from an empty buffer,
  173. the buffer should be able to notify the data consumer
  174. (e.g. by throwing underflow exception) that there are no elements stored in it.
  175. The __cb does not implement such a behaviour for two reasons:
  176. * It would introduce a performance overhead.
  177. * No other std container implements it this way.
  178. It is considered to be a bug to read or remove an element
  179. (e.g. by calling [memberref boost::circular_buffer::front() front()]
  180. or [memberref boost::circular_buffer::pop_back() pop_back()])
  181. from an empty std container and from an empty __cb as well.
  182. The data consumer has to test if the container is not empty before reading/removing from it by testing
  183. [memberref boost::circular_buffer::empty empty()].
  184. However, when reading from the __cb,
  185. there is an option to rely on the [memberref boost::circular_buffer::at() at()]
  186. method which throws an exception when the index is out of range.
  187. [h3 Iterator Invalidation]
  188. An iterator is usually considered to be invalidated if an element,
  189. the iterator pointed to, had been removed or overwritten by an another element.
  190. This definition is enforced by the Debug Support and is documented for every method.
  191. However, some applications utilizing __cb may require less strict definition:
  192. an iterator is invalid only if it points to an uninitialized memory.
  193. Consider following example:
  194. [import ../example/circular_buffer_iter_example.cpp]
  195. [circular_buffer_iter_example_1]
  196. The iterator does not point to the original element any more
  197. (and is considered to be invalid from the "strict" point of view)
  198. but it still points to the same valid place in the memory.
  199. This "soft" definition of iterator invalidation is supported by the __cb
  200. but should be considered as an implementation detail rather than a full-fledged feature.
  201. The rules when the iterator is still valid can be inferred from the code in
  202. [@boost:libs/circular_buffer/test/soft_iterator_invalidation.cpp soft_iterator_invalidation.cpp].
  203. [h3 Move emulation and rvalues]
  204. Since Boost 1.54.0 support for move semantics was implemented using
  205. the [@boost:libs/move/index.html Boost.Move] library.
  206. If rvalue references are available __cb will use them, but if not it uses a close,
  207. but imperfect emulation. On such compilers:
  208. * Non-copyable objects can be stored in the containers.
  209. They can be constructed in place using `emplace`, or if they support
  210. Boost.Move, moved into place.
  211. * The containers themselves are not movable.
  212. * Argument forwarding is not perfect.
  213. __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;
  214. or if the value type has no copy constructor.
  215. Some methods won't use move constructor for the value type at all, if the constructor throws. This is
  216. required for data consistency and avoidance of situations, when aftrer an exception __cb
  217. contains moved away objects along with the good ones.
  218. 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.
  219. There you'll find information about how to make constructor of class noexcept and how to make a non-copyable
  220. class in C++03 and C++98.
  221. Performance of __cb will *greatly improve* if value type has noexcept move constructor and noexcept move assignment.
  222. [h3 Exceptions of move_if_noexcept(T&)]
  223. Reference documentation of the __cb contains notes like "Throws: See Exceptions of `move_if_noexcept(T&)`".
  224. That note means the following: `move_if_noexcept(T& value)` does not throws exceptions at all, but it returns
  225. `value` as rvalue reference only if class `T` have noexcept move constructor and noexcept move assignment operator;
  226. or if it has no copy constructor. Otherwise `move_if_noexcept(T& value)` returns `value` as const reference.
  227. This leads us to the following situation:
  228. * If `value` has a noexcept move constructor and noexcept move assignment operator, then no exceptions will be thrown at all.
  229. * If `value` has a throwing move constructor and some copy constructor, then method may throw exceptions of copy constructor.
  230. * If `value` has no copy constructor, then method may throw exceptions of move constructor.
  231. `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.
  232. [h3 Caveats]
  233. The __cb should not be used for storing pointers to dynamically allocated objects.
  234. When a circular buffer becomes full, further insertion will overwrite the stored pointers
  235. - resulting in a [*memory leak]. One recommend alternative is the use of smart pointers, for example
  236. [@http://www.boost.org/doc/libs/1_53_0/libs/smart_ptr/smart_ptr.htm Boost Smart pointers].
  237. [@http://en.wikipedia.org/wiki/Std::auto_ptr std::auto_ptr]
  238. [caution Any container of `std::auto_ptr` is considered particularly hazardous.]
  239. [tip Never create a circular buffer of `std::auto_ptr`.
  240. Refer to Scott Meyers' excellent book Effective STL for a detailed discussion.
  241. (Meyers S., Effective STL: 50 Specific Ways to Improve Your Use of the Standard Template Library.
  242. Addison-Wesley, 2001.)
  243. ]
  244. While internals of a __cb are circular, [*iterators are not].
  245. Iterators of a __cb are only valid for the range `\[begin(), end()\]`,
  246. so for example: iterators `(begin() - 1)` and `(end() + 1)` are both invalid.
  247. [h3 Debug Support]
  248. In order to help a programmer to avoid and find common bugs,
  249. the __cb can be enabled to provide a kind of debug support.
  250. When the debugging functionality is enabled, the __cb maintains a list of valid iterators.
  251. As soon as any element gets destroyed all iterators pointing to this element
  252. are removed from this list and explicitly invalidated (an invalidation flag is set).
  253. The debug support also consists of many assertions (`BOOST_ASSERT` macros)
  254. which ensure the __cb and its iterators are used in the correct manner at runtime.
  255. In case an invalid iterator is used, the assertion will report an error.
  256. The connection of explicit iterator invalidation and assertions
  257. makes a very robust debug technique which catches most of the errors.
  258. Moreover, the uninitialized memory allocated by __cb is filled with the value `0xcc` in the debug mode.
  259. When debugging the code, this can help the programmer to recognize the initialized memory from the uninitialized.
  260. For details refer the source code [@boost:boost/circular_buffer/debug.hpp circular_buffer/debug.hpp].
  261. [caution Since the debugging code makes __cb and its iterators more interconnected, thread safety guarantees of __cb
  262. are different when debug support is enabled. In addition to the container itself, all iterators tracked by the container
  263. (including any copies thereof) must be protected from concurrent access. In particular, this includes copying, destroying or
  264. obtaining iterators from the container, even if for read-only access.]
  265. The debug support is disabled by default. To enable it, one has to define `BOOST_CB_ENABLE_DEBUG` macro with the value of 1
  266. while compiling the code using __cb.
  267. [h3 Compatibility with Interprocess library]
  268. The __cb is compatible with the [@boost:libs/interprocess/index.html Boost.Interprocess]
  269. [/ This should be in @boost:libs/interprocess/doc/index.html ]
  270. library used for interprocess communication.
  271. Considering that the circular_buffer's debug support relies on 'raw' pointers
  272. (which is not permitted by the Interprocess library)
  273. the code has to compiled with debug support disabled (i.e. with `BOOST_CB_ENABLE_DEBUG` macro not defined or defined to 0).
  274. Not doing that will cause the compilation to fail.
  275. [endsect] [/section:implementation Implementation ]
  276. [section:examples More Examples]
  277. [h3 Summing all the values in a circular buffer]
  278. [import ../example/circular_buffer_sum_example.cpp]
  279. [circular_buffer_sum_example_1]
  280. [/circular_buffer_example_output - there is no output for this example]
  281. The __cb has a capacity of three `int`.
  282. Therefore, the size of the buffer will never exceed three.
  283. The `std::accumulate` algorithm evaluates the sum of the stored elements.
  284. The semantics of the __cb can be inferred from the assertions.
  285. You can see the full example code at [@boost:libs/circular_buffer/example/circular_buffer_sum_example.cpp circular_buffer_sum_example.cpp].
  286. [h3 Bounded Buffer Example]
  287. The bounded buffer is normally used in a producer-consumer mode:
  288. producer threads produce items and store them in the container
  289. and consumer threads remove these items and process them.
  290. The bounded buffer has to guarantee that
  291. * producers do not insert items into the container when the container is full,
  292. * consumers do not try to remove items when the container is empty,
  293. * each produced item is consumed by exactly one consumer.
  294. [import ../example/circular_buffer_bound_example.cpp]
  295. [circular_buffer_bound_example_1]
  296. [/ there is no output for this example]
  297. The bounded_buffer relies on [@boost:/doc/html/thread.html Boost.Thread]
  298. and [@boost:libs/bind/index.html Boost.Bind] libraries
  299. and [@boost:libs/utility/call_traits.htm Boost.call_traits utility].
  300. The [memberref boost::circular_buffer::push_front() push_front()]
  301. method is called by the producer thread in order to insert a new item into the buffer.
  302. The method locks the mutex and waits until there is a space for the new item.
  303. (The mutex is unlocked during the waiting stage and has to be regained when the condition is met.)
  304. If there is a space in the buffer available,
  305. the execution continues and the method inserts the item at the end of the __cb.
  306. Then it increments the number of unread items and unlocks the mutex
  307. (in case an exception is thrown before the mutex is unlocked,
  308. the mutex is unlocked automatically by the destructor of the scoped_lock).
  309. At last the method notifies one of the consumer threads
  310. waiting for a new item to be inserted into the buffer.
  311. The [memberref boost::circular_buffer::pop_back() pop_back()]
  312. method is called by the consumer thread in order to read the next item from the buffer.
  313. The method locks the mutex and waits until there is an unread item in the buffer.
  314. If there is at least one unread item,
  315. the method decrements the number of unread items and reads the next item from the __cb.
  316. Then it unlocks the mutex and notifies one of the producer threads
  317. waiting for the buffer to free a space for the next item.
  318. The `bounded buffer::pop_back()`
  319. method [*does not remove the item] but the item is left
  320. in the circular_buffer which then [*replaces it with a new one]
  321. (inserted by a producer) when the circular_buffer is full.
  322. This technique is more effective than removing the item
  323. explicitly by calling the [memberref boost::circular_buffer::pop_back() circular_buffer::pop_back()]
  324. method of the __cb.
  325. This claim is based on the assumption that an assignment (replacement)
  326. of a new item into an old one is more effective than a destruction
  327. (removal) of an old item and a consequent inplace construction (insertion) of a new item.
  328. For comparison of bounded buffers based on different containers compile and
  329. run [@boost:libs/circular_buffer/test/bounded_buffer_comparison.cpp bounded_buffer_comparison.cpp].
  330. The test should reveal the bounded buffer based on the __cb is most effective
  331. closely followed by the `std::deque` based bounded buffer.
  332. (In reality, the result may differ sometimes because the test
  333. is always affected by external factors such as immediate CPU load.)
  334. [import ../test/bounded_buffer_comparison.cpp]
  335. You can see the full test code at [@boost:libs/circular_buffer/test/bounded_buffer_comparison.cpp bounded_buffer_comparison.cpp],
  336. and an example of output is [bounded_buffer_comparison_output].
  337. [endsect] [/section:examples More examples]
  338. [section:headers Header Files]
  339. The circular buffer library is defined in the file [@boost:boost/circular_buffer.hpp circular_buffer.hpp].
  340. #include <boost/circular_buffer.hpp>
  341. (There is also a forward declaration for the __cb
  342. in the header file [@boost:boost/circular_buffer_fwd.hpp circular_buffer_fwd.hpp]).
  343. The __cb is defined in the file [@boost:boost/circular_buffer/base.hpp base.hpp].
  344. The __cbso is defined in the file [@boost:boost/circular_buffer/space_optimized.hpp space_optimized.hpp].
  345. [endsect] [/section:headers Header Files]
  346. [section:concepts Modelled Concepts]
  347. [@https://www.boost.org/sgi/stl/RandomAccessContainer.html Random Access Container],
  348. [@https://www.boost.org/sgi/stl/FrontInsertionSequence.html Front Insertion Sequence], and
  349. [@https://www.boost.org/sgi/stl/BackInsertionSequence.html Back Insertion sequence]
  350. [endsect] [/section:concepts Modelled Concepts]
  351. [section:template_params Template Parameters]
  352. [table:templ Template parameter requirements
  353. [[parameter] [Requirements]]
  354. [[T] [The type of the elements stored in the circular_buffer.
  355. The T has to be [@boost:libs/utility/Assignable.html Assignable]
  356. and [@boost:libs/utility/CopyConstructible.html CopyConstructible].
  357. Moreover T has to be [@https://www.boost.org/sgi/stl/DefaultConstructible.html DefaultConstructible]
  358. if supplied as a default parameter when invoking some of the circular_buffer's methods,
  359. e.g. `insert(iterator pos, const value_type& item = value_type())`.
  360. And [@https://www.boost.org/sgi/stl/EqualityComparable.html EqualityComparable]
  361. and/or [@boost:libs/utility/LessThanComparable.html LessThanComparable]
  362. if the circular_buffer will be compared with another container.]]
  363. [[Alloc] [The allocator type used for all internal memory management.
  364. The Alloc has to meet the allocator requirements imposed by STL.]]
  365. ]
  366. [endsect] [/section:template_params Template Parameters]
  367. [section:tickets Trac Tickets]
  368. Report and view bugs and features by adding a ticket at [@https://svn.boost.org/trac/boost Boost.Trac].
  369. Existing open tickets for this library alone can be viewed
  370. [@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].
  371. Existing tickets for this library - including closed ones - can be viewed
  372. [@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].
  373. Type: Bugs
  374. [@https://svn.boost.org/trac/boost/ticket/4100 #4100] Some boost classes have sizeof that depends on NDEBUG.
  375. [@https://svn.boost.org/trac/boost/ticket/5362 #5362] circular_buffer does not compile with BOOST_NO_EXCEPTIONS.
  376. [@https://svn.boost.org/trac/boost/ticket/6277 #6277] Checked iterators are not threadsafe.
  377. [@https://svn.boost.org/trac/boost/ticket/6747 #6747] Circular_Buffer / Bounded_Buffer inside Template class problem.
  378. [@https://svn.boost.org/trac/boost/ticket/7025 #7025] circular buffer reports warning: " type qualifiers ignored on function return type" while compile.
  379. [@https://svn.boost.org/trac/boost/ticket/7950 #7950] Eliminate W4-warnings under VS2005.
  380. [@https://svn.boost.org/trac/boost/ticket/8012 #8012] Inconsistency in `linearize()`.
  381. [@https://svn.boost.org/trac/boost/ticket/8438 #8438] `vector` & __cb storage misbehave when using compiler optimizations.
  382. Type: Feature Requests
  383. [@https://svn.boost.org/trac/boost/ticket/5511 #5511] Documentation needs some improvement.
  384. [@https://svn.boost.org/trac/boost/ticket/7888 #7888] circular_buffer should support move semantics.
  385. Type: Patches
  386. [@https://svn.boost.org/trac/boost/ticket/8032 #8032] Warning fixes in circular_buffer.
  387. [endsect] [/section:tickets Trac Tickets]
  388. [section:release Release Notes]
  389. [h4 Boost 1.56]
  390. * C++11 allocator model support implemented by Glen Fernandes.
  391. [h4 Boost 1.55]
  392. * Documentation refactored by Paul A. Bristow using Quickbook, Doxygen and Autoindexing.
  393. * Rvalue references emulation added by Antony Polukhin using Boost.Move.
  394. [h4 Boost 1.42]
  395. * 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.
  396. * 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).
  397. [h4 Boost 1.37]
  398. *Added new methods is_linearized() and rotate(const_iterator).
  399. * Fixed bugs:
  400. [@https://svn.boost.org/trac/boost/ticket/1987 #1987] Patch to make circular_buffer.hpp #includes absolute.
  401. [@https://svn.boost.org/trac/boost/ticket/1852 #1852] Copy constructor does not copy capacity.
  402. [h4 Boost 1.36]
  403. * Changed behaviour of the circular_buffer(const allocator_type&) constructor.
  404. Since this version the constructor does not allocate any memory and both capacity and size are set to zero.
  405. * Fixed bug:
  406. [@https://svn.boost.org/trac/boost/ticket/191 #1919] Default constructed circular buffer throws std::bad_alloc.
  407. [h4 Boost 1.35]
  408. * Initial release.
  409. [endsect] [/section:release Release Notes]
  410. [section:acknowledgements Acknowledgements]
  411. Thomas Witt in 2002 produced a prototype called cyclic buffer.
  412. The circular_buffer has a short history. Its first version was a std::deque adaptor.
  413. This container was not very effective because of many reallocations when inserting/removing an element.
  414. Thomas Wenish did a review of this version and
  415. motivated me to create a circular buffer which allocates memory at once when created.
  416. The second version adapted `std::vector` but it has been abandoned soon
  417. because of limited control over iterator invalidation.
  418. The current version is a full-fledged STL compliant container.
  419. Pavel Vozenilek did a thorough review of this version and came with many good ideas and improvements.
  420. The idea of the space optimized circular buffer has been introduced by Pavel Vozenilek.
  421. Also, I would like to thank Howard Hinnant, Nigel Stewart and everyone
  422. who participated at the formal review for valuable comments and ideas.
  423. Paul A. Bristow refactored the documentation in 2013 to use the full power of Quickbook, Doxygen and Autoindexing.
  424. [endsect] [/section:acknowledgements Acknowledgements]
  425. [section:version_id Documentation Version Info]
  426. Last edit to Quickbook file __FILENAME__ was at __TIME__ on __DATE__.
  427. [tip This should appear on the pdf version
  428. (but may be redundant on a html version where the last edit date is on the first (home) page).]
  429. [warning Home page "Last revised" is GMT, not local time. Last edit date is local time.]
  430. [/See also Adobe Reader pdf File Properties for creation date, and PDF producer, version and page count.]
  431. [endsect] [/section:version_id Version Info]
  432. [xinclude autodoc.xml] [/ Using Doxygen reference documentation.]
  433. [/ The position of this in the Quickbook determines the location of the Doxygen references section.]
  434. [/ Index(es) should be invoked in the main module, not within a section.]
  435. '''
  436. <index/>
  437. '''
  438. [/ circular_buffer.qbk
  439. Copyright 2013 Paul A. Bristow.
  440. Copyright 2003-2008 Jan Gaspar.
  441. Distributed under the Boost Software License, Version 1.0.
  442. (See accompanying file LICENSE_1_0.txt or copy at
  443. http://www.boost.org/LICENSE_1_0.txt).
  444. ]