annotate DEPENDENCIES/generic/include/boost/circular_buffer/space_optimized.hpp @ 16:2665513ce2d3

Add boost headers
author Chris Cannam
date Tue, 05 Aug 2014 11:11:38 +0100
parents
children c530137014c0
rev   line source
Chris@16 1 // Implementation of the circular buffer adaptor.
Chris@16 2
Chris@16 3 // Copyright (c) 2003-2008 Jan Gaspar
Chris@16 4 // Copyright (c) 2013 Paul A. Bristow // Doxygen comments changed for new version of documentation.
Chris@16 5 // Copyright (c) 2013 Antony Polukhin // Move semantics implementation.
Chris@16 6
Chris@16 7 // Use, modification, and distribution is subject to the Boost Software
Chris@16 8 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
Chris@16 9 // http://www.boost.org/LICENSE_1_0.txt)
Chris@16 10
Chris@16 11 #if !defined(BOOST_CIRCULAR_BUFFER_SPACE_OPTIMIZED_HPP)
Chris@16 12 #define BOOST_CIRCULAR_BUFFER_SPACE_OPTIMIZED_HPP
Chris@16 13
Chris@16 14 #if defined(_MSC_VER) && _MSC_VER >= 1200
Chris@16 15 #pragma once
Chris@16 16 #endif
Chris@16 17
Chris@16 18 #include <boost/type_traits/is_same.hpp>
Chris@16 19 #include <boost/detail/workaround.hpp>
Chris@16 20
Chris@16 21 namespace boost {
Chris@16 22
Chris@16 23 /*!
Chris@16 24 \class circular_buffer_space_optimized
Chris@16 25 \brief Space optimized circular buffer container adaptor.
Chris@16 26 <code>T</code> must be a copyable class or must have an noexcept move constructor
Chris@16 27 and move assignment operator.
Chris@16 28 */
Chris@16 29 template <class T, class Alloc>
Chris@16 30 class circular_buffer_space_optimized :
Chris@16 31 /*! \cond */
Chris@16 32 #if BOOST_CB_ENABLE_DEBUG
Chris@16 33 public
Chris@16 34 #endif
Chris@16 35 /*! \endcond */
Chris@16 36 circular_buffer<T, Alloc> {
Chris@16 37 public:
Chris@16 38 // Typedefs
Chris@16 39
Chris@16 40 typedef typename circular_buffer<T, Alloc>::value_type value_type;
Chris@16 41 typedef typename circular_buffer<T, Alloc>::pointer pointer;
Chris@16 42 typedef typename circular_buffer<T, Alloc>::const_pointer const_pointer;
Chris@16 43 typedef typename circular_buffer<T, Alloc>::reference reference;
Chris@16 44 typedef typename circular_buffer<T, Alloc>::const_reference const_reference;
Chris@16 45 typedef typename circular_buffer<T, Alloc>::size_type size_type;
Chris@16 46 typedef typename circular_buffer<T, Alloc>::difference_type difference_type;
Chris@16 47 typedef typename circular_buffer<T, Alloc>::allocator_type allocator_type;
Chris@16 48 typedef typename circular_buffer<T, Alloc>::const_iterator const_iterator;
Chris@16 49 typedef typename circular_buffer<T, Alloc>::iterator iterator;
Chris@16 50 typedef typename circular_buffer<T, Alloc>::const_reverse_iterator const_reverse_iterator;
Chris@16 51 typedef typename circular_buffer<T, Alloc>::reverse_iterator reverse_iterator;
Chris@16 52 typedef typename circular_buffer<T, Alloc>::array_range array_range;
Chris@16 53 typedef typename circular_buffer<T, Alloc>::const_array_range const_array_range;
Chris@16 54 typedef typename circular_buffer<T, Alloc>::param_value_type param_value_type;
Chris@16 55 typedef typename circular_buffer<T, Alloc>::rvalue_type rvalue_type;
Chris@16 56 //typedef typename circular_buffer<T, Alloc>::return_value_type return_value_type;
Chris@16 57
Chris@16 58 /* <pre> is not passed through to html or pdf. So <br> is used in code section below. Ugly :-(
Chris@16 59 Ideally want a link to capacity_control, but this would require include details
Chris@16 60 and this would expose all the functions in details.
Chris@16 61 There must be a better way of doing this.
Chris@16 62 */
Chris@16 63
Chris@16 64 /*! Capacity controller of the space optimized circular buffer.
Chris@16 65
Chris@16 66 \see capacity_control in details.hpp.
Chris@16 67 <p>
Chris@16 68 <code>
Chris@16 69 class capacity_control<br>
Chris@16 70 {<br>
Chris@16 71 size_type m_capacity; // Available capacity.<br>
Chris@16 72 size_type m_min_capacity; // Minimum capacity.<br>
Chris@16 73 public:<br>
Chris@16 74 capacity_control(size_type capacity, size_type min_capacity = 0)<br>
Chris@16 75 : m_capacity(capacity), m_min_capacity(min_capacity)<br>
Chris@16 76 {};<br>
Chris@16 77 size_type %capacity() const { return m_capacity; }<br>
Chris@16 78 size_type min_capacity() const { return m_min_capacity; }<br>
Chris@16 79 operator size_type() const { return m_capacity; }<br>
Chris@16 80 };<br>
Chris@16 81 </code>
Chris@16 82 </p>
Chris@16 83
Chris@16 84
Chris@16 85 <p>Always
Chris@16 86 <code>capacity >= min_capacity</code>.
Chris@16 87 </p>
Chris@16 88 <p>
Chris@16 89 The <code>capacity()</code> represents the capacity
Chris@16 90 of the <code>circular_buffer_space_optimized</code> and
Chris@16 91 the <code>min_capacity()</code> determines the minimal allocated size of its internal buffer.
Chris@16 92 </p>
Chris@16 93 <p>The converting constructor of the <code>capacity_control</code> allows implicit conversion from
Chris@16 94 <code>size_type</code>-like types which ensures compatibility of creating an instance of the
Chris@16 95 <code>circular_buffer_space_optimized</code> with other STL containers.
Chris@16 96
Chris@16 97 On the other hand the operator <code>%size_type()</code>
Chris@16 98 provides implicit conversion to the <code>size_type</code> which allows to treat the
Chris@16 99 capacity of the <code>circular_buffer_space_optimized</code> the same way as in the
Chris@16 100 <code>circular_buffer</a></code>.
Chris@16 101 </p>
Chris@16 102 */
Chris@16 103 typedef cb_details::capacity_control<size_type> capacity_type;
Chris@16 104
Chris@16 105 // Inherited
Chris@16 106
Chris@16 107 using circular_buffer<T, Alloc>::get_allocator;
Chris@16 108 using circular_buffer<T, Alloc>::begin;
Chris@16 109 using circular_buffer<T, Alloc>::end;
Chris@16 110 using circular_buffer<T, Alloc>::rbegin;
Chris@16 111 using circular_buffer<T, Alloc>::rend;
Chris@16 112 using circular_buffer<T, Alloc>::at;
Chris@16 113 using circular_buffer<T, Alloc>::front;
Chris@16 114 using circular_buffer<T, Alloc>::back;
Chris@16 115 using circular_buffer<T, Alloc>::array_one;
Chris@16 116 using circular_buffer<T, Alloc>::array_two;
Chris@16 117 using circular_buffer<T, Alloc>::linearize;
Chris@16 118 using circular_buffer<T, Alloc>::is_linearized;
Chris@16 119 using circular_buffer<T, Alloc>::rotate;
Chris@16 120 using circular_buffer<T, Alloc>::size;
Chris@16 121 using circular_buffer<T, Alloc>::max_size;
Chris@16 122 using circular_buffer<T, Alloc>::empty;
Chris@16 123
Chris@16 124 #if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
Chris@16 125 reference operator [] (size_type n) { return circular_buffer<T, Alloc>::operator[](n); }
Chris@16 126 const_reference operator [] (size_type n) const { return circular_buffer<T, Alloc>::operator[](n); }
Chris@16 127 #else
Chris@16 128 using circular_buffer<T, Alloc>::operator[];
Chris@16 129 #endif
Chris@16 130
Chris@16 131 private:
Chris@16 132 // Member variables
Chris@16 133
Chris@16 134 //! The capacity controller of the space optimized circular buffer.
Chris@16 135 capacity_type m_capacity_ctrl;
Chris@16 136
Chris@16 137 public:
Chris@16 138 // Overridden
Chris@16 139
Chris@16 140 //! Is the <code>circular_buffer_space_optimized</code> full?
Chris@16 141 /*!
Chris@16 142 \return <code>true</code> if the number of elements stored in the <code>circular_buffer_space_optimized</code>
Chris@16 143 equals the capacity of the <code>circular_buffer_space_optimized</code>; <code>false</code> otherwise.
Chris@16 144 \throws Nothing.
Chris@16 145 \par Exception Safety
Chris@16 146 No-throw.
Chris@16 147 \par Iterator Invalidation
Chris@16 148 Does not invalidate any iterators.
Chris@16 149 \par Complexity
Chris@16 150 Constant (in the size of the <code>circular_buffer_space_optimized</code>).
Chris@16 151 \sa <code>empty()</code>
Chris@16 152 */
Chris@16 153 bool full() const BOOST_NOEXCEPT { return m_capacity_ctrl == size(); }
Chris@16 154
Chris@16 155 /*! \brief Get the maximum number of elements which can be inserted into the
Chris@16 156 <code>circular_buffer_space_optimized</code> without overwriting any of already stored elements.
Chris@16 157 \return <code>capacity().%capacity() - size()</code>
Chris@16 158 \throws Nothing.
Chris@16 159 \par Exception Safety
Chris@16 160 No-throw.
Chris@16 161 \par Iterator Invalidation
Chris@16 162 Does not invalidate any iterators.
Chris@16 163 \par Complexity
Chris@16 164 Constant (in the size of the <code>circular_buffer_space_optimized</code>).
Chris@16 165 \sa <code>capacity()</code>, <code>size()</code>, <code>max_size()</code>
Chris@16 166 */
Chris@16 167 size_type reserve() const BOOST_NOEXCEPT { return m_capacity_ctrl - size(); }
Chris@16 168
Chris@16 169 //! Get the capacity of the <code>circular_buffer_space_optimized</code>.
Chris@16 170 /*!
Chris@16 171 \return The capacity controller representing the maximum number of elements which can be stored in the
Chris@16 172 <code>circular_buffer_space_optimized</code> and the minimal allocated size of the internal buffer.
Chris@16 173 \throws Nothing.
Chris@16 174 \par Exception Safety
Chris@16 175 No-throw.
Chris@16 176 \par Iterator Invalidation
Chris@16 177 Does not invalidate any iterators.
Chris@16 178 \par Complexity
Chris@16 179 Constant (in the size of the <code>circular_buffer_space_optimized</code>).
Chris@16 180 \sa <code>reserve()</code>, <code>size()</code>, <code>max_size()</code>,
Chris@16 181 <code>set_capacity(const capacity_type&)</code>
Chris@16 182 */
Chris@16 183 const capacity_type& capacity() const BOOST_NOEXCEPT { return m_capacity_ctrl; }
Chris@16 184
Chris@16 185 #if defined(BOOST_CB_TEST)
Chris@16 186
Chris@16 187 // Return the current capacity of the adapted circular buffer.
Chris@16 188 /*
Chris@16 189 \note This method is not intended to be used directly by the user.
Chris@16 190 It is defined only for testing purposes.
Chris@16 191 */
Chris@16 192 size_type internal_capacity() const BOOST_NOEXCEPT { return circular_buffer<T, Alloc>::capacity(); }
Chris@16 193
Chris@16 194 #endif // #if defined(BOOST_CB_TEST)
Chris@16 195
Chris@16 196 /*! \brief Change the capacity (and the minimal guaranteed amount of allocated memory) of the
Chris@16 197 <code>circular_buffer_space_optimized</code>.
Chris@16 198 \post <code>capacity() == capacity_ctrl \&\& size() \<= capacity_ctrl.capacity()</code><br><br>
Chris@16 199 If the current number of elements stored in the <code>circular_buffer_space_optimized</code> is greater
Chris@16 200 than the desired new capacity then number of <code>[size() - capacity_ctrl.capacity()]</code> <b>last</b>
Chris@16 201 elements will be removed and the new size will be equal to <code>capacity_ctrl.capacity()</code>.<br><br>
Chris@16 202 If the current number of elements stored in the <code>circular_buffer_space_optimized</code> is lower
Chris@16 203 than the new capacity then the amount of allocated memory in the internal buffer may be accommodated as
Chris@16 204 necessary but it will never drop below <code>capacity_ctrl.min_capacity()</code>.
Chris@16 205 \param capacity_ctrl The new capacity controller.
Chris@16 206 \throws "An allocation error" if memory is exhausted, (<code>std::bad_alloc</code> if the standard allocator is
Chris@16 207 used).
Chris@16 208 Whatever <code>T::T(const T&)</code> throws or nothing if <code>T::T(T&&)</code> is noexcept.
Chris@16 209 \par Exception Safety
Chris@16 210 Strong.
Chris@16 211 \par Iterator Invalidation
Chris@16 212 Invalidates all iterators pointing to the <code>circular_buffer_space_optimized</code> (except iterators
Chris@16 213 equal to <code>end()</code>).
Chris@16 214 \par Complexity
Chris@16 215 Linear (in <code>min[size(), capacity_ctrl.%capacity()]</code>).
Chris@16 216 \note To explicitly clear the extra allocated memory use the <b>shrink-to-fit</b> technique:<br><br>
Chris@16 217 <code>%boost::%circular_buffer_space_optimized\<int\> cb(1000);<br>
Chris@16 218 ...<br>
Chris@16 219 %boost::%circular_buffer_space_optimized\<int\>(cb).swap(cb);</code><br><br>
Chris@16 220 For more information about the shrink-to-fit technique in STL see
Chris@16 221 <a href="http://www.gotw.ca/gotw/054.htm">http://www.gotw.ca/gotw/054.htm</a>.
Chris@16 222 \sa <code>rset_capacity(const capacity_type&)</code>,
Chris@16 223 <code>\link resize() resize(size_type, const_reference)\endlink</code>
Chris@16 224 */
Chris@16 225 void set_capacity(const capacity_type& capacity_ctrl) {
Chris@16 226 m_capacity_ctrl = capacity_ctrl;
Chris@16 227 if (capacity_ctrl < size()) {
Chris@16 228 iterator e = end();
Chris@16 229 circular_buffer<T, Alloc>::erase(e - (size() - capacity_ctrl), e);
Chris@16 230 }
Chris@16 231 adjust_min_capacity();
Chris@16 232 }
Chris@16 233
Chris@16 234 //! Change the size of the <code>circular_buffer_space_optimized</code>.
Chris@16 235 /*!
Chris@16 236 \post <code>size() == new_size \&\& capacity().%capacity() >= new_size</code><br><br>
Chris@16 237 If the new size is greater than the current size, copies of <code>item</code> will be inserted at the
Chris@16 238 <b>back</b> of the of the <code>circular_buffer_space_optimized</code> in order to achieve the desired
Chris@16 239 size. In the case the resulting size exceeds the current capacity the capacity will be set to
Chris@16 240 <code>new_size</code>.<br><br>
Chris@16 241 If the current number of elements stored in the <code>circular_buffer_space_optimized</code> is greater
Chris@16 242 than the desired new size then number of <code>[size() - new_size]</code> <b>last</b> elements will be
Chris@16 243 removed. (The capacity will remain unchanged.)<br><br>
Chris@16 244 The amount of allocated memory in the internal buffer may be accommodated as necessary.
Chris@16 245 \param new_size The new size.
Chris@16 246 \param item The element the <code>circular_buffer_space_optimized</code> will be filled with in order to gain
Chris@16 247 the requested size. (See the <i>Effect</i>.)
Chris@16 248 \throws "An allocation error" if memory is exhausted (<code>std::bad_alloc</code> if the standard allocator is
Chris@16 249 used).
Chris@16 250 Whatever <code>T::T(const T&)</code> throws.
Chris@16 251 \par Exception Safety
Chris@16 252 Basic.
Chris@16 253 \par Iterator Invalidation
Chris@16 254 Invalidates all iterators pointing to the <code>circular_buffer_space_optimized</code> (except iterators
Chris@16 255 equal to <code>end()</code>).
Chris@16 256 \par Complexity
Chris@16 257 Linear (in the new size of the <code>circular_buffer_space_optimized</code>).
Chris@16 258 \sa <code>\link rresize() rresize(size_type, const_reference)\endlink</code>,
Chris@16 259 <code>set_capacity(const capacity_type&)</code>
Chris@16 260 */
Chris@16 261 void resize(size_type new_size, param_value_type item = value_type()) {
Chris@16 262 if (new_size > size()) {
Chris@16 263 if (new_size > m_capacity_ctrl)
Chris@16 264 m_capacity_ctrl = capacity_type(new_size, m_capacity_ctrl.min_capacity());
Chris@16 265 insert(end(), new_size - size(), item);
Chris@16 266 } else {
Chris@16 267 iterator e = end();
Chris@16 268 erase(e - (size() - new_size), e);
Chris@16 269 }
Chris@16 270 }
Chris@16 271
Chris@16 272 /*! \brief Change the capacity (and the minimal guaranteed amount of allocated memory) of the
Chris@16 273 <code>circular_buffer_space_optimized</code>.
Chris@16 274 \post <code>capacity() == capacity_ctrl \&\& size() \<= capacity_ctrl</code><br><br>
Chris@16 275 If the current number of elements stored in the <code>circular_buffer_space_optimized</code> is greater
Chris@16 276 than the desired new capacity then number of <code>[size() - capacity_ctrl.capacity()]</code>
Chris@16 277 <b>first</b> elements will be removed and the new size will be equal to
Chris@16 278 <code>capacity_ctrl.capacity()</code>.<br><br>
Chris@16 279 If the current number of elements stored in the <code>circular_buffer_space_optimized</code> is lower
Chris@16 280 than the new capacity then the amount of allocated memory in the internal buffer may be accommodated as
Chris@16 281 necessary but it will never drop below <code>capacity_ctrl.min_capacity()</code>.
Chris@16 282 \param capacity_ctrl The new capacity controller.
Chris@16 283 \throws "An allocation error" if memory is exhausted (<code>std::bad_alloc</code> if the standard allocator is
Chris@16 284 used).
Chris@16 285 Whatever <code>T::T(const T&)</code> throws or nothing if <code>T::T(T&&)</code> is noexcept.
Chris@16 286 \par Exception Safety
Chris@16 287 Strong.
Chris@16 288 \par Iterator Invalidation
Chris@16 289 Invalidates all iterators pointing to the <code>circular_buffer_space_optimized</code> (except iterators
Chris@16 290 equal to <code>end()</code>).
Chris@16 291 \par Complexity
Chris@16 292 Linear (in <code>min[size(), capacity_ctrl.%capacity()]</code>).
Chris@16 293 \sa <code>set_capacity(const capacity_type&)</code>,
Chris@16 294 <code>\link rresize() rresize(size_type, const_reference)\endlink</code>
Chris@16 295 */
Chris@16 296 void rset_capacity(const capacity_type& capacity_ctrl) {
Chris@16 297 m_capacity_ctrl = capacity_ctrl;
Chris@16 298 if (capacity_ctrl < size()) {
Chris@16 299 iterator b = begin();
Chris@16 300 circular_buffer<T, Alloc>::rerase(b, b + (size() - capacity_ctrl));
Chris@16 301 }
Chris@16 302 adjust_min_capacity();
Chris@16 303 }
Chris@16 304
Chris@16 305 //! Change the size of the <code>circular_buffer_space_optimized</code>.
Chris@16 306 /*!
Chris@16 307 \post <code>size() == new_size \&\& capacity().%capacity() >= new_size</code><br><br>
Chris@16 308 If the new size is greater than the current size, copies of <code>item</code> will be inserted at the
Chris@16 309 <b>front</b> of the of the <code>circular_buffer_space_optimized</code> in order to achieve the desired
Chris@16 310 size. In the case the resulting size exceeds the current capacity the capacity will be set to
Chris@16 311 <code>new_size</code>.<br><br>
Chris@16 312 If the current number of elements stored in the <code>circular_buffer_space_optimized</code> is greater
Chris@16 313 than the desired new size then number of <code>[size() - new_size]</code> <b>first</b> elements will be
Chris@16 314 removed. (The capacity will remain unchanged.)<br><br>
Chris@16 315 The amount of allocated memory in the internal buffer may be accommodated as necessary.
Chris@16 316 \param new_size The new size.
Chris@16 317 \param item The element the <code>circular_buffer_space_optimized</code> will be filled with in order to gain
Chris@16 318 the requested size. (See the <i>Effect</i>.)
Chris@16 319 \throws "An allocation error" if memory is exhausted (<code>std::bad_alloc</code> if the standard allocator is
Chris@16 320 used).
Chris@16 321 Whatever <code>T::T(const T&)</code> throws.
Chris@16 322 \par Exception Safety
Chris@16 323 Basic.
Chris@16 324 \par Iterator Invalidation
Chris@16 325 Invalidates all iterators pointing to the <code>circular_buffer_space_optimized</code> (except iterators
Chris@16 326 equal to <code>end()</code>).
Chris@16 327 \par Complexity
Chris@16 328 Linear (in the new size of the <code>circular_buffer_space_optimized</code>).
Chris@16 329 \sa <code>\link resize() resize(size_type, const_reference)\endlink</code>,
Chris@16 330 <code>rset_capacity(const capacity_type&)</code>
Chris@16 331 */
Chris@16 332 void rresize(size_type new_size, param_value_type item = value_type()) {
Chris@16 333 if (new_size > size()) {
Chris@16 334 if (new_size > m_capacity_ctrl)
Chris@16 335 m_capacity_ctrl = capacity_type(new_size, m_capacity_ctrl.min_capacity());
Chris@16 336 rinsert(begin(), new_size - size(), item);
Chris@16 337 } else {
Chris@16 338 rerase(begin(), end() - new_size);
Chris@16 339 }
Chris@16 340 }
Chris@16 341
Chris@16 342 //! Create an empty space optimized circular buffer with zero capacity.
Chris@16 343 /*!
Chris@16 344 \post <code>capacity().%capacity() == 0 \&\& capacity().min_capacity() == 0 \&\& size() == 0</code>
Chris@16 345 \param alloc The allocator.
Chris@16 346 \throws Nothing.
Chris@16 347 \par Complexity
Chris@16 348 Constant.
Chris@16 349 \warning Since Boost version 1.36 the behaviour of this constructor has changed. Now it creates a space
Chris@16 350 optimized circular buffer with zero capacity.
Chris@16 351 */
Chris@16 352 explicit circular_buffer_space_optimized(const allocator_type& alloc = allocator_type()) BOOST_NOEXCEPT
Chris@16 353 : circular_buffer<T, Alloc>(0, alloc)
Chris@16 354 , m_capacity_ctrl(0) {}
Chris@16 355
Chris@16 356 //! Create an empty space optimized circular buffer with the specified capacity.
Chris@16 357 /*!
Chris@16 358 \post <code>capacity() == capacity_ctrl \&\& size() == 0</code><br><br>
Chris@16 359 The amount of allocated memory in the internal buffer is <code>capacity_ctrl.min_capacity()</code>.
Chris@16 360 \param capacity_ctrl The capacity controller representing the maximum number of elements which can be stored in
Chris@16 361 the <code>circular_buffer_space_optimized</code> and the minimal allocated size of the
Chris@16 362 internal buffer.
Chris@16 363 \param alloc The allocator.
Chris@16 364 \throws "An allocation error" if memory is exhausted (<code>std::bad_alloc</code> if the standard allocator is
Chris@16 365 used).
Chris@16 366 \par Complexity
Chris@16 367 Constant.
Chris@16 368 */
Chris@16 369 explicit circular_buffer_space_optimized(capacity_type capacity_ctrl,
Chris@16 370 const allocator_type& alloc = allocator_type())
Chris@16 371 : circular_buffer<T, Alloc>(capacity_ctrl.min_capacity(), alloc)
Chris@16 372 , m_capacity_ctrl(capacity_ctrl) {}
Chris@16 373
Chris@16 374 /*! \brief Create a full space optimized circular buffer with the specified capacity filled with
Chris@16 375 <code>capacity_ctrl.%capacity()</code> copies of <code>item</code>.
Chris@16 376 \post <code>capacity() == capacity_ctrl \&\& full() \&\& (*this)[0] == item \&\& (*this)[1] == item \&\& ...
Chris@16 377 \&\& (*this) [capacity_ctrl.%capacity() - 1] == item </code><br><br>
Chris@16 378 The amount of allocated memory in the internal buffer is <code>capacity_ctrl.capacity()</code>.
Chris@16 379 \param capacity_ctrl The capacity controller representing the maximum number of elements which can be stored in
Chris@16 380 the <code>circular_buffer_space_optimized</code> and the minimal allocated size of the
Chris@16 381 internal buffer.
Chris@16 382 \param item The element the created <code>circular_buffer_space_optimized</code> will be filled with.
Chris@16 383 \param alloc The allocator.
Chris@16 384 \throws "An allocation error" if memory is exhausted (<code>std::bad_alloc</code> if the standard allocator is
Chris@16 385 used).
Chris@16 386 \throws Whatever <code>T::T(const T&)</code> throws.
Chris@16 387 \par Complexity
Chris@16 388 Linear (in the <code>capacity_ctrl.%capacity()</code>).
Chris@16 389 */
Chris@16 390 circular_buffer_space_optimized(capacity_type capacity_ctrl, param_value_type item,
Chris@16 391 const allocator_type& alloc = allocator_type())
Chris@16 392 : circular_buffer<T, Alloc>(capacity_ctrl.capacity(), item, alloc)
Chris@16 393 , m_capacity_ctrl(capacity_ctrl) {}
Chris@16 394
Chris@16 395 /*! \brief Create a space optimized circular buffer with the specified capacity filled with <code>n</code> copies
Chris@16 396 of <code>item</code>.
Chris@16 397 \pre <code>capacity_ctrl.%capacity() >= n</code>
Chris@16 398 \post <code>capacity() == capacity_ctrl \&\& size() == n \&\& (*this)[0] == item \&\& (*this)[1] == item
Chris@16 399 \&\& ... \&\& (*this)[n - 1] == item</code><br><br>
Chris@16 400 The amount of allocated memory in the internal buffer is
Chris@16 401 <code>max[n, capacity_ctrl.min_capacity()]</code>.
Chris@16 402 \param capacity_ctrl The capacity controller representing the maximum number of elements which can be stored in
Chris@16 403 the <code>circular_buffer_space_optimized</code> and the minimal allocated size of the
Chris@16 404 internal buffer.
Chris@16 405 \param n The number of elements the created <code>circular_buffer_space_optimized</code> will be filled with.
Chris@16 406 \param item The element the created <code>circular_buffer_space_optimized</code> will be filled with.
Chris@16 407 \param alloc The allocator.
Chris@16 408 \throws "An allocation error" if memory is exhausted (<code>std::bad_alloc</code> if the standard allocator is
Chris@16 409 used).
Chris@16 410 Whatever <code>T::T(const T&)</code> throws.
Chris@16 411 \par Complexity
Chris@16 412 Linear (in the <code>n</code>).
Chris@16 413 */
Chris@16 414 circular_buffer_space_optimized(capacity_type capacity_ctrl, size_type n, param_value_type item,
Chris@16 415 const allocator_type& alloc = allocator_type())
Chris@16 416 : circular_buffer<T, Alloc>(init_capacity(capacity_ctrl, n), n, item, alloc)
Chris@16 417 , m_capacity_ctrl(capacity_ctrl) {}
Chris@16 418
Chris@16 419 #if BOOST_WORKAROUND(BOOST_MSVC, < 1300)
Chris@16 420
Chris@16 421 /*! \cond */
Chris@16 422 circular_buffer_space_optimized(const circular_buffer_space_optimized<T, Alloc>& cb)
Chris@16 423 : circular_buffer<T, Alloc>(cb.begin(), cb.end())
Chris@16 424 , m_capacity_ctrl(cb.m_capacity_ctrl) {}
Chris@16 425
Chris@16 426 template <class InputIterator>
Chris@16 427 circular_buffer_space_optimized(InputIterator first, InputIterator last)
Chris@16 428 : circular_buffer<T, Alloc>(first, last)
Chris@16 429 , m_capacity_ctrl(circular_buffer<T, Alloc>::capacity()) {}
Chris@16 430
Chris@16 431 template <class InputIterator>
Chris@16 432 circular_buffer_space_optimized(capacity_type capacity_ctrl, InputIterator first, InputIterator last)
Chris@16 433 : circular_buffer<T, Alloc>(
Chris@16 434 init_capacity(capacity_ctrl, first, last, is_integral<InputIterator>()),
Chris@16 435 first, last)
Chris@16 436 , m_capacity_ctrl(capacity_ctrl) {
Chris@16 437 reduce_capacity(
Chris@16 438 is_same< BOOST_DEDUCED_TYPENAME BOOST_ITERATOR_CATEGORY<InputIterator>::type, std::input_iterator_tag >());
Chris@16 439 }
Chris@16 440 /*! \endcond */
Chris@16 441
Chris@16 442 #else
Chris@16 443
Chris@16 444 //! The copy constructor.
Chris@16 445 /*!
Chris@16 446 Creates a copy of the specified <code>circular_buffer_space_optimized</code>.
Chris@16 447 \post <code>*this == cb</code><br><br>
Chris@16 448 The amount of allocated memory in the internal buffer is <code>cb.size()</code>.
Chris@16 449 \param cb The <code>circular_buffer_space_optimized</code> to be copied.
Chris@16 450 \throws "An allocation error" if memory is exhausted (<code>std::bad_alloc</code> if the standard allocator is
Chris@16 451 used).
Chris@16 452 Whatever <code>T::T(const T&)</code> throws.
Chris@16 453 \par Complexity
Chris@16 454 Linear (in the size of <code>cb</code>).
Chris@16 455 */
Chris@16 456 circular_buffer_space_optimized(const circular_buffer_space_optimized<T, Alloc>& cb)
Chris@16 457 : circular_buffer<T, Alloc>(cb.begin(), cb.end(), cb.get_allocator())
Chris@16 458 , m_capacity_ctrl(cb.m_capacity_ctrl) {}
Chris@16 459
Chris@16 460 #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
Chris@16 461 //! The move constructor.
Chris@16 462 /*! \brief Move constructs a <code>circular_buffer_space_optimized</code> from <code>cb</code>,
Chris@16 463 leaving <code>cb</code> empty.
Chris@16 464 \pre C++ compiler with rvalue references support.
Chris@16 465 \post <code>cb.empty()</code>
Chris@16 466 \param cb <code>circular_buffer</code> to 'steal' value from.
Chris@16 467 \throws Nothing.
Chris@16 468 \par Constant.
Chris@16 469 */
Chris@16 470 circular_buffer_space_optimized(circular_buffer_space_optimized<T, Alloc>&& cb) BOOST_NOEXCEPT
Chris@16 471 : circular_buffer<T, Alloc>()
Chris@16 472 , m_capacity_ctrl(0) {
Chris@16 473 cb.swap(*this);
Chris@16 474 }
Chris@16 475 #endif // BOOST_NO_CXX11_RVALUE_REFERENCES
Chris@16 476
Chris@16 477 //! Create a full space optimized circular buffer filled with a copy of the range.
Chris@16 478 /*!
Chris@16 479 \pre Valid range <code>[first, last)</code>.<br>
Chris@16 480 <code>first</code> and <code>last</code> have to meet the requirements of
Chris@16 481 <a href="http://www.sgi.com/tech/stl/InputIterator.html">InputIterator</a>.
Chris@16 482 \post <code>capacity().%capacity() == std::distance(first, last) \&\& capacity().min_capacity() == 0 \&\&
Chris@16 483 full() \&\& (*this)[0]== *first \&\& (*this)[1] == *(first + 1) \&\& ... \&\&
Chris@16 484 (*this)[std::distance(first, last) - 1] == *(last - 1)</code><br><br>
Chris@16 485 The amount of allocated memory in the internal buffer is <code>std::distance(first, last)</code>.
Chris@16 486 \param first The beginning of the range to be copied.
Chris@16 487 \param last The end of the range to be copied.
Chris@16 488 \param alloc The allocator.
Chris@16 489 \throws "An allocation error" if memory is exhausted (<code>std::bad_alloc</code> if the standard allocator is
Chris@16 490 used).
Chris@16 491 Whatever <code>T::T(const T&)</code> throws or nothing if <code>T::T(T&&)</code> is noexcept
Chris@16 492 and <code>InputIterator</code> is a move iterator.
Chris@16 493 \par Complexity
Chris@16 494 Linear (in the <code>std::distance(first, last)</code>).
Chris@16 495 */
Chris@16 496 template <class InputIterator>
Chris@16 497 circular_buffer_space_optimized(InputIterator first, InputIterator last,
Chris@16 498 const allocator_type& alloc = allocator_type())
Chris@16 499 : circular_buffer<T, Alloc>(first, last, alloc)
Chris@16 500 , m_capacity_ctrl(circular_buffer<T, Alloc>::capacity()) {}
Chris@16 501
Chris@16 502 /*! \brief Create a space optimized circular buffer with the specified capacity (and the minimal guaranteed amount
Chris@16 503 of allocated memory) filled with a copy of the range.
Chris@16 504 \pre Valid range <code>[first, last)</code>.<br>
Chris@16 505 <code>first</code> and <code>last</code> have to meet the requirements of
Chris@16 506 <a href="http://www.sgi.com/tech/stl/InputIterator.html">InputIterator</a>.
Chris@16 507 \post <code>capacity() == capacity_ctrl \&\& size() \<= std::distance(first, last) \&\& (*this)[0]==
Chris@16 508 *(last - capacity_ctrl.%capacity()) \&\& (*this)[1] == *(last - capacity_ctrl.%capacity() + 1) \&\& ...
Chris@16 509 \&\& (*this)[capacity_ctrl.%capacity() - 1] == *(last - 1)</code><br><br>
Chris@16 510 If the number of items to be copied from the range <code>[first, last)</code> is greater than the
Chris@16 511 specified <code>capacity_ctrl.%capacity()</code> then only elements from the range
Chris@16 512 <code>[last - capacity_ctrl.%capacity(), last)</code> will be copied.<br><br>
Chris@16 513 The amount of allocated memory in the internal buffer is <code>max[capacity_ctrl.min_capacity(),
Chris@16 514 min[capacity_ctrl.%capacity(), std::distance(first, last)]]</code>.
Chris@16 515 \param capacity_ctrl The capacity controller representing the maximum number of elements which can be stored in
Chris@16 516 the <code>circular_buffer_space_optimized</code> and the minimal allocated size of the
Chris@16 517 internal buffer.
Chris@16 518 \param first The beginning of the range to be copied.
Chris@16 519 \param last The end of the range to be copied.
Chris@16 520 \param alloc The allocator.
Chris@16 521 \throws "An allocation error" if memory is exhausted (<code>std::bad_alloc</code> if the standard allocator is
Chris@16 522 used).
Chris@16 523 Whatever <code>T::T(const T&)</code> throws.
Chris@16 524 \par Complexity
Chris@16 525 Linear (in <code>std::distance(first, last)</code>; in
Chris@16 526 <code>min[capacity_ctrl.%capacity(), std::distance(first, last)]</code> if the <code>InputIterator</code>
Chris@16 527 is a <a href="http://www.sgi.com/tech/stl/RandomAccessIterator.html">RandomAccessIterator</a>).
Chris@16 528 */
Chris@16 529 template <class InputIterator>
Chris@16 530 circular_buffer_space_optimized(capacity_type capacity_ctrl, InputIterator first, InputIterator last,
Chris@16 531 const allocator_type& alloc = allocator_type())
Chris@16 532 : circular_buffer<T, Alloc>(
Chris@16 533 init_capacity(capacity_ctrl, first, last, is_integral<InputIterator>()),
Chris@16 534 first, last, alloc)
Chris@16 535 , m_capacity_ctrl(capacity_ctrl) {
Chris@16 536 reduce_capacity(
Chris@16 537 is_same< BOOST_DEDUCED_TYPENAME BOOST_ITERATOR_CATEGORY<InputIterator>::type, std::input_iterator_tag >());
Chris@16 538 }
Chris@16 539
Chris@16 540 #endif // #if BOOST_WORKAROUND(BOOST_MSVC, < 1300)
Chris@16 541
Chris@16 542 #if defined(BOOST_CB_NEVER_DEFINED)
Chris@16 543 // This section will never be compiled - the default destructor will be generated instead.
Chris@16 544 // Declared only for documentation purpose.
Chris@16 545
Chris@16 546 //! The destructor.
Chris@16 547 /*!
Chris@16 548 Destroys the <code>circular_buffer_space_optimized</code>.
Chris@16 549 \throws Nothing.
Chris@16 550 \par Iterator Invalidation
Chris@16 551 Invalidates all iterators pointing to the <code>circular_buffer_space_optimized</code> (including
Chris@16 552 iterators equal to <code>end()</code>).
Chris@16 553 \par Complexity
Chris@16 554 Linear (in the size of the <code>circular_buffer_space_optimized</code>).
Chris@16 555 \sa <code>clear()</code>
Chris@16 556 */
Chris@16 557 ~circular_buffer_space_optimized();
Chris@16 558
Chris@16 559 //! no-comment
Chris@16 560 void erase_begin(size_type n);
Chris@16 561
Chris@16 562 //! no-comment
Chris@16 563 void erase_end(size_type n);
Chris@16 564
Chris@16 565 #endif // #if defined(BOOST_CB_NEVER_DEFINED)
Chris@16 566
Chris@16 567 //! The assign operator.
Chris@16 568 /*!
Chris@16 569 Makes this <code>circular_buffer_space_optimized</code> to become a copy of the specified
Chris@16 570 <code>circular_buffer_space_optimized</code>.
Chris@16 571 \post <code>*this == cb</code><br><br>
Chris@16 572 The amount of allocated memory in the internal buffer is <code>cb.size()</code>.
Chris@16 573 \param cb The <code>circular_buffer_space_optimized</code> to be copied.
Chris@16 574 \throws "An allocation error" if memory is exhausted (<code>std::bad_alloc</code> if the standard allocator is
Chris@16 575 used).
Chris@16 576 \throws Whatever <code>T::T(const T&)</code> throws.
Chris@16 577 \par Exception Safety
Chris@16 578 Strong.
Chris@16 579 \par Iterator Invalidation
Chris@16 580 Invalidates all iterators pointing to this <code>circular_buffer_space_optimized</code> (except iterators
Chris@16 581 equal to <code>end()</code>).
Chris@16 582 \par Complexity
Chris@16 583 Linear (in the size of <code>cb</code>).
Chris@16 584 \sa <code>\link assign(size_type, param_value_type) assign(size_type, const_reference)\endlink</code>,
Chris@16 585 <code>\link assign(capacity_type, size_type, param_value_type)
Chris@16 586 assign(capacity_type, size_type, const_reference)\endlink</code>,
Chris@16 587 <code>assign(InputIterator, InputIterator)</code>,
Chris@16 588 <code>assign(capacity_type, InputIterator, InputIterator)</code>
Chris@16 589 */
Chris@16 590 circular_buffer_space_optimized<T, Alloc>& operator = (const circular_buffer_space_optimized<T, Alloc>& cb) {
Chris@16 591 if (this == &cb)
Chris@16 592 return *this;
Chris@16 593 circular_buffer<T, Alloc>::assign(cb.begin(), cb.end());
Chris@16 594 m_capacity_ctrl = cb.m_capacity_ctrl;
Chris@16 595 return *this;
Chris@16 596 }
Chris@16 597
Chris@16 598 #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
Chris@16 599 /*! \brief Move assigns content of <code>cb</code> to <code>*this</code>, leaving <code>cb</code> empty.
Chris@16 600 \pre C++ compiler with rvalue references support.
Chris@16 601 \post <code>cb.empty()</code>
Chris@16 602 \param cb <code>circular_buffer</code> to 'steal' value from.
Chris@16 603 \throws Nothing.
Chris@16 604 \par Complexity
Chris@16 605 Constant.
Chris@16 606 */
Chris@16 607 circular_buffer_space_optimized<T, Alloc>& operator = (circular_buffer_space_optimized<T, Alloc>&& cb) BOOST_NOEXCEPT {
Chris@16 608 cb.swap(*this); // now `this` holds `cb`
Chris@16 609 circular_buffer<T, Alloc>(get_allocator()) // temprary that holds initial `cb` allocator
Chris@16 610 .swap(cb); // makes `cb` empty
Chris@16 611 return *this;
Chris@16 612 }
Chris@16 613 #endif // BOOST_NO_CXX11_RVALUE_REFERENCES
Chris@16 614
Chris@16 615
Chris@16 616 //! Assign <code>n</code> items into the space optimized circular buffer.
Chris@16 617 /*!
Chris@16 618 The content of the <code>circular_buffer_space_optimized</code> will be removed and replaced with
Chris@16 619 <code>n</code> copies of the <code>item</code>.
Chris@16 620 \post <code>capacity().%capacity() == n \&\& capacity().min_capacity() == 0 \&\& size() == n \&\& (*this)[0] ==
Chris@16 621 item \&\& (*this)[1] == item \&\& ... \&\& (*this) [n - 1] == item</code><br><br>
Chris@16 622 The amount of allocated memory in the internal buffer is <code>n</code>.
Chris@16 623 \param n The number of elements the <code>circular_buffer_space_optimized</code> will be filled with.
Chris@16 624 \param item The element the <code>circular_buffer_space_optimized</code> will be filled with.
Chris@16 625 \throws "An allocation error" if memory is exhausted (<code>std::bad_alloc</code> if the standard allocator is
Chris@16 626 used).
Chris@16 627 Whatever <code>T::T(const T&)</code> throws.
Chris@16 628 \par Exception Safety
Chris@16 629 Basic.
Chris@16 630 \par Iterator Invalidation
Chris@16 631 Invalidates all iterators pointing to the <code>circular_buffer_space_optimized</code> (except iterators
Chris@16 632 equal to <code>end()</code>).
Chris@16 633 \par Complexity
Chris@16 634 Linear (in the <code>n</code>).
Chris@16 635 \sa <code>\link operator=(const circular_buffer_space_optimized&) operator=\endlink</code>,
Chris@16 636 <code>\link assign(capacity_type, size_type, param_value_type)
Chris@16 637 assign(capacity_type, size_type, const_reference)\endlink</code>,
Chris@16 638 <code>assign(InputIterator, InputIterator)</code>,
Chris@16 639 <code>assign(capacity_type, InputIterator, InputIterator)</code>
Chris@16 640 */
Chris@16 641 void assign(size_type n, param_value_type item) {
Chris@16 642 circular_buffer<T, Alloc>::assign(n, item);
Chris@16 643 m_capacity_ctrl = capacity_type(n);
Chris@16 644 }
Chris@16 645
Chris@16 646 //! Assign <code>n</code> items into the space optimized circular buffer specifying the capacity.
Chris@16 647 /*!
Chris@16 648 The capacity of the <code>circular_buffer_space_optimized</code> will be set to the specified value and the
Chris@16 649 content of the <code>circular_buffer_space_optimized</code> will be removed and replaced with <code>n</code>
Chris@16 650 copies of the <code>item</code>.
Chris@16 651 \pre <code>capacity_ctrl.%capacity() >= n</code>
Chris@16 652 \post <code>capacity() == capacity_ctrl \&\& size() == n \&\& (*this)[0] == item \&\& (*this)[1] == item
Chris@16 653 \&\& ... \&\& (*this) [n - 1] == item </code><br><br>
Chris@16 654 The amount of allocated memory will be <code>max[n, capacity_ctrl.min_capacity()]</code>.
Chris@16 655 \param capacity_ctrl The new capacity controller.
Chris@16 656 \param n The number of elements the <code>circular_buffer_space_optimized</code> will be filled with.
Chris@16 657 \param item The element the <code>circular_buffer_space_optimized</code> will be filled with.
Chris@16 658 \throws "An allocation error" if memory is exhausted (<code>std::bad_alloc</code> if the standard allocator is
Chris@16 659 used).
Chris@16 660 Whatever <code>T::T(const T&)</code> throws.
Chris@16 661 \par Exception Safety
Chris@16 662 Basic.
Chris@16 663 \par Iterator Invalidation
Chris@16 664 Invalidates all iterators pointing to the <code>circular_buffer_space_optimized</code> (except iterators
Chris@16 665 equal to <code>end()</code>).
Chris@16 666 \par Complexity
Chris@16 667 Linear (in the <code>n</code>).
Chris@16 668 \sa <code>\link operator=(const circular_buffer_space_optimized&) operator=\endlink</code>,
Chris@16 669 <code>\link assign(size_type, param_value_type) assign(size_type, const_reference)\endlink</code>,
Chris@16 670 <code>assign(InputIterator, InputIterator)</code>,
Chris@16 671 <code>assign(capacity_type, InputIterator, InputIterator)</code>
Chris@16 672 */
Chris@16 673 void assign(capacity_type capacity_ctrl, size_type n, param_value_type item) {
Chris@16 674 BOOST_CB_ASSERT(capacity_ctrl.capacity() >= n); // check for new capacity lower than n
Chris@16 675 circular_buffer<T, Alloc>::assign((std::max)(capacity_ctrl.min_capacity(), n), n, item);
Chris@16 676 m_capacity_ctrl = capacity_ctrl;
Chris@16 677 }
Chris@16 678
Chris@16 679 //! Assign a copy of the range into the space optimized circular buffer.
Chris@16 680 /*!
Chris@16 681 The content of the <code>circular_buffer_space_optimized</code> will be removed and replaced with copies of
Chris@16 682 elements from the specified range.
Chris@16 683 \pre Valid range <code>[first, last)</code>.<br>
Chris@16 684 <code>first</code> and <code>last</code> have to meet the requirements of
Chris@16 685 <a href="http://www.sgi.com/tech/stl/InputIterator.html">InputIterator</a>.
Chris@16 686 \post <code>capacity().%capacity() == std::distance(first, last) \&\& capacity().min_capacity() == 0 \&\&
Chris@16 687 size() == std::distance(first, last) \&\& (*this)[0]== *first \&\& (*this)[1] == *(first + 1) \&\& ...
Chris@16 688 \&\& (*this)[std::distance(first, last) - 1] == *(last - 1)</code><br><br>
Chris@16 689 The amount of allocated memory in the internal buffer is <code>std::distance(first, last)</code>.
Chris@16 690 \param first The beginning of the range to be copied.
Chris@16 691 \param last The end of the range to be copied.
Chris@16 692 \throws "An allocation error" if memory is exhausted (<code>std::bad_alloc</code> if the standard allocator is
Chris@16 693 used).
Chris@16 694 Whatever <code>T::T(const T&)</code> throws or nothing if <code>T::T(T&&)</code> is noexcept and
Chris@16 695 <code>InputIterator</code> is a move iterator.
Chris@16 696 \par Exception Safety
Chris@16 697 Basic.
Chris@16 698 \par Iterator Invalidation
Chris@16 699 Invalidates all iterators pointing to the <code>circular_buffer_space_optimized</code> (except iterators
Chris@16 700 equal to <code>end()</code>).
Chris@16 701 \par Complexity
Chris@16 702 Linear (in the <code>std::distance(first, last)</code>).
Chris@16 703 \sa <code>\link operator=(const circular_buffer_space_optimized&) operator=\endlink</code>,
Chris@16 704 <code>\link assign(size_type, param_value_type) assign(size_type, const_reference)\endlink</code>,
Chris@16 705 <code>\link assign(capacity_type, size_type, param_value_type)
Chris@16 706 assign(capacity_type, size_type, const_reference)\endlink</code>,
Chris@16 707 <code>assign(capacity_type, InputIterator, InputIterator)</code>
Chris@16 708 */
Chris@16 709 template <class InputIterator>
Chris@16 710 void assign(InputIterator first, InputIterator last) {
Chris@16 711 circular_buffer<T, Alloc>::assign(first, last);
Chris@16 712 m_capacity_ctrl = capacity_type(circular_buffer<T, Alloc>::capacity());
Chris@16 713 }
Chris@16 714
Chris@16 715 //! Assign a copy of the range into the space optimized circular buffer specifying the capacity.
Chris@16 716 /*!
Chris@16 717 The capacity of the <code>circular_buffer_space_optimized</code> will be set to the specified value and the
Chris@16 718 content of the <code>circular_buffer_space_optimized</code> will be removed and replaced with copies of
Chris@16 719 elements from the specified range.
Chris@16 720 \pre Valid range <code>[first, last)</code>.<br>
Chris@16 721 <code>first</code> and <code>last</code> have to meet the requirements of
Chris@16 722 <a href="http://www.sgi.com/tech/stl/InputIterator.html">InputIterator</a>.
Chris@16 723 \post <code>capacity() == capacity_ctrl \&\& size() \<= std::distance(first, last) \&\&
Chris@16 724 (*this)[0]== *(last - capacity) \&\& (*this)[1] == *(last - capacity + 1) \&\& ... \&\&
Chris@16 725 (*this)[capacity - 1] == *(last - 1)</code><br><br>
Chris@16 726 If the number of items to be copied from the range <code>[first, last)</code> is greater than the
Chris@16 727 specified <code>capacity</code> then only elements from the range <code>[last - capacity, last)</code>
Chris@16 728 will be copied.<br><br> The amount of allocated memory in the internal buffer is
Chris@16 729 <code>max[std::distance(first, last), capacity_ctrl.min_capacity()]</code>.
Chris@16 730 \param capacity_ctrl The new capacity controller.
Chris@16 731 \param first The beginning of the range to be copied.
Chris@16 732 \param last The end of the range to be copied.
Chris@16 733 \throws "An allocation error" if memory is exhausted (<code>std::bad_alloc</code> if the standard allocator is
Chris@16 734 used).
Chris@16 735 Whatever <code>T::T(const T&)</code> throws or nothing if <code>T::T(T&&)</code> is noexcept and
Chris@16 736 <code>InputIterator</code> is a move iterator.
Chris@16 737 \par Exception Safety
Chris@16 738 Basic.
Chris@16 739 \par Iterator Invalidation
Chris@16 740 Invalidates all iterators pointing to the <code>circular_buffer_space_optimized</code> (except iterators
Chris@16 741 equal to <code>end()</code>).
Chris@16 742 \par Complexity
Chris@16 743 Linear (in <code>std::distance(first, last)</code>; in
Chris@16 744 <code>min[capacity_ctrl.%capacity(), std::distance(first, last)]</code> if the <code>InputIterator</code>
Chris@16 745 is a <a href="http://www.sgi.com/tech/stl/RandomAccessIterator.html">RandomAccessIterator</a>).
Chris@16 746 \sa <code>\link operator=(const circular_buffer_space_optimized&) operator=\endlink</code>,
Chris@16 747 <code>\link assign(size_type, param_value_type) assign(size_type, const_reference)\endlink</code>,
Chris@16 748 <code>\link assign(capacity_type, size_type, param_value_type)
Chris@16 749 assign(capacity_type, size_type, const_reference)\endlink</code>,
Chris@16 750 <code>assign(InputIterator, InputIterator)</code>
Chris@16 751 */
Chris@16 752 template <class InputIterator>
Chris@16 753 void assign(capacity_type capacity_ctrl, InputIterator first, InputIterator last) {
Chris@16 754 m_capacity_ctrl = capacity_ctrl;
Chris@16 755 circular_buffer<T, Alloc>::assign(capacity_ctrl, first, last);
Chris@16 756 }
Chris@16 757
Chris@16 758 //! Swap the contents of two space-optimized circular-buffers.
Chris@16 759 /*!
Chris@16 760 \post <code>this</code> contains elements of <code>cb</code> and vice versa; the capacity and the amount of
Chris@16 761 allocated memory in the internal buffer of <code>this</code> equal to the capacity and the amount of
Chris@16 762 allocated memory of <code>cb</code> and vice versa.
Chris@16 763 \param cb The <code>circular_buffer_space_optimized</code> whose content will be swapped.
Chris@16 764 \throws Nothing.
Chris@16 765 \par Exception Safety
Chris@16 766 No-throw.
Chris@16 767 \par Iterator Invalidation
Chris@16 768 Invalidates all iterators of both <code>circular_buffer_space_optimized</code> containers. (On the other
Chris@16 769 hand the iterators still point to the same elements but within another container. If you want to rely on
Chris@16 770 this feature you have to turn the __debug_support off by defining macro BOOST_CB_DISABLE_DEBUG,
Chris@16 771 otherwise an assertion will report an error if such invalidated iterator is used.)
Chris@16 772 \par Complexity
Chris@16 773 Constant (in the size of the <code>circular_buffer_space_optimized</code>).
Chris@16 774 \sa <code>swap(circular_buffer<T, Alloc>&, circular_buffer<T, Alloc>&)</code>,
Chris@16 775 <code>swap(circular_buffer_space_optimized<T, Alloc>&, circular_buffer_space_optimized<T, Alloc>&)</code>
Chris@16 776
Chris@16 777
Chris@16 778 */
Chris@16 779 // Note link does not work right. Asked on Doxygen forum for advice 23 May 2103.
Chris@16 780
Chris@16 781 void swap(circular_buffer_space_optimized<T, Alloc>& cb) BOOST_NOEXCEPT {
Chris@16 782 std::swap(m_capacity_ctrl, cb.m_capacity_ctrl);
Chris@16 783 circular_buffer<T, Alloc>::swap(cb);
Chris@16 784 }
Chris@16 785
Chris@16 786 //! Insert a new element at the end of the space optimized circular buffer.
Chris@16 787 /*!
Chris@16 788 \post if <code>capacity().%capacity() > 0</code> then <code>back() == item</code><br>
Chris@16 789 If the <code>circular_buffer_space_optimized</code> is full, the first element will be removed. If the
Chris@16 790 capacity is <code>0</code>, nothing will be inserted.<br><br>
Chris@16 791 The amount of allocated memory in the internal buffer may be predictively increased.
Chris@16 792 \param item The element to be inserted.
Chris@16 793 \throws "An allocation error" if memory is exhausted (<code>std::bad_alloc</code> if the standard allocator is
Chris@16 794 used).
Chris@16 795 Whatever <code>T::T(const T&)</code> throws.
Chris@16 796 \par Exception Safety
Chris@16 797 Basic.
Chris@16 798 \par Iterator Invalidation
Chris@16 799 Invalidates all iterators pointing to the <code>circular_buffer_space_optimized</code> (except iterators
Chris@16 800 equal to <code>end()</code>).
Chris@16 801 \par Complexity
Chris@16 802 Linear (in the size of the <code>circular_buffer_space_optimized</code>).
Chris@16 803 \sa <code>\link push_front() push_front(const_reference)\endlink</code>, <code>pop_back()</code>,
Chris@16 804 <code>pop_front()</code>
Chris@16 805 */
Chris@16 806 void push_back(param_value_type item) {
Chris@16 807 check_low_capacity();
Chris@16 808 circular_buffer<T, Alloc>::push_back(item);
Chris@16 809 }
Chris@16 810
Chris@16 811 //! Insert a new element at the end of the space optimized circular buffer.
Chris@16 812 /*!
Chris@16 813 \post if <code>capacity().%capacity() > 0</code> then <code>back() == item</code><br>
Chris@16 814 If the <code>circular_buffer_space_optimized</code> is full, the first element will be removed. If the
Chris@16 815 capacity is <code>0</code>, nothing will be inserted.<br><br>
Chris@16 816 The amount of allocated memory in the internal buffer may be predictively increased.
Chris@16 817 \param item The element to be inserted.
Chris@16 818 \throws "An allocation error" if memory is exhausted (<code>std::bad_alloc</code> if the standard allocator is
Chris@16 819 used).
Chris@16 820 \par Exception Safety
Chris@16 821 Basic.
Chris@16 822 \par Iterator Invalidation
Chris@16 823 Invalidates all iterators pointing to the <code>circular_buffer_space_optimized</code> (except iterators
Chris@16 824 equal to <code>end()</code>).
Chris@16 825 \par Complexity
Chris@16 826 Linear (in the size of the <code>circular_buffer_space_optimized</code>).
Chris@16 827 \sa <code>\link push_front() push_front(const_reference)\endlink</code>, <code>pop_back()</code>,
Chris@16 828 <code>pop_front()</code>
Chris@16 829 */
Chris@16 830 void push_back(rvalue_type item) {
Chris@16 831 check_low_capacity();
Chris@16 832 circular_buffer<T, Alloc>::push_back(boost::move(item));
Chris@16 833 }
Chris@16 834
Chris@16 835 //! Insert a new element at the end of the space optimized circular buffer.
Chris@16 836 /*!
Chris@16 837 \post if <code>capacity().%capacity() > 0</code> then <code>back() == item</code><br>
Chris@16 838 If the <code>circular_buffer_space_optimized</code> is full, the first element will be removed. If the
Chris@16 839 capacity is <code>0</code>, nothing will be inserted.<br><br>
Chris@16 840 The amount of allocated memory in the internal buffer may be predictively increased.
Chris@16 841 \throws "An allocation error" if memory is exhausted (<code>std::bad_alloc</code> if the standard allocator is
Chris@16 842 used).
Chris@16 843 Whatever <code>T::T()</code> throws.
Chris@16 844 Whatever <code>T::T(const T&)</code> throws or nothing if <code>T::T(T&&)</code> is noexcept.
Chris@16 845 \par Exception Safety
Chris@16 846 Basic.
Chris@16 847 \par Iterator Invalidation
Chris@16 848 Invalidates all iterators pointing to the <code>circular_buffer_space_optimized</code> (except iterators
Chris@16 849 equal to <code>end()</code>).
Chris@16 850 \par Complexity
Chris@16 851 Linear (in the size of the <code>circular_buffer_space_optimized</code>).
Chris@16 852 \sa <code>\link push_front() push_front(const_reference)\endlink</code>, <code>pop_back()</code>,
Chris@16 853 <code>pop_front()</code>
Chris@16 854 */
Chris@16 855 void push_back() {
Chris@16 856 check_low_capacity();
Chris@16 857 circular_buffer<T, Alloc>::push_back();
Chris@16 858 }
Chris@16 859
Chris@16 860 //! Insert a new element at the beginning of the space optimized circular buffer.
Chris@16 861 /*!
Chris@16 862 \post if <code>capacity().%capacity() > 0</code> then <code>front() == item</code><br>
Chris@16 863 If the <code>circular_buffer_space_optimized</code> is full, the last element will be removed. If the
Chris@16 864 capacity is <code>0</code>, nothing will be inserted.<br><br>
Chris@16 865 The amount of allocated memory in the internal buffer may be predictively increased.
Chris@16 866 \param item The element to be inserted.
Chris@16 867 \throws "An allocation error" if memory is exhausted (<code>std::bad_alloc</code> if the standard allocator is
Chris@16 868 used).
Chris@16 869 Whatever <code>T::T(const T&)</code> throws.
Chris@16 870 \par Exception Safety
Chris@16 871 Basic.
Chris@16 872 \par Iterator Invalidation
Chris@16 873 Invalidates all iterators pointing to the <code>circular_buffer_space_optimized</code> (except iterators
Chris@16 874 equal to <code>end()</code>).
Chris@16 875 \par Complexity
Chris@16 876 Linear (in the size of the <code>circular_buffer_space_optimized</code>).
Chris@16 877 \sa <code>\link push_back() push_back(const_reference)\endlink</code>, <code>pop_back()</code>,
Chris@16 878 <code>pop_front()</code>
Chris@16 879 */
Chris@16 880 void push_front(param_value_type item) {
Chris@16 881 check_low_capacity();
Chris@16 882 circular_buffer<T, Alloc>::push_front(item);
Chris@16 883 }
Chris@16 884
Chris@16 885 //! Insert a new element at the beginning of the space optimized circular buffer.
Chris@16 886 /*!
Chris@16 887 \post if <code>capacity().%capacity() > 0</code> then <code>front() == item</code><br>
Chris@16 888 If the <code>circular_buffer_space_optimized</code> is full, the last element will be removed. If the
Chris@16 889 capacity is <code>0</code>, nothing will be inserted.<br><br>
Chris@16 890 The amount of allocated memory in the internal buffer may be predictively increased.
Chris@16 891 \param item The element to be inserted.
Chris@16 892 \throws "An allocation error" if memory is exhausted (<code>std::bad_alloc</code> if the standard allocator is
Chris@16 893 used).
Chris@16 894 Whatever <code>T::T(const T&)</code> throws or nothing if <code>T::T(T&&)</code> is noexcept.
Chris@16 895 \par Exception Safety
Chris@16 896 Basic.
Chris@16 897 \par Iterator Invalidation
Chris@16 898 Invalidates all iterators pointing to the <code>circular_buffer_space_optimized</code> (except iterators
Chris@16 899 equal to <code>end()</code>).
Chris@16 900 \par Complexity
Chris@16 901 Linear (in the size of the <code>circular_buffer_space_optimized</code>).
Chris@16 902 \sa <code>\link push_back() push_back(const_reference)\endlink</code>, <code>pop_back()</code>,
Chris@16 903 <code>pop_front()</code>
Chris@16 904 */
Chris@16 905 void push_front(rvalue_type item) {
Chris@16 906 check_low_capacity();
Chris@16 907 circular_buffer<T, Alloc>::push_front(boost::move(item));
Chris@16 908 }
Chris@16 909
Chris@16 910 //! Insert a new element at the beginning of the space optimized circular buffer.
Chris@16 911 /*!
Chris@16 912 \post if <code>capacity().%capacity() > 0</code> then <code>front() == item</code><br>
Chris@16 913 If the <code>circular_buffer_space_optimized</code> is full, the last element will be removed. If the
Chris@16 914 capacity is <code>0</code>, nothing will be inserted.<br><br>
Chris@16 915 The amount of allocated memory in the internal buffer may be predictively increased.
Chris@16 916 \throws "An allocation error" if memory is exhausted (<code>std::bad_alloc</code> if the standard allocator is
Chris@16 917 used).
Chris@16 918 Whatever <code>T::T()</code> throws.
Chris@16 919 Whatever <code>T::T(const T&)</code> throws or nothing if <code>T::T(T&&)</code> is noexcept.
Chris@16 920 \par Exception Safety
Chris@16 921 Basic.
Chris@16 922 \par Iterator Invalidation
Chris@16 923 Invalidates all iterators pointing to the <code>circular_buffer_space_optimized</code> (except iterators
Chris@16 924 equal to <code>end()</code>).
Chris@16 925 \par Complexity
Chris@16 926 Linear (in the size of the <code>circular_buffer_space_optimized</code>).
Chris@16 927 \sa <code>\link push_back() push_back(const_reference)\endlink</code>, <code>pop_back()</code>,
Chris@16 928 <code>pop_front()</code>
Chris@16 929 */
Chris@16 930 void push_front() {
Chris@16 931 check_low_capacity();
Chris@16 932 circular_buffer<T, Alloc>::push_front();
Chris@16 933 }
Chris@16 934
Chris@16 935 //! Remove the last element from the space optimized circular buffer.
Chris@16 936 /*!
Chris@16 937 \pre <code>!empty()</code>
Chris@16 938 \post The last element is removed from the <code>circular_buffer_space_optimized</code>.<br><br>
Chris@16 939 The amount of allocated memory in the internal buffer may be predictively decreased.
Chris@16 940 \throws "An allocation error" if memory is exhausted (<code>std::bad_alloc</code> if the standard allocator is
Chris@16 941 used).
Chris@16 942 \par Exception Safety
Chris@16 943 Basic.
Chris@16 944 \par Iterator Invalidation
Chris@16 945 Invalidates all iterators pointing to the <code>circular_buffer_space_optimized</code> (except iterators
Chris@16 946 equal to <code>end()</code>).
Chris@16 947 \par Complexity
Chris@16 948 Linear (in the size of the <code>circular_buffer_space_optimized</code>).
Chris@16 949 \sa <code>pop_front()</code>, <code>\link push_back() push_back(const_reference)\endlink</code>,
Chris@16 950 <code>\link push_front() push_front(const_reference)\endlink</code>
Chris@16 951 */
Chris@16 952 void pop_back() {
Chris@16 953 circular_buffer<T, Alloc>::pop_back();
Chris@16 954 check_high_capacity();
Chris@16 955 }
Chris@16 956
Chris@16 957 //! Remove the first element from the space optimized circular buffer.
Chris@16 958 /*!
Chris@16 959 \pre <code>!empty()</code>
Chris@16 960 \post The first element is removed from the <code>circular_buffer_space_optimized</code>.<br><br>
Chris@16 961 The amount of allocated memory in the internal buffer may be predictively decreased.
Chris@16 962 \throws "An allocation error" if memory is exhausted (<code>std::bad_alloc</code> if the standard allocator is
Chris@16 963 used).
Chris@16 964 \par Exception Safety
Chris@16 965 Basic.
Chris@16 966 \par Iterator Invalidation
Chris@16 967 Invalidates all iterators pointing to the <code>circular_buffer_space_optimized</code> (except iterators
Chris@16 968 equal to <code>end()</code>).
Chris@16 969 \par Complexity
Chris@16 970 Linear (in the size of the <code>circular_buffer_space_optimized</code>).
Chris@16 971 \sa <code>pop_back()</code>, <code>\link push_back() push_back(const_reference)\endlink</code>,
Chris@16 972 <code>\link push_front() push_front(const_reference)\endlink</code>
Chris@16 973 */
Chris@16 974 void pop_front() {
Chris@16 975 circular_buffer<T, Alloc>::pop_front();
Chris@16 976 check_high_capacity();
Chris@16 977 }
Chris@16 978
Chris@16 979 //! Insert an element at the specified position.
Chris@16 980 /*!
Chris@16 981 \pre <code>pos</code> is a valid iterator pointing to the <code>circular_buffer_space_optimized</code> or its
Chris@16 982 end.
Chris@16 983 \post The <code>item</code> will be inserted at the position <code>pos</code>.<br>
Chris@16 984 If the <code>circular_buffer_space_optimized</code> is full, the first element will be overwritten. If
Chris@16 985 the <code>circular_buffer_space_optimized</code> is full and the <code>pos</code> points to
Chris@16 986 <code>begin()</code>, then the <code>item</code> will not be inserted. If the capacity is <code>0</code>,
Chris@16 987 nothing will be inserted.<br><br>
Chris@16 988 The amount of allocated memory in the internal buffer may be predictively increased.
Chris@16 989 \param pos An iterator specifying the position where the <code>item</code> will be inserted.
Chris@16 990 \param item The element to be inserted.
Chris@16 991 \return Iterator to the inserted element or <code>begin()</code> if the <code>item</code> is not inserted. (See
Chris@16 992 the <i>Effect</i>.)
Chris@16 993 \throws "An allocation error" if memory is exhausted (<code>std::bad_alloc</code> if the standard allocator is
Chris@16 994 used).
Chris@16 995 Whatever <code>T::T(const T&)</code> throws.
Chris@16 996 Whatever <code>T::operator = (const T&)</code> throws.
Chris@16 997 \par Exception Safety
Chris@16 998 Basic.
Chris@16 999 \par Iterator Invalidation
Chris@16 1000 Invalidates all iterators pointing to the <code>circular_buffer_space_optimized</code> (except iterators
Chris@16 1001 equal to <code>end()</code>).
Chris@16 1002 \par Complexity
Chris@16 1003 Linear (in the size of the <code>circular_buffer_space_optimized</code>).
Chris@16 1004 \sa <code>\link insert(iterator, size_type, param_value_type)
Chris@16 1005 insert(iterator, size_type, value_type)\endlink</code>,
Chris@16 1006 <code>insert(iterator, InputIterator, InputIterator)</code>,
Chris@16 1007 <code>\link rinsert(iterator, param_value_type) rinsert(iterator, value_type)\endlink</code>,
Chris@16 1008 <code>\link rinsert(iterator, size_type, param_value_type)
Chris@16 1009 rinsert(iterator, size_type, value_type)\endlink</code>,
Chris@16 1010 <code>rinsert(iterator, InputIterator, InputIterator)</code>
Chris@16 1011 */
Chris@16 1012 iterator insert(iterator pos, param_value_type item) {
Chris@16 1013 size_type index = pos - begin();
Chris@16 1014 check_low_capacity();
Chris@16 1015 return circular_buffer<T, Alloc>::insert(begin() + index, item);
Chris@16 1016 }
Chris@16 1017
Chris@16 1018 //! Insert an element at the specified position.
Chris@16 1019 /*!
Chris@16 1020 \pre <code>pos</code> is a valid iterator pointing to the <code>circular_buffer_space_optimized</code> or its
Chris@16 1021 end.
Chris@16 1022 \post The <code>item</code> will be inserted at the position <code>pos</code>.<br>
Chris@16 1023 If the <code>circular_buffer_space_optimized</code> is full, the first element will be overwritten. If
Chris@16 1024 the <code>circular_buffer_space_optimized</code> is full and the <code>pos</code> points to
Chris@16 1025 <code>begin()</code>, then the <code>item</code> will not be inserted. If the capacity is <code>0</code>,
Chris@16 1026 nothing will be inserted.<br><br>
Chris@16 1027 The amount of allocated memory in the internal buffer may be predictively increased.
Chris@16 1028 \param pos An iterator specifying the position where the <code>item</code> will be inserted.
Chris@16 1029 \param item The element to be inserted.
Chris@16 1030 \return Iterator to the inserted element or <code>begin()</code> if the <code>item</code> is not inserted. (See
Chris@16 1031 the <i>Effect</i>.)
Chris@16 1032 \throws "An allocation error" if memory is exhausted (<code>std::bad_alloc</code> if the standard allocator is
Chris@16 1033 used).
Chris@16 1034 Whatever <code>T::T(const T&)</code> throws or nothing if <code>T::T(T&&)</code> is noexcept.
Chris@16 1035 \par Exception Safety
Chris@16 1036 Basic.
Chris@16 1037 \par Iterator Invalidation
Chris@16 1038 Invalidates all iterators pointing to the <code>circular_buffer_space_optimized</code> (except iterators
Chris@16 1039 equal to <code>end()</code>).
Chris@16 1040 \par Complexity
Chris@16 1041 Linear (in the size of the <code>circular_buffer_space_optimized</code>).
Chris@16 1042 \sa <code>\link insert(iterator, size_type, param_value_type)
Chris@16 1043 insert(iterator, size_type, value_type)\endlink</code>,
Chris@16 1044 <code>insert(iterator, InputIterator, InputIterator)</code>,
Chris@16 1045 <code>\link rinsert(iterator, param_value_type) rinsert(iterator, value_type)\endlink</code>,
Chris@16 1046 <code>\link rinsert(iterator, size_type, param_value_type)
Chris@16 1047 rinsert(iterator, size_type, value_type)\endlink</code>,
Chris@16 1048 <code>rinsert(iterator, InputIterator, InputIterator)</code>
Chris@16 1049 */
Chris@16 1050 iterator insert(iterator pos, rvalue_type item) {
Chris@16 1051 size_type index = pos - begin();
Chris@16 1052 check_low_capacity();
Chris@16 1053 return circular_buffer<T, Alloc>::insert(begin() + index, boost::move(item));
Chris@16 1054 }
Chris@16 1055
Chris@16 1056 //! Insert an element at the specified position.
Chris@16 1057 /*!
Chris@16 1058 \pre <code>pos</code> is a valid iterator pointing to the <code>circular_buffer_space_optimized</code> or its
Chris@16 1059 end.
Chris@16 1060 \post The <code>item</code> will be inserted at the position <code>pos</code>.<br>
Chris@16 1061 If the <code>circular_buffer_space_optimized</code> is full, the first element will be overwritten. If
Chris@16 1062 the <code>circular_buffer_space_optimized</code> is full and the <code>pos</code> points to
Chris@16 1063 <code>begin()</code>, then the <code>item</code> will not be inserted. If the capacity is <code>0</code>,
Chris@16 1064 nothing will be inserted.<br><br>
Chris@16 1065 The amount of allocated memory in the internal buffer may be predictively increased.
Chris@16 1066 \param pos An iterator specifying the position where the <code>item</code> will be inserted.
Chris@16 1067 \return Iterator to the inserted element or <code>begin()</code> if the <code>item</code> is not inserted. (See
Chris@16 1068 the <i>Effect</i>.)
Chris@16 1069 \throws "An allocation error" if memory is exhausted (<code>std::bad_alloc</code> if the standard allocator is
Chris@16 1070 used).
Chris@16 1071 Whatever <code>T::T()</code> throws.
Chris@16 1072 Whatever <code>T::T(const T&)</code> throws or nothing if <code>T::T(T&&)</code> is noexcept.
Chris@16 1073 \par Exception Safety
Chris@16 1074 Basic.
Chris@16 1075 \par Iterator Invalidation
Chris@16 1076 Invalidates all iterators pointing to the <code>circular_buffer_space_optimized</code> (except iterators
Chris@16 1077 equal to <code>end()</code>).
Chris@16 1078 \par Complexity
Chris@16 1079 Linear (in the size of the <code>circular_buffer_space_optimized</code>).
Chris@16 1080 \sa <code>\link insert(iterator, size_type, param_value_type)
Chris@16 1081 insert(iterator, size_type, value_type)\endlink</code>,
Chris@16 1082 <code>insert(iterator, InputIterator, InputIterator)</code>,
Chris@16 1083 <code>\link rinsert(iterator, param_value_type) rinsert(iterator, value_type)\endlink</code>,
Chris@16 1084 <code>\link rinsert(iterator, size_type, param_value_type)
Chris@16 1085 rinsert(iterator, size_type, value_type)\endlink</code>,
Chris@16 1086 <code>rinsert(iterator, InputIterator, InputIterator)</code>
Chris@16 1087 */
Chris@16 1088 iterator insert(iterator pos) {
Chris@16 1089 size_type index = pos - begin();
Chris@16 1090 check_low_capacity();
Chris@16 1091 return circular_buffer<T, Alloc>::insert(begin() + index);
Chris@16 1092 }
Chris@16 1093
Chris@16 1094 //! Insert <code>n</code> copies of the <code>item</code> at the specified position.
Chris@16 1095 /*!
Chris@16 1096 \pre <code>pos</code> is a valid iterator pointing to the <code>circular_buffer_space_optimized</code> or its
Chris@16 1097 end.
Chris@16 1098 \post The number of <code>min[n, (pos - begin()) + reserve()]</code> elements will be inserted at the position
Chris@16 1099 <code>pos</code>.<br>The number of <code>min[pos - begin(), max[0, n - reserve()]]</code> elements will
Chris@16 1100 be overwritten at the beginning of the <code>circular_buffer_space_optimized</code>.<br>(See
Chris@16 1101 <i>Example</i> for the explanation.)<br><br>
Chris@16 1102 The amount of allocated memory in the internal buffer may be predictively increased.
Chris@16 1103 \param pos An iterator specifying the position where the <code>item</code>s will be inserted.
Chris@16 1104 \param n The number of <code>item</code>s the to be inserted.
Chris@16 1105 \param item The element whose copies will be inserted.
Chris@16 1106 \throws "An allocation error" if memory is exhausted (<code>std::bad_alloc</code> if the standard allocator is
Chris@16 1107 used).
Chris@16 1108 Whatever <code>T::T(const T&)</code> throws.
Chris@16 1109 Whatever <code>T::operator = (const T&)</code> throws.
Chris@16 1110 \par Exception Safety
Chris@16 1111 Basic.
Chris@16 1112 \par Iterator Invalidation
Chris@16 1113 Invalidates all iterators pointing to the <code>circular_buffer_space_optimized</code> (except iterators
Chris@16 1114 equal to <code>end()</code>).
Chris@16 1115 \par Complexity
Chris@16 1116 Linear (in <code>min[capacity().%capacity(), size() + n]</code>).
Chris@16 1117 \par Example
Chris@16 1118 Consider a <code>circular_buffer_space_optimized</code> with the capacity of 6 and the size of 4. Its
Chris@16 1119 internal buffer may look like the one below.<br><br>
Chris@16 1120 <code>|1|2|3|4| | |</code><br>
Chris@16 1121 <code>p ___^</code><br><br>After inserting 5 elements at the position <code>p</code>:<br><br>
Chris@16 1122 <code>insert(p, (size_t)5, 0);</code><br><br>actually only 4 elements get inserted and elements
Chris@16 1123 <code>1</code> and <code>2</code> are overwritten. This is due to the fact the insert operation preserves
Chris@16 1124 the capacity. After insertion the internal buffer looks like this:<br><br><code>|0|0|0|0|3|4|</code><br>
Chris@16 1125 <br>For comparison if the capacity would not be preserved the internal buffer would then result in
Chris@16 1126 <code>|1|2|0|0|0|0|0|3|4|</code>.
Chris@16 1127 \sa <code>\link insert(iterator, param_value_type) insert(iterator, value_type)\endlink</code>,
Chris@16 1128 <code>insert(iterator, InputIterator, InputIterator)</code>,
Chris@16 1129 <code>\link rinsert(iterator, param_value_type) rinsert(iterator, value_type)\endlink</code>,
Chris@16 1130 <code>\link rinsert(iterator, size_type, param_value_type)
Chris@16 1131 rinsert(iterator, size_type, value_type)\endlink</code>,
Chris@16 1132 <code>rinsert(iterator, InputIterator, InputIterator)</code>
Chris@16 1133 */
Chris@16 1134 void insert(iterator pos, size_type n, param_value_type item) {
Chris@16 1135 size_type index = pos - begin();
Chris@16 1136 check_low_capacity(n);
Chris@16 1137 circular_buffer<T, Alloc>::insert(begin() + index, n, item);
Chris@16 1138 }
Chris@16 1139
Chris@16 1140 //! Insert the range <code>[first, last)</code> at the specified position.
Chris@16 1141 /*!
Chris@16 1142 \pre <code>pos</code> is a valid iterator pointing to the <code>circular_buffer_space_optimized</code> or its
Chris@16 1143 end.<br>Valid range <code>[first, last)</code> where <code>first</code> and <code>last</code> meet the
Chris@16 1144 requirements of an <a href="http://www.sgi.com/tech/stl/InputIterator.html">InputIterator</a>.
Chris@16 1145 \post Elements from the range
Chris@16 1146 <code>[first + max[0, distance(first, last) - (pos - begin()) - reserve()], last)</code> will be
Chris@16 1147 inserted at the position <code>pos</code>.<br>The number of <code>min[pos - begin(), max[0,
Chris@16 1148 distance(first, last) - reserve()]]</code> elements will be overwritten at the beginning of the
Chris@16 1149 <code>circular_buffer_space_optimized</code>.<br>(See <i>Example</i> for the explanation.)<br><br>
Chris@16 1150 The amount of allocated memory in the internal buffer may be predictively increased.
Chris@16 1151 \param pos An iterator specifying the position where the range will be inserted.
Chris@16 1152 \param first The beginning of the range to be inserted.
Chris@16 1153 \param last The end of the range to be inserted.
Chris@16 1154 \throws "An allocation error" if memory is exhausted (<code>std::bad_alloc</code> if the standard allocator is
Chris@16 1155 used).
Chris@16 1156 Whatever <code>T::T(const T&)</code> throws or nothing if <code>T::T(T&&)</code> is noexcept.
Chris@16 1157 \par Exception Safety
Chris@16 1158 Basic.
Chris@16 1159 \par Iterator Invalidation
Chris@16 1160 Invalidates all iterators pointing to the <code>circular_buffer_space_optimized</code> (except iterators
Chris@16 1161 equal to <code>end()</code>).
Chris@16 1162 \par Complexity
Chris@16 1163 Linear (in <code>[size() + std::distance(first, last)]</code>; in
Chris@16 1164 <code>min[capacity().%capacity(), size() + std::distance(first, last)]</code> if the
Chris@16 1165 <code>InputIterator</code> is a
Chris@16 1166 <a href="http://www.sgi.com/tech/stl/RandomAccessIterator.html">RandomAccessIterator</a>).
Chris@16 1167 \par Example
Chris@16 1168 Consider a <code>circular_buffer_space_optimized</code> with the capacity of 6 and the size of 4. Its
Chris@16 1169 internal buffer may look like the one below.<br><br>
Chris@16 1170 <code>|1|2|3|4| | |</code><br>
Chris@16 1171 <code>p ___^</code><br><br>After inserting a range of elements at the position <code>p</code>:<br><br>
Chris@16 1172 <code>int array[] = { 5, 6, 7, 8, 9 };</code><br><code>insert(p, array, array + 5);</code><br><br>
Chris@16 1173 actually only elements <code>6</code>, <code>7</code>, <code>8</code> and <code>9</code> from the
Chris@16 1174 specified range get inserted and elements <code>1</code> and <code>2</code> are overwritten. This is due
Chris@16 1175 to the fact the insert operation preserves the capacity. After insertion the internal buffer looks like
Chris@16 1176 this:<br><br><code>|6|7|8|9|3|4|</code><br><br>For comparison if the capacity would not be preserved the
Chris@16 1177 internal buffer would then result in <code>|1|2|5|6|7|8|9|3|4|</code>.
Chris@16 1178 \sa <code>\link insert(iterator, param_value_type) insert(iterator, value_type)\endlink</code>,
Chris@16 1179 <code>\link insert(iterator, size_type, param_value_type)
Chris@16 1180 insert(iterator, size_type, value_type)\endlink</code>, <code>\link rinsert(iterator, param_value_type)
Chris@16 1181 rinsert(iterator, value_type)\endlink</code>, <code>\link rinsert(iterator, size_type, param_value_type)
Chris@16 1182 rinsert(iterator, size_type, value_type)\endlink</code>,
Chris@16 1183 <code>rinsert(iterator, InputIterator, InputIterator)</code>
Chris@16 1184 */
Chris@16 1185 template <class InputIterator>
Chris@16 1186 void insert(iterator pos, InputIterator first, InputIterator last) {
Chris@16 1187 insert(pos, first, last, is_integral<InputIterator>());
Chris@16 1188 }
Chris@16 1189
Chris@16 1190 //! Insert an element before the specified position.
Chris@16 1191 /*!
Chris@16 1192 \pre <code>pos</code> is a valid iterator pointing to the <code>circular_buffer_space_optimized</code> or its
Chris@16 1193 end.
Chris@16 1194 \post The <code>item</code> will be inserted before the position <code>pos</code>.<br>
Chris@16 1195 If the <code>circular_buffer_space_optimized</code> is full, the last element will be overwritten. If the
Chris@16 1196 <code>circular_buffer_space_optimized</code> is full and the <code>pos</code> points to
Chris@16 1197 <code>end()</code>, then the <code>item</code> will not be inserted. If the capacity is <code>0</code>,
Chris@16 1198 nothing will be inserted.<br><br>
Chris@16 1199 The amount of allocated memory in the internal buffer may be predictively increased.
Chris@16 1200 \param pos An iterator specifying the position before which the <code>item</code> will be inserted.
Chris@16 1201 \param item The element to be inserted.
Chris@16 1202 \return Iterator to the inserted element or <code>end()</code> if the <code>item</code> is not inserted. (See
Chris@16 1203 the <i>Effect</i>.)
Chris@16 1204 \throws "An allocation error" if memory is exhausted (<code>std::bad_alloc</code> if the standard allocator is
Chris@16 1205 used).
Chris@16 1206 Whatever <code>T::T(const T&)</code> throws.
Chris@16 1207 Whatever <code>T::operator = (const T&)</code> throws.
Chris@16 1208 \par Exception Safety
Chris@16 1209 Basic.
Chris@16 1210 \par Iterator Invalidation
Chris@16 1211 Invalidates all iterators pointing to the <code>circular_buffer_space_optimized</code> (except iterators
Chris@16 1212 equal to <code>end()</code>).
Chris@16 1213 \par Complexity
Chris@16 1214 Linear (in the size of the <code>circular_buffer_space_optimized</code>).
Chris@16 1215 \sa <code>\link rinsert(iterator, size_type, param_value_type)
Chris@16 1216 rinsert(iterator, size_type, value_type)\endlink</code>,
Chris@16 1217 <code>rinsert(iterator, InputIterator, InputIterator)</code>,
Chris@16 1218 <code>\link insert(iterator, param_value_type) insert(iterator, value_type)\endlink</code>,
Chris@16 1219 <code>\link insert(iterator, size_type, param_value_type)
Chris@16 1220 insert(iterator, size_type, value_type)\endlink</code>,
Chris@16 1221 <code>insert(iterator, InputIterator, InputIterator)</code>
Chris@16 1222 */
Chris@16 1223 iterator rinsert(iterator pos, param_value_type item) {
Chris@16 1224 size_type index = pos - begin();
Chris@16 1225 check_low_capacity();
Chris@16 1226 return circular_buffer<T, Alloc>::rinsert(begin() + index, item);
Chris@16 1227 }
Chris@16 1228
Chris@16 1229 //! Insert an element before the specified position.
Chris@16 1230 /*!
Chris@16 1231 \pre <code>pos</code> is a valid iterator pointing to the <code>circular_buffer_space_optimized</code> or its
Chris@16 1232 end.
Chris@16 1233 \post The <code>item</code> will be inserted before the position <code>pos</code>.<br>
Chris@16 1234 If the <code>circular_buffer_space_optimized</code> is full, the last element will be overwritten. If the
Chris@16 1235 <code>circular_buffer_space_optimized</code> is full and the <code>pos</code> points to
Chris@16 1236 <code>end()</code>, then the <code>item</code> will not be inserted. If the capacity is <code>0</code>,
Chris@16 1237 nothing will be inserted.<br><br>
Chris@16 1238 The amount of allocated memory in the internal buffer may be predictively increased.
Chris@16 1239 \param pos An iterator specifying the position before which the <code>item</code> will be inserted.
Chris@16 1240 \param item The element to be inserted.
Chris@16 1241 \return Iterator to the inserted element or <code>end()</code> if the <code>item</code> is not inserted. (See
Chris@16 1242 the <i>Effect</i>.)
Chris@16 1243 \throws "An allocation error" if memory is exhausted (<code>std::bad_alloc</code> if the standard allocator is
Chris@16 1244 used).
Chris@16 1245 Whatever <code>T::T(const T&)</code> throws or nothing if <code>T::T(T&&)</code> is noexcept.
Chris@16 1246 \par Exception Safety
Chris@16 1247 Basic.
Chris@16 1248 \par Iterator Invalidation
Chris@16 1249 Invalidates all iterators pointing to the <code>circular_buffer_space_optimized</code> (except iterators
Chris@16 1250 equal to <code>end()</code>).
Chris@16 1251 \par Complexity
Chris@16 1252 Linear (in the size of the <code>circular_buffer_space_optimized</code>).
Chris@16 1253 \sa <code>\link rinsert(iterator, size_type, param_value_type)
Chris@16 1254 rinsert(iterator, size_type, value_type)\endlink</code>,
Chris@16 1255 <code>rinsert(iterator, InputIterator, InputIterator)</code>,
Chris@16 1256 <code>\link insert(iterator, param_value_type) insert(iterator, value_type)\endlink</code>,
Chris@16 1257 <code>\link insert(iterator, size_type, param_value_type)
Chris@16 1258 insert(iterator, size_type, value_type)\endlink</code>,
Chris@16 1259 <code>insert(iterator, InputIterator, InputIterator)</code>
Chris@16 1260 */
Chris@16 1261 iterator rinsert(iterator pos, rvalue_type item) {
Chris@16 1262 size_type index = pos - begin();
Chris@16 1263 check_low_capacity();
Chris@16 1264 return circular_buffer<T, Alloc>::rinsert(begin() + index, boost::move(item));
Chris@16 1265 }
Chris@16 1266
Chris@16 1267 //! Insert an element before the specified position.
Chris@16 1268 /*!
Chris@16 1269 \pre <code>pos</code> is a valid iterator pointing to the <code>circular_buffer_space_optimized</code> or its
Chris@16 1270 end.
Chris@16 1271 \post The <code>item</code> will be inserted before the position <code>pos</code>.<br>
Chris@16 1272 If the <code>circular_buffer_space_optimized</code> is full, the last element will be overwritten. If the
Chris@16 1273 <code>circular_buffer_space_optimized</code> is full and the <code>pos</code> points to
Chris@16 1274 <code>end()</code>, then the <code>item</code> will not be inserted. If the capacity is <code>0</code>,
Chris@16 1275 nothing will be inserted.<br><br>
Chris@16 1276 The amount of allocated memory in the internal buffer may be predictively increased.
Chris@16 1277 \param pos An iterator specifying the position before which the <code>item</code> will be inserted.
Chris@16 1278 \return Iterator to the inserted element or <code>end()</code> if the <code>item</code> is not inserted. (See
Chris@16 1279 the <i>Effect</i>.)
Chris@16 1280 \throws "An allocation error" if memory is exhausted (<code>std::bad_alloc</code> if the standard allocator is
Chris@16 1281 used).
Chris@16 1282 Whatever <code>T::T()</code> throws.
Chris@16 1283 Whatever <code>T::T(const T&)</code> throws or nothing if <code>T::T(T&&)</code> is noexcept.
Chris@16 1284 \par Exception Safety
Chris@16 1285 Basic.
Chris@16 1286 \par Iterator Invalidation
Chris@16 1287 Invalidates all iterators pointing to the <code>circular_buffer_space_optimized</code> (except iterators
Chris@16 1288 equal to <code>end()</code>).
Chris@16 1289 \par Complexity
Chris@16 1290 Linear (in the size of the <code>circular_buffer_space_optimized</code>).
Chris@16 1291 \sa <code>\link rinsert(iterator, size_type, param_value_type)
Chris@16 1292 rinsert(iterator, size_type, value_type)\endlink</code>,
Chris@16 1293 <code>rinsert(iterator, InputIterator, InputIterator)</code>,
Chris@16 1294 <code>\link insert(iterator, param_value_type) insert(iterator, value_type)\endlink</code>,
Chris@16 1295 <code>\link insert(iterator, size_type, param_value_type)
Chris@16 1296 insert(iterator, size_type, value_type)\endlink</code>,
Chris@16 1297 <code>insert(iterator, InputIterator, InputIterator)</code>
Chris@16 1298 */
Chris@16 1299 iterator rinsert(iterator pos) {
Chris@16 1300 size_type index = pos - begin();
Chris@16 1301 check_low_capacity();
Chris@16 1302 return circular_buffer<T, Alloc>::rinsert(begin() + index);
Chris@16 1303 }
Chris@16 1304
Chris@16 1305 //! Insert <code>n</code> copies of the <code>item</code> before the specified position.
Chris@16 1306 /*!
Chris@16 1307 \pre <code>pos</code> is a valid iterator pointing to the <code>circular_buffer_space_optimized</code> or its
Chris@16 1308 end.
Chris@16 1309 \post The number of <code>min[n, (end() - pos) + reserve()]</code> elements will be inserted before the
Chris@16 1310 position <code>pos</code>.<br>The number of <code>min[end() - pos, max[0, n - reserve()]]</code> elements
Chris@16 1311 will be overwritten at the end of the <code>circular_buffer_space_optimized</code>.<br>(See
Chris@16 1312 <i>Example</i> for the explanation.)<br><br>
Chris@16 1313 The amount of allocated memory in the internal buffer may be predictively increased.
Chris@16 1314 \param pos An iterator specifying the position where the <code>item</code>s will be inserted.
Chris@16 1315 \param n The number of <code>item</code>s the to be inserted.
Chris@16 1316 \param item The element whose copies will be inserted.
Chris@16 1317 \throws "An allocation error" if memory is exhausted (<code>std::bad_alloc</code> if the standard allocator is
Chris@16 1318 used).
Chris@16 1319 Whatever <code>T::T(const T&)</code> throws.
Chris@16 1320 Whatever <code>T::operator = (const T&)</code> throws.
Chris@16 1321 \par Exception Safety
Chris@16 1322 Basic.
Chris@16 1323 \par Iterator Invalidation
Chris@16 1324 Invalidates all iterators pointing to the <code>circular_buffer_space_optimized</code> (except iterators
Chris@16 1325 equal to <code>end()</code>).
Chris@16 1326 \par Complexity
Chris@16 1327 Linear (in <code>min[capacity().%capacity(), size() + n]</code>).
Chris@16 1328 \par Example
Chris@16 1329 Consider a <code>circular_buffer_space_optimized</code> with the capacity of 6 and the size of 4. Its
Chris@16 1330 internal buffer may look like the one below.<br><br>
Chris@16 1331 <code>|1|2|3|4| | |</code><br>
Chris@16 1332 <code>p ___^</code><br><br>After inserting 5 elements before the position <code>p</code>:<br><br>
Chris@16 1333 <code>rinsert(p, (size_t)5, 0);</code><br><br>actually only 4 elements get inserted and elements
Chris@16 1334 <code>3</code> and <code>4</code> are overwritten. This is due to the fact the rinsert operation preserves
Chris@16 1335 the capacity. After insertion the internal buffer looks like this:<br><br><code>|1|2|0|0|0|0|</code><br>
Chris@16 1336 <br>For comparison if the capacity would not be preserved the internal buffer would then result in
Chris@16 1337 <code>|1|2|0|0|0|0|0|3|4|</code>.
Chris@16 1338 \sa <code>\link rinsert(iterator, param_value_type) rinsert(iterator, value_type)\endlink</code>,
Chris@16 1339 <code>rinsert(iterator, InputIterator, InputIterator)</code>,
Chris@16 1340 <code>\link insert(iterator, param_value_type) insert(iterator, value_type)\endlink</code>,
Chris@16 1341 <code>\link insert(iterator, size_type, param_value_type)
Chris@16 1342 insert(iterator, size_type, value_type)\endlink</code>,
Chris@16 1343 <code>insert(iterator, InputIterator, InputIterator)</code>
Chris@16 1344 */
Chris@16 1345 void rinsert(iterator pos, size_type n, param_value_type item) {
Chris@16 1346 size_type index = pos - begin();
Chris@16 1347 check_low_capacity(n);
Chris@16 1348 circular_buffer<T, Alloc>::rinsert(begin() + index, n, item);
Chris@16 1349 }
Chris@16 1350
Chris@16 1351 //! Insert the range <code>[first, last)</code> before the specified position.
Chris@16 1352 /*!
Chris@16 1353 \pre <code>pos</code> is a valid iterator pointing to the <code>circular_buffer_space_optimized</code> or its
Chris@16 1354 end.<br>
Chris@16 1355 Valid range <code>[first, last)</code> where <code>first</code> and <code>last</code> meet the
Chris@16 1356 requirements of an <a href="http://www.sgi.com/tech/stl/InputIterator.html">InputIterator</a>.
Chris@16 1357 \post Elements from the range
Chris@16 1358 <code>[first, last - max[0, distance(first, last) - (end() - pos) - reserve()])</code> will be inserted
Chris@16 1359 before the position <code>pos</code>.<br>The number of <code>min[end() - pos, max[0,
Chris@16 1360 distance(first, last) - reserve()]]</code> elements will be overwritten at the end of the
Chris@16 1361 <code>circular_buffer</code>.<br>(See <i>Example</i> for the explanation.)<br><br>
Chris@16 1362 The amount of allocated memory in the internal buffer may be predictively increased.
Chris@16 1363 \param pos An iterator specifying the position where the range will be inserted.
Chris@16 1364 \param first The beginning of the range to be inserted.
Chris@16 1365 \param last The end of the range to be inserted.
Chris@16 1366 \throws "An allocation error" if memory is exhausted (<code>std::bad_alloc</code> if the standard allocator is
Chris@16 1367 used).
Chris@16 1368 Whatever <code>T::T(const T&)</code> throws.
Chris@16 1369 Whatever <code>T::operator = (const T&)</code> throws.
Chris@16 1370 \par Exception Safety
Chris@16 1371 Basic.
Chris@16 1372 \par Iterator Invalidation
Chris@16 1373 Invalidates all iterators pointing to the <code>circular_buffer_space_optimized</code> (except iterators
Chris@16 1374 equal to <code>end()</code>).
Chris@16 1375 \par Complexity
Chris@16 1376 Linear (in <code>[size() + std::distance(first, last)]</code>; in
Chris@16 1377 <code>min[capacity().%capacity(), size() + std::distance(first, last)]</code> if the
Chris@16 1378 <code>InputIterator</code> is a
Chris@16 1379 <a href="http://www.sgi.com/tech/stl/RandomAccessIterator.html">RandomAccessIterator</a>).
Chris@16 1380 \par Example
Chris@16 1381 Consider a <code>circular_buffer_space_optimized</code> with the capacity of 6 and the size of 4. Its
Chris@16 1382 internal buffer may look like the one below.<br><br>
Chris@16 1383 <code>|1|2|3|4| | |</code><br>
Chris@16 1384 <code>p ___^</code><br><br>After inserting a range of elements before the position <code>p</code>:<br><br>
Chris@16 1385 <code>int array[] = { 5, 6, 7, 8, 9 };</code><br><code>insert(p, array, array + 5);</code><br><br>
Chris@16 1386 actually only elements <code>5</code>, <code>6</code>, <code>7</code> and <code>8</code> from the
Chris@16 1387 specified range get inserted and elements <code>3</code> and <code>4</code> are overwritten. This is due
Chris@16 1388 to the fact the rinsert operation preserves the capacity. After insertion the internal buffer looks like
Chris@16 1389 this:<br><br><code>|1|2|5|6|7|8|</code><br><br>For comparison if the capacity would not be preserved the
Chris@16 1390 internal buffer would then result in <code>|1|2|5|6|7|8|9|3|4|</code>.
Chris@16 1391 \sa <code>\link rinsert(iterator, param_value_type) rinsert(iterator, value_type)\endlink</code>,
Chris@16 1392 <code>\link rinsert(iterator, size_type, param_value_type)
Chris@16 1393 rinsert(iterator, size_type, value_type)\endlink</code>, <code>\link insert(iterator, param_value_type)
Chris@16 1394 insert(iterator, value_type)\endlink</code>, <code>\link insert(iterator, size_type, param_value_type)
Chris@16 1395 insert(iterator, size_type, value_type)\endlink</code>,
Chris@16 1396 <code>insert(iterator, InputIterator, InputIterator)</code>
Chris@16 1397 */
Chris@16 1398 template <class InputIterator>
Chris@16 1399 void rinsert(iterator pos, InputIterator first, InputIterator last) {
Chris@16 1400 rinsert(pos, first, last, is_integral<InputIterator>());
Chris@16 1401 }
Chris@16 1402
Chris@16 1403 //! Remove an element at the specified position.
Chris@16 1404 /*!
Chris@16 1405 \pre <code>pos</code> is a valid iterator pointing to the <code>circular_buffer_space_optimized</code> (but not
Chris@16 1406 an <code>end()</code>).
Chris@16 1407 \post The element at the position <code>pos</code> is removed.<br><br>
Chris@16 1408 The amount of allocated memory in the internal buffer may be predictively decreased.
Chris@16 1409 \param pos An iterator pointing at the element to be removed.
Chris@16 1410 \return Iterator to the first element remaining beyond the removed element or <code>end()</code> if no such
Chris@16 1411 element exists.
Chris@16 1412 \throws "An allocation error" if memory is exhausted (<code>std::bad_alloc</code> if the standard allocator is
Chris@16 1413 used).
Chris@16 1414 Whatever <code>T::operator = (const T&)</code> throws or
Chris@16 1415 nothing if <code>T::operator = (T&&)</code> is noexcept.
Chris@16 1416 \par Exception Safety
Chris@16 1417 Basic.
Chris@16 1418 \par Iterator Invalidation
Chris@16 1419 Invalidates all iterators pointing to the <code>circular_buffer_space_optimized</code> (except iterators
Chris@16 1420 equal to <code>end()</code>).
Chris@16 1421 \par Complexity
Chris@16 1422 Linear (in the size of the <code>circular_buffer_space_optimized</code>).
Chris@16 1423 \sa <code>erase(iterator, iterator)</code>, <code>rerase(iterator)</code>,
Chris@16 1424 <code>rerase(iterator, iterator)</code>, <code>clear()</code>
Chris@16 1425 */
Chris@16 1426 iterator erase(iterator pos) {
Chris@16 1427 iterator it = circular_buffer<T, Alloc>::erase(pos);
Chris@16 1428 size_type index = it - begin();
Chris@16 1429 check_high_capacity();
Chris@16 1430 return begin() + index;
Chris@16 1431 }
Chris@16 1432
Chris@16 1433 //! Erase the range <code>[first, last)</code>.
Chris@16 1434 /*!
Chris@16 1435 \pre Valid range <code>[first, last)</code>.
Chris@16 1436 \post The elements from the range <code>[first, last)</code> are removed. (If <code>first == last</code>
Chris@16 1437 nothing is removed.)<br><br>
Chris@16 1438 The amount of allocated memory in the internal buffer may be predictively decreased.
Chris@16 1439 \param first The beginning of the range to be removed.
Chris@16 1440 \param last The end of the range to be removed.
Chris@16 1441 \return Iterator to the first element remaining beyond the removed elements or <code>end()</code> if no such
Chris@16 1442 element exists.
Chris@16 1443 \throws "An allocation error" if memory is exhausted (<code>std::bad_alloc</code> if the standard allocator is
Chris@16 1444 used).
Chris@16 1445 Whatever <code>T::operator = (const T&)</code> throws or
Chris@16 1446 nothing if <code>T::operator = (T&&)</code> is noexcept.
Chris@16 1447 \par Exception Safety
Chris@16 1448 Basic.
Chris@16 1449 \par Iterator Invalidation
Chris@16 1450 Invalidates all iterators pointing to the <code>circular_buffer_space_optimized</code> (except iterators
Chris@16 1451 equal to <code>end()</code>).
Chris@16 1452 \par Complexity
Chris@16 1453 Linear (in the size of the <code>circular_buffer_space_optimized</code>).
Chris@16 1454 \sa <code>erase(iterator)</code>, <code>rerase(iterator)</code>, <code>rerase(iterator, iterator)</code>,
Chris@16 1455 <code>clear()</code>
Chris@16 1456 */
Chris@16 1457 iterator erase(iterator first, iterator last) {
Chris@16 1458 iterator it = circular_buffer<T, Alloc>::erase(first, last);
Chris@16 1459 size_type index = it - begin();
Chris@16 1460 check_high_capacity();
Chris@16 1461 return begin() + index;
Chris@16 1462 }
Chris@16 1463
Chris@16 1464 //! Remove an element at the specified position.
Chris@16 1465 /*!
Chris@16 1466 \pre <code>pos</code> is a valid iterator pointing to the <code>circular_buffer_space_optimized</code> (but not
Chris@16 1467 an <code>end()</code>).<br><br>
Chris@16 1468 The amount of allocated memory in the internal buffer may be predictively decreased.
Chris@16 1469 \post The element at the position <code>pos</code> is removed.
Chris@16 1470 \param pos An iterator pointing at the element to be removed.
Chris@16 1471 \return Iterator to the first element remaining in front of the removed element or <code>begin()</code> if no
Chris@16 1472 such element exists.
Chris@16 1473 \throws "An allocation error" if memory is exhausted (<code>std::bad_alloc</code> if the standard allocator is
Chris@16 1474 used).
Chris@16 1475 Whatever <code>T::operator = (const T&)</code> throws or
Chris@16 1476 nothing if <code>T::operator = (T&&)</code> is noexcept.
Chris@16 1477 \par Exception Safety
Chris@16 1478 Basic.
Chris@16 1479 \par Iterator Invalidation
Chris@16 1480 Invalidates all iterators pointing to the <code>circular_buffer_space_optimized</code> (except iterators
Chris@16 1481 equal to <code>end()</code>).
Chris@16 1482 \par Complexity
Chris@16 1483 Linear (in the size of the <code>circular_buffer_space_optimized</code>).
Chris@16 1484 \note Basically there is no difference between <code>erase(iterator)</code> and this method. It is implemented
Chris@16 1485 only for consistency with the base <code>circular_buffer</code>.
Chris@16 1486 \sa <code>erase(iterator)</code>, <code>erase(iterator, iterator)</code>,
Chris@16 1487 <code>rerase(iterator, iterator)</code>, <code>clear()</code>
Chris@16 1488 */
Chris@16 1489 iterator rerase(iterator pos) {
Chris@16 1490 iterator it = circular_buffer<T, Alloc>::rerase(pos);
Chris@16 1491 size_type index = it - begin();
Chris@16 1492 check_high_capacity();
Chris@16 1493 return begin() + index;
Chris@16 1494 }
Chris@16 1495
Chris@16 1496 //! Erase the range <code>[first, last)</code>.
Chris@16 1497 /*!
Chris@16 1498 \pre Valid range <code>[first, last)</code>.
Chris@16 1499 \post The elements from the range <code>[first, last)</code> are removed. (If <code>first == last</code>
Chris@16 1500 nothing is removed.)<br><br>
Chris@16 1501 The amount of allocated memory in the internal buffer may be predictively decreased.
Chris@16 1502 \param first The beginning of the range to be removed.
Chris@16 1503 \param last The end of the range to be removed.
Chris@16 1504 \return Iterator to the first element remaining in front of the removed elements or <code>begin()</code> if no
Chris@16 1505 such element exists.
Chris@16 1506 \throws "An allocation error" if memory is exhausted (<code>std::bad_alloc</code> if the standard allocator is
Chris@16 1507 used).
Chris@16 1508 Whatever <code>T::operator = (const T&)</code> throws or
Chris@16 1509 nothing if <code>T::operator = (T&&)</code> is noexcept.
Chris@16 1510 \par Exception Safety
Chris@16 1511 Basic.
Chris@16 1512 \par Iterator Invalidation
Chris@16 1513 Invalidates all iterators pointing to the <code>circular_buffer_space_optimized</code> (except iterators
Chris@16 1514 equal to <code>end()</code>).
Chris@16 1515 \par Complexity
Chris@16 1516 Linear (in the size of the <code>circular_buffer_space_optimized</code>).
Chris@16 1517 \note Basically there is no difference between <code>erase(iterator, iterator)</code> and this method. It is
Chris@16 1518 implemented only for consistency with the base
Chris@16 1519 <code><circular_buffer</code>.
Chris@16 1520 \sa <code>erase(iterator)</code>, <code>erase(iterator, iterator)</code>, <code>rerase(iterator)</code>,
Chris@16 1521 <code>clear()</code>
Chris@16 1522 */
Chris@16 1523 iterator rerase(iterator first, iterator last) {
Chris@16 1524 iterator it = circular_buffer<T, Alloc>::rerase(first, last);
Chris@16 1525 size_type index = it - begin();
Chris@16 1526 check_high_capacity();
Chris@16 1527 return begin() + index;
Chris@16 1528 }
Chris@16 1529
Chris@16 1530 //! Remove all stored elements from the space optimized circular buffer.
Chris@16 1531 /*!
Chris@16 1532 \post <code>size() == 0</code><br><br>
Chris@16 1533 The amount of allocated memory in the internal buffer may be predictively decreased.
Chris@16 1534 \throws "An allocation error" if memory is exhausted (<code>std::bad_alloc</code> if the standard allocator is
Chris@16 1535 used).
Chris@16 1536 \par Exception Safety
Chris@16 1537 Basic.
Chris@16 1538 \par Iterator Invalidation
Chris@16 1539 Invalidates all iterators pointing to the <code>circular_buffer_space_optimized</code> (except iterators
Chris@16 1540 equal to <code>end()</code>).
Chris@16 1541 \par Complexity
Chris@16 1542 Linear (in the size of the <code>circular_buffer_space_optimized</code>).
Chris@16 1543 \sa <code>~circular_buffer_space_optimized()</code>, <code>erase(iterator)</code>,
Chris@16 1544 <code>erase(iterator, iterator)</code>, <code>rerase(iterator)</code>,
Chris@16 1545 <code>rerase(iterator, iterator)</code>
Chris@16 1546 */
Chris@16 1547 void clear() { erase(begin(), end()); }
Chris@16 1548
Chris@16 1549 private:
Chris@16 1550 // Helper methods
Chris@16 1551
Chris@16 1552 //! Adjust the amount of allocated memory.
Chris@16 1553 void adjust_min_capacity() {
Chris@16 1554 if (m_capacity_ctrl.min_capacity() > circular_buffer<T, Alloc>::capacity())
Chris@16 1555 circular_buffer<T, Alloc>::set_capacity(m_capacity_ctrl.min_capacity());
Chris@16 1556 else
Chris@16 1557 check_high_capacity();
Chris@16 1558 }
Chris@16 1559
Chris@16 1560 //! Ensure the reserve for possible growth up.
Chris@16 1561 size_type ensure_reserve(size_type new_capacity, size_type buffer_size) const {
Chris@16 1562 if (buffer_size + new_capacity / 5 >= new_capacity)
Chris@16 1563 new_capacity *= 2; // ensure at least 20% reserve
Chris@16 1564 if (new_capacity > m_capacity_ctrl)
Chris@16 1565 return m_capacity_ctrl;
Chris@16 1566 return new_capacity;
Chris@16 1567 }
Chris@16 1568
Chris@16 1569 //! Check for low capacity.
Chris@16 1570 /*
Chris@16 1571 \post If the capacity is low it will be increased.
Chris@16 1572 */
Chris@16 1573 void check_low_capacity(size_type n = 1) {
Chris@16 1574 size_type new_size = size() + n;
Chris@16 1575 size_type new_capacity = circular_buffer<T, Alloc>::capacity();
Chris@16 1576 if (new_size > new_capacity) {
Chris@16 1577 if (new_capacity == 0)
Chris@16 1578 new_capacity = 1;
Chris@16 1579 for (; new_size > new_capacity; new_capacity *= 2) {}
Chris@16 1580 circular_buffer<T, Alloc>::set_capacity(
Chris@16 1581 ensure_reserve(new_capacity, new_size));
Chris@16 1582 }
Chris@16 1583 #if BOOST_CB_ENABLE_DEBUG
Chris@16 1584 this->invalidate_iterators_except(end());
Chris@16 1585 #endif
Chris@16 1586 }
Chris@16 1587
Chris@16 1588 //! Check for high capacity.
Chris@16 1589 /*
Chris@16 1590 \post If the capacity is high it will be decreased.
Chris@16 1591 */
Chris@16 1592 void check_high_capacity() {
Chris@16 1593 size_type new_capacity = circular_buffer<T, Alloc>::capacity();
Chris@16 1594 while (new_capacity / 3 >= size()) { // (new_capacity / 3) -> avoid oscillations
Chris@16 1595 new_capacity /= 2;
Chris@16 1596 if (new_capacity <= m_capacity_ctrl.min_capacity()) {
Chris@16 1597 new_capacity = m_capacity_ctrl.min_capacity();
Chris@16 1598 break;
Chris@16 1599 }
Chris@16 1600 }
Chris@16 1601 circular_buffer<T, Alloc>::set_capacity(
Chris@16 1602 ensure_reserve(new_capacity, size()));
Chris@16 1603 #if BOOST_CB_ENABLE_DEBUG
Chris@16 1604 this->invalidate_iterators_except(end());
Chris@16 1605 #endif
Chris@16 1606 }
Chris@16 1607
Chris@16 1608 //! Specialized method for reducing the capacity.
Chris@16 1609 void reduce_capacity(const true_type&) {
Chris@16 1610 circular_buffer<T, Alloc>::set_capacity((std::max)(m_capacity_ctrl.min_capacity(), size()));
Chris@16 1611 }
Chris@16 1612
Chris@16 1613 //! Specialized method for reducing the capacity.
Chris@16 1614 void reduce_capacity(const false_type&) {}
Chris@16 1615
Chris@16 1616 //! Determine the initial capacity.
Chris@16 1617 static size_type init_capacity(const capacity_type& capacity_ctrl, size_type n) {
Chris@16 1618 BOOST_CB_ASSERT(capacity_ctrl.capacity() >= n); // check for capacity lower than n
Chris@16 1619 return (std::max)(capacity_ctrl.min_capacity(), n);
Chris@16 1620 }
Chris@16 1621
Chris@16 1622 //! Specialized method for determining the initial capacity.
Chris@16 1623 template <class IntegralType>
Chris@16 1624 static size_type init_capacity(const capacity_type& capacity_ctrl, IntegralType n, IntegralType,
Chris@16 1625 const true_type&) {
Chris@16 1626 return init_capacity(capacity_ctrl, static_cast<size_type>(n));
Chris@16 1627 }
Chris@16 1628
Chris@16 1629 //! Specialized method for determining the initial capacity.
Chris@16 1630 template <class Iterator>
Chris@16 1631 static size_type init_capacity(const capacity_type& capacity_ctrl, Iterator first, Iterator last,
Chris@16 1632 const false_type&) {
Chris@16 1633 BOOST_CB_IS_CONVERTIBLE(Iterator, value_type); // check for invalid iterator type
Chris@16 1634 #if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x581))
Chris@16 1635 return init_capacity(capacity_ctrl, first, last, BOOST_ITERATOR_CATEGORY<Iterator>::type());
Chris@16 1636 #else
Chris@16 1637 return init_capacity(
Chris@16 1638 capacity_ctrl, first, last, BOOST_DEDUCED_TYPENAME BOOST_ITERATOR_CATEGORY<Iterator>::type());
Chris@16 1639 #endif
Chris@16 1640 }
Chris@16 1641
Chris@16 1642 //! Specialized method for determining the initial capacity.
Chris@16 1643 template <class InputIterator>
Chris@16 1644 static size_type init_capacity(const capacity_type& capacity_ctrl, InputIterator, InputIterator,
Chris@16 1645 const std::input_iterator_tag&) {
Chris@16 1646 return capacity_ctrl.capacity();
Chris@16 1647 }
Chris@16 1648
Chris@16 1649 //! Specialized method for determining the initial capacity.
Chris@16 1650 template <class ForwardIterator>
Chris@16 1651 static size_type init_capacity(const capacity_type& capacity_ctrl, ForwardIterator first, ForwardIterator last,
Chris@16 1652 const std::forward_iterator_tag&) {
Chris@16 1653 BOOST_CB_ASSERT(std::distance(first, last) >= 0); // check for wrong range
Chris@16 1654 return (std::max)(capacity_ctrl.min_capacity(),
Chris@16 1655 (std::min)(capacity_ctrl.capacity(), static_cast<size_type>(std::distance(first, last))));
Chris@16 1656 }
Chris@16 1657
Chris@16 1658 //! Specialized insert method.
Chris@16 1659 template <class IntegralType>
Chris@16 1660 void insert(const iterator& pos, IntegralType n, IntegralType item, const true_type&) {
Chris@16 1661 insert(pos, static_cast<size_type>(n), static_cast<value_type>(item));
Chris@16 1662 }
Chris@16 1663
Chris@16 1664 //! Specialized insert method.
Chris@16 1665 template <class Iterator>
Chris@16 1666 void insert(const iterator& pos, Iterator first, Iterator last, const false_type&) {
Chris@16 1667 size_type index = pos - begin();
Chris@16 1668 check_low_capacity(std::distance(first, last));
Chris@16 1669 circular_buffer<T, Alloc>::insert(begin() + index, first, last);
Chris@16 1670 }
Chris@16 1671
Chris@16 1672 //! Specialized rinsert method.
Chris@16 1673 template <class IntegralType>
Chris@16 1674 void rinsert(const iterator& pos, IntegralType n, IntegralType item, const true_type&) {
Chris@16 1675 rinsert(pos, static_cast<size_type>(n), static_cast<value_type>(item));
Chris@16 1676 }
Chris@16 1677
Chris@16 1678 //! Specialized rinsert method.
Chris@16 1679 template <class Iterator>
Chris@16 1680 void rinsert(const iterator& pos, Iterator first, Iterator last, const false_type&) {
Chris@16 1681 size_type index = pos - begin();
Chris@16 1682 check_low_capacity(std::distance(first, last));
Chris@16 1683 circular_buffer<T, Alloc>::rinsert(begin() + index, first, last);
Chris@16 1684 }
Chris@16 1685 };
Chris@16 1686
Chris@16 1687 // Non-member functions
Chris@16 1688
Chris@16 1689 //! Test two space optimized circular buffers for equality.
Chris@16 1690 template <class T, class Alloc>
Chris@16 1691 inline bool operator == (const circular_buffer_space_optimized<T, Alloc>& lhs,
Chris@16 1692 const circular_buffer_space_optimized<T, Alloc>& rhs) {
Chris@16 1693 return lhs.size() == rhs.size() &&
Chris@16 1694 std::equal(lhs.begin(), lhs.end(), rhs.begin());
Chris@16 1695 }
Chris@16 1696
Chris@16 1697 //! Lexicographical comparison.
Chris@16 1698 template <class T, class Alloc>
Chris@16 1699 inline bool operator < (const circular_buffer_space_optimized<T, Alloc>& lhs,
Chris@16 1700 const circular_buffer_space_optimized<T, Alloc>& rhs) {
Chris@16 1701 return std::lexicographical_compare(
Chris@16 1702 lhs.begin(), lhs.end(), rhs.begin(), rhs.end());
Chris@16 1703 }
Chris@16 1704
Chris@16 1705 #if !defined(BOOST_NO_FUNCTION_TEMPLATE_ORDERING) || BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1310))
Chris@16 1706
Chris@16 1707 //! Test two space optimized circular buffers for non-equality.
Chris@16 1708 template <class T, class Alloc>
Chris@16 1709 inline bool operator != (const circular_buffer_space_optimized<T, Alloc>& lhs,
Chris@16 1710 const circular_buffer_space_optimized<T, Alloc>& rhs) {
Chris@16 1711 return !(lhs == rhs);
Chris@16 1712 }
Chris@16 1713
Chris@16 1714 //! Lexicographical comparison.
Chris@16 1715 template <class T, class Alloc>
Chris@16 1716 inline bool operator > (const circular_buffer_space_optimized<T, Alloc>& lhs,
Chris@16 1717 const circular_buffer_space_optimized<T, Alloc>& rhs) {
Chris@16 1718 return rhs < lhs;
Chris@16 1719 }
Chris@16 1720
Chris@16 1721 //! Lexicographical comparison.
Chris@16 1722 template <class T, class Alloc>
Chris@16 1723 inline bool operator <= (const circular_buffer_space_optimized<T, Alloc>& lhs,
Chris@16 1724 const circular_buffer_space_optimized<T, Alloc>& rhs) {
Chris@16 1725 return !(rhs < lhs);
Chris@16 1726 }
Chris@16 1727
Chris@16 1728 //! Lexicographical comparison.
Chris@16 1729 template <class T, class Alloc>
Chris@16 1730 inline bool operator >= (const circular_buffer_space_optimized<T, Alloc>& lhs,
Chris@16 1731 const circular_buffer_space_optimized<T, Alloc>& rhs) {
Chris@16 1732 return !(lhs < rhs);
Chris@16 1733 }
Chris@16 1734
Chris@16 1735 //! Swap the contents of two space optimized circular buffers.
Chris@16 1736 template <class T, class Alloc>
Chris@16 1737 inline void swap(circular_buffer_space_optimized<T, Alloc>& lhs,
Chris@16 1738 circular_buffer_space_optimized<T, Alloc>& rhs) BOOST_NOEXCEPT {
Chris@16 1739 lhs.swap(rhs);
Chris@16 1740 }
Chris@16 1741
Chris@16 1742 #endif // #if !defined(BOOST_NO_FUNCTION_TEMPLATE_ORDERING) || BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1310))
Chris@16 1743
Chris@16 1744 } // namespace boost
Chris@16 1745
Chris@16 1746 #endif // #if !defined(BOOST_CIRCULAR_BUFFER_SPACE_OPTIMIZED_HPP)