Brian Silverman | fad8f55 | 2018-08-04 23:36:19 -0700 | [diff] [blame^] | 1 | // Boost.Container varray |
| 2 | // |
| 3 | // Copyright (c) 2012-2013 Adam Wulkiewicz, Lodz, Poland. |
| 4 | // Copyright (c) 2011-2013 Andrew Hundt. |
| 5 | // Copyright (c) 2014-2014 Ion Gaztanaga |
| 6 | // |
| 7 | // Use, modification and distribution is subject to the Boost Software License, |
| 8 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at |
| 9 | // http://www.boost.org/LICENSE_1_0.txt) |
| 10 | |
| 11 | #ifndef BOOST_CONTAINER_VARRAY_HPP |
| 12 | #define BOOST_CONTAINER_VARRAY_HPP |
| 13 | |
| 14 | #ifndef BOOST_CONFIG_HPP |
| 15 | # include <boost/config.hpp> |
| 16 | #endif |
| 17 | |
| 18 | #if defined(BOOST_HAS_PRAGMA_ONCE) |
| 19 | # pragma once |
| 20 | #endif |
| 21 | |
| 22 | #include <boost/container/detail/config_begin.hpp> |
| 23 | |
| 24 | #include "detail/varray.hpp" |
| 25 | #include <boost/move/utility_core.hpp> |
| 26 | |
| 27 | namespace boost { namespace container { |
| 28 | |
| 29 | /** |
| 30 | * @defgroup varray_non_member varray non-member functions |
| 31 | */ |
| 32 | |
| 33 | /** |
| 34 | * @brief A variable-size array container with fixed capacity. |
| 35 | * |
| 36 | * varray is a sequence container like boost::container::vector with contiguous storage that can |
| 37 | * change in size, along with the static allocation, low overhead, and fixed capacity of boost::array. |
| 38 | * |
| 39 | * A varray is a sequence that supports random access to elements, constant time insertion and |
| 40 | * removal of elements at the end, and linear time insertion and removal of elements at the beginning or |
| 41 | * in the middle. The number of elements in a varray may vary dynamically up to a fixed capacity |
| 42 | * because elements are stored within the object itself similarly to an array. However, objects are |
| 43 | * initialized as they are inserted into varray unlike C arrays or std::array which must construct |
| 44 | * all elements on instantiation. The behavior of varray enables the use of statically allocated |
| 45 | * elements in cases with complex object lifetime requirements that would otherwise not be trivially |
| 46 | * possible. |
| 47 | * |
| 48 | * @par Error Handling |
| 49 | * Insertion beyond the capacity and out of bounds errors result in undefined behavior. |
| 50 | * The reason for this is because unlike vectors, varray does not perform allocation. |
| 51 | * |
| 52 | * @tparam Value The type of element that will be stored. |
| 53 | * @tparam Capacity The maximum number of elements varray can store, fixed at compile time. |
| 54 | */ |
| 55 | template <typename Value, std::size_t Capacity> |
| 56 | class varray |
| 57 | : public dtl::varray<Value, Capacity> |
| 58 | { |
| 59 | typedef dtl::varray<Value, Capacity> base_t; |
| 60 | |
| 61 | BOOST_COPYABLE_AND_MOVABLE(varray) |
| 62 | |
| 63 | public: |
| 64 | //! @brief The type of elements stored in the container. |
| 65 | typedef typename base_t::value_type value_type; |
| 66 | //! @brief The unsigned integral type used by the container. |
| 67 | typedef typename base_t::size_type size_type; |
| 68 | //! @brief The pointers difference type. |
| 69 | typedef typename base_t::difference_type difference_type; |
| 70 | //! @brief The pointer type. |
| 71 | typedef typename base_t::pointer pointer; |
| 72 | //! @brief The const pointer type. |
| 73 | typedef typename base_t::const_pointer const_pointer; |
| 74 | //! @brief The value reference type. |
| 75 | typedef typename base_t::reference reference; |
| 76 | //! @brief The value const reference type. |
| 77 | typedef typename base_t::const_reference const_reference; |
| 78 | //! @brief The iterator type. |
| 79 | typedef typename base_t::iterator iterator; |
| 80 | //! @brief The const iterator type. |
| 81 | typedef typename base_t::const_iterator const_iterator; |
| 82 | //! @brief The reverse iterator type. |
| 83 | typedef typename base_t::reverse_iterator reverse_iterator; |
| 84 | //! @brief The const reverse iterator. |
| 85 | typedef typename base_t::const_reverse_iterator const_reverse_iterator; |
| 86 | |
| 87 | //! @brief Constructs an empty varray. |
| 88 | //! |
| 89 | //! @par Throws |
| 90 | //! Nothing. |
| 91 | //! |
| 92 | //! @par Complexity |
| 93 | //! Constant O(1). |
| 94 | varray() |
| 95 | : base_t() |
| 96 | {} |
| 97 | |
| 98 | //! @pre <tt>count <= capacity()</tt> |
| 99 | //! |
| 100 | //! @brief Constructs a varray containing count value initialized Values. |
| 101 | //! |
| 102 | //! @param count The number of values which will be contained in the container. |
| 103 | //! |
| 104 | //! @par Throws |
| 105 | //! If Value's value initialization throws. |
| 106 | //! |
| 107 | //! @par Complexity |
| 108 | //! Linear O(N). |
| 109 | explicit varray(size_type count) |
| 110 | : base_t(count) |
| 111 | {} |
| 112 | |
| 113 | //! @pre <tt>count <= capacity()</tt> |
| 114 | //! |
| 115 | //! @brief Constructs a varray containing count copies of value. |
| 116 | //! |
| 117 | //! @param count The number of copies of a values that will be contained in the container. |
| 118 | //! @param value The value which will be used to copy construct values. |
| 119 | //! |
| 120 | //! @par Throws |
| 121 | //! If Value's copy constructor throws. |
| 122 | //! |
| 123 | //! @par Complexity |
| 124 | //! Linear O(N). |
| 125 | varray(size_type count, value_type const& value) |
| 126 | : base_t(count, value) |
| 127 | {} |
| 128 | |
| 129 | //! @pre |
| 130 | //! @li <tt>distance(first, last) <= capacity()</tt> |
| 131 | //! @li Iterator must meet the \c ForwardTraversalIterator concept. |
| 132 | //! |
| 133 | //! @brief Constructs a varray containing copy of a range <tt>[first, last)</tt>. |
| 134 | //! |
| 135 | //! @param first The iterator to the first element in range. |
| 136 | //! @param last The iterator to the one after the last element in range. |
| 137 | //! |
| 138 | //! @par Throws |
| 139 | //! If Value's constructor taking a dereferenced Iterator throws. |
| 140 | //! |
| 141 | //! @par Complexity |
| 142 | //! Linear O(N). |
| 143 | template <typename Iterator> |
| 144 | varray(Iterator first, Iterator last) |
| 145 | : base_t(first, last) |
| 146 | {} |
| 147 | |
| 148 | //! @brief Constructs a copy of other varray. |
| 149 | //! |
| 150 | //! @param other The varray which content will be copied to this one. |
| 151 | //! |
| 152 | //! @par Throws |
| 153 | //! If Value's copy constructor throws. |
| 154 | //! |
| 155 | //! @par Complexity |
| 156 | //! Linear O(N). |
| 157 | varray(varray const& other) |
| 158 | : base_t(other) |
| 159 | {} |
| 160 | |
| 161 | //! @pre <tt>other.size() <= capacity()</tt>. |
| 162 | //! |
| 163 | //! @brief Constructs a copy of other varray. |
| 164 | //! |
| 165 | //! @param other The varray which content will be copied to this one. |
| 166 | //! |
| 167 | //! @par Throws |
| 168 | //! If Value's copy constructor throws. |
| 169 | //! |
| 170 | //! @par Complexity |
| 171 | //! Linear O(N). |
| 172 | template <std::size_t C> |
| 173 | varray(varray<value_type, C> const& other) : base_t(other) {} |
| 174 | |
| 175 | //! @brief Copy assigns Values stored in the other varray to this one. |
| 176 | //! |
| 177 | //! @param other The varray which content will be copied to this one. |
| 178 | //! |
| 179 | //! @par Throws |
| 180 | //! If Value's copy constructor or copy assignment throws. |
| 181 | //! |
| 182 | //! @par Complexity |
| 183 | //! Linear O(N). |
| 184 | varray & operator=(BOOST_COPY_ASSIGN_REF(varray) other) |
| 185 | { |
| 186 | base_t::operator=(static_cast<base_t const&>(other)); |
| 187 | return *this; |
| 188 | } |
| 189 | |
| 190 | //! @pre <tt>other.size() <= capacity()</tt> |
| 191 | //! |
| 192 | //! @brief Copy assigns Values stored in the other varray to this one. |
| 193 | //! |
| 194 | //! @param other The varray which content will be copied to this one. |
| 195 | //! |
| 196 | //! @par Throws |
| 197 | //! If Value's copy constructor or copy assignment throws. |
| 198 | //! |
| 199 | //! @par Complexity |
| 200 | //! Linear O(N). |
| 201 | template <std::size_t C> |
| 202 | // TEMPORARY WORKAROUND |
| 203 | #if defined(BOOST_NO_CXX11_RVALUE_REFERENCES) |
| 204 | varray & operator=(::boost::rv< varray<value_type, C> > const& other) |
| 205 | #else |
| 206 | varray & operator=(varray<value_type, C> const& other) |
| 207 | #endif |
| 208 | { |
| 209 | base_t::operator=(static_cast<varray<value_type, C> const&>(other)); |
| 210 | return *this; |
| 211 | } |
| 212 | |
| 213 | //! @brief Move constructor. Moves Values stored in the other varray to this one. |
| 214 | //! |
| 215 | //! @param other The varray which content will be moved to this one. |
| 216 | //! |
| 217 | //! @par Throws |
| 218 | //! @li If \c boost::has_nothrow_move<Value>::value is \c true and Value's move constructor throws. |
| 219 | //! @li If \c boost::has_nothrow_move<Value>::value is \c false and Value's copy constructor throws. |
| 220 | //! |
| 221 | //! @par Complexity |
| 222 | //! Linear O(N). |
| 223 | varray(BOOST_RV_REF(varray) other) |
| 224 | : base_t(boost::move(static_cast<base_t&>(other))) |
| 225 | {} |
| 226 | |
| 227 | //! @pre <tt>other.size() <= capacity()</tt> |
| 228 | //! |
| 229 | //! @brief Move constructor. Moves Values stored in the other varray to this one. |
| 230 | //! |
| 231 | //! @param other The varray which content will be moved to this one. |
| 232 | //! |
| 233 | //! @par Throws |
| 234 | //! @li If \c boost::has_nothrow_move<Value>::value is \c true and Value's move constructor throws. |
| 235 | //! @li If \c boost::has_nothrow_move<Value>::value is \c false and Value's copy constructor throws. |
| 236 | //! |
| 237 | //! @par Complexity |
| 238 | //! Linear O(N). |
| 239 | template <std::size_t C> |
| 240 | varray(BOOST_RV_REF_2_TEMPL_ARGS(varray, value_type, C) other) |
| 241 | : base_t(boost::move(static_cast<dtl::varray<value_type, C>&>(other))) |
| 242 | {} |
| 243 | |
| 244 | //! @brief Move assignment. Moves Values stored in the other varray to this one. |
| 245 | //! |
| 246 | //! @param other The varray which content will be moved to this one. |
| 247 | //! |
| 248 | //! @par Throws |
| 249 | //! @li If \c boost::has_nothrow_move<Value>::value is \c true and Value's move constructor or move assignment throws. |
| 250 | //! @li If \c boost::has_nothrow_move<Value>::value is \c false and Value's copy constructor or copy assignment throws. |
| 251 | //! |
| 252 | //! @par Complexity |
| 253 | //! Linear O(N). |
| 254 | varray & operator=(BOOST_RV_REF(varray) other) |
| 255 | { |
| 256 | base_t::operator=(boost::move(static_cast<base_t&>(other))); |
| 257 | return *this; |
| 258 | } |
| 259 | |
| 260 | //! @pre <tt>other.size() <= capacity()</tt> |
| 261 | //! |
| 262 | //! @brief Move assignment. Moves Values stored in the other varray to this one. |
| 263 | //! |
| 264 | //! @param other The varray which content will be moved to this one. |
| 265 | //! |
| 266 | //! @par Throws |
| 267 | //! @li If \c boost::has_nothrow_move<Value>::value is \c true and Value's move constructor or move assignment throws. |
| 268 | //! @li If \c boost::has_nothrow_move<Value>::value is \c false and Value's copy constructor or copy assignment throws. |
| 269 | //! |
| 270 | //! @par Complexity |
| 271 | //! Linear O(N). |
| 272 | template <std::size_t C> |
| 273 | varray & operator=(BOOST_RV_REF_2_TEMPL_ARGS(varray, value_type, C) other) |
| 274 | { |
| 275 | base_t::operator=(boost::move(static_cast<dtl::varray<value_type, C>&>(other))); |
| 276 | return *this; |
| 277 | } |
| 278 | |
| 279 | #ifdef BOOST_CONTAINER_DOXYGEN_INVOKED |
| 280 | |
| 281 | //! @brief Destructor. Destroys Values stored in this container. |
| 282 | //! |
| 283 | //! @par Throws |
| 284 | //! Nothing |
| 285 | //! |
| 286 | //! @par Complexity |
| 287 | //! Linear O(N). |
| 288 | ~varray(); |
| 289 | |
| 290 | //! @brief Swaps contents of the other varray and this one. |
| 291 | //! |
| 292 | //! @param other The varray which content will be swapped with this one's content. |
| 293 | //! |
| 294 | //! @par Throws |
| 295 | //! @li If \c boost::has_nothrow_move<Value>::value is \c true and Value's move constructor or move assignment throws, |
| 296 | //! @li If \c boost::has_nothrow_move<Value>::value is \c false and Value's copy constructor or copy assignment throws, |
| 297 | //! |
| 298 | //! @par Complexity |
| 299 | //! Linear O(N). |
| 300 | void swap(varray & other); |
| 301 | |
| 302 | //! @pre <tt>other.size() <= capacity() && size() <= other.capacity()</tt> |
| 303 | //! |
| 304 | //! @brief Swaps contents of the other varray and this one. |
| 305 | //! |
| 306 | //! @param other The varray which content will be swapped with this one's content. |
| 307 | //! |
| 308 | //! @par Throws |
| 309 | //! @li If \c boost::has_nothrow_move<Value>::value is \c true and Value's move constructor or move assignment throws, |
| 310 | //! @li If \c boost::has_nothrow_move<Value>::value is \c false and Value's copy constructor or copy assignment throws, |
| 311 | //! |
| 312 | //! @par Complexity |
| 313 | //! Linear O(N). |
| 314 | template <std::size_t C> |
| 315 | void swap(varray<value_type, C> & other); |
| 316 | |
| 317 | //! @pre <tt>count <= capacity()</tt> |
| 318 | //! |
| 319 | //! @brief Inserts or erases elements at the end such that |
| 320 | //! the size becomes count. New elements are value initialized. |
| 321 | //! |
| 322 | //! @param count The number of elements which will be stored in the container. |
| 323 | //! |
| 324 | //! @par Throws |
| 325 | //! If Value's value initialization throws. |
| 326 | //! |
| 327 | //! @par Complexity |
| 328 | //! Linear O(N). |
| 329 | void resize(size_type count); |
| 330 | |
| 331 | //! @pre <tt>count <= capacity()</tt> |
| 332 | //! |
| 333 | //! @brief Inserts or erases elements at the end such that |
| 334 | //! the size becomes count. New elements are copy constructed from value. |
| 335 | //! |
| 336 | //! @param count The number of elements which will be stored in the container. |
| 337 | //! @param value The value used to copy construct the new element. |
| 338 | //! |
| 339 | //! @par Throws |
| 340 | //! If Value's copy constructor throws. |
| 341 | //! |
| 342 | //! @par Complexity |
| 343 | //! Linear O(N). |
| 344 | void resize(size_type count, value_type const& value); |
| 345 | |
| 346 | //! @pre <tt>count <= capacity()</tt> |
| 347 | //! |
| 348 | //! @brief This call has no effect because the Capacity of this container is constant. |
| 349 | //! |
| 350 | //! @param count The number of elements which the container should be able to contain. |
| 351 | //! |
| 352 | //! @par Throws |
| 353 | //! Nothing. |
| 354 | //! |
| 355 | //! @par Complexity |
| 356 | //! Linear O(N). |
| 357 | void reserve(size_type count); |
| 358 | |
| 359 | //! @pre <tt>size() < capacity()</tt> |
| 360 | //! |
| 361 | //! @brief Adds a copy of value at the end. |
| 362 | //! |
| 363 | //! @param value The value used to copy construct the new element. |
| 364 | //! |
| 365 | //! @par Throws |
| 366 | //! If Value's copy constructor throws. |
| 367 | //! |
| 368 | //! @par Complexity |
| 369 | //! Constant O(1). |
| 370 | void push_back(value_type const& value); |
| 371 | |
| 372 | //! @pre <tt>size() < capacity()</tt> |
| 373 | //! |
| 374 | //! @brief Moves value to the end. |
| 375 | //! |
| 376 | //! @param value The value to move construct the new element. |
| 377 | //! |
| 378 | //! @par Throws |
| 379 | //! If Value's move constructor throws. |
| 380 | //! |
| 381 | //! @par Complexity |
| 382 | //! Constant O(1). |
| 383 | void push_back(BOOST_RV_REF(value_type) value); |
| 384 | |
| 385 | //! @pre <tt>!empty()</tt> |
| 386 | //! |
| 387 | //! @brief Destroys last value and decreases the size. |
| 388 | //! |
| 389 | //! @par Throws |
| 390 | //! Nothing by default. |
| 391 | //! |
| 392 | //! @par Complexity |
| 393 | //! Constant O(1). |
| 394 | void pop_back(); |
| 395 | |
| 396 | //! @pre |
| 397 | //! @li \c position must be a valid iterator of \c *this in range <tt>[begin(), end()]</tt>. |
| 398 | //! @li <tt>size() < capacity()</tt> |
| 399 | //! |
| 400 | //! @brief Inserts a copy of element at position. |
| 401 | //! |
| 402 | //! @param position The position at which the new value will be inserted. |
| 403 | //! @param value The value used to copy construct the new element. |
| 404 | //! |
| 405 | //! @par Throws |
| 406 | //! @li If Value's copy constructor or copy assignment throws |
| 407 | //! @li If Value's move constructor or move assignment throws. |
| 408 | //! |
| 409 | //! @par Complexity |
| 410 | //! Constant or linear. |
| 411 | iterator insert(iterator position, value_type const& value); |
| 412 | |
| 413 | //! @pre |
| 414 | //! @li \c position must be a valid iterator of \c *this in range <tt>[begin(), end()]</tt>. |
| 415 | //! @li <tt>size() < capacity()</tt> |
| 416 | //! |
| 417 | //! @brief Inserts a move-constructed element at position. |
| 418 | //! |
| 419 | //! @param position The position at which the new value will be inserted. |
| 420 | //! @param value The value used to move construct the new element. |
| 421 | //! |
| 422 | //! @par Throws |
| 423 | //! If Value's move constructor or move assignment throws. |
| 424 | //! |
| 425 | //! @par Complexity |
| 426 | //! Constant or linear. |
| 427 | iterator insert(iterator position, BOOST_RV_REF(value_type) value); |
| 428 | |
| 429 | //! @pre |
| 430 | //! @li \c position must be a valid iterator of \c *this in range <tt>[begin(), end()]</tt>. |
| 431 | //! @li <tt>size() + count <= capacity()</tt> |
| 432 | //! |
| 433 | //! @brief Inserts a count copies of value at position. |
| 434 | //! |
| 435 | //! @param position The position at which new elements will be inserted. |
| 436 | //! @param count The number of new elements which will be inserted. |
| 437 | //! @param value The value used to copy construct new elements. |
| 438 | //! |
| 439 | //! @par Throws |
| 440 | //! @li If Value's copy constructor or copy assignment throws. |
| 441 | //! @li If Value's move constructor or move assignment throws. |
| 442 | //! |
| 443 | //! @par Complexity |
| 444 | //! Linear O(N). |
| 445 | iterator insert(iterator position, size_type count, value_type const& value); |
| 446 | |
| 447 | //! @pre |
| 448 | //! @li \c position must be a valid iterator of \c *this in range <tt>[begin(), end()]</tt>. |
| 449 | //! @li <tt>distance(first, last) <= capacity()</tt> |
| 450 | //! @li \c Iterator must meet the \c ForwardTraversalIterator concept. |
| 451 | //! |
| 452 | //! @brief Inserts a copy of a range <tt>[first, last)</tt> at position. |
| 453 | //! |
| 454 | //! @param position The position at which new elements will be inserted. |
| 455 | //! @param first The iterator to the first element of a range used to construct new elements. |
| 456 | //! @param last The iterator to the one after the last element of a range used to construct new elements. |
| 457 | //! |
| 458 | //! @par Throws |
| 459 | //! @li If Value's constructor and assignment taking a dereferenced \c Iterator. |
| 460 | //! @li If Value's move constructor or move assignment throws. |
| 461 | //! |
| 462 | //! @par Complexity |
| 463 | //! Linear O(N). |
| 464 | template <typename Iterator> |
| 465 | iterator insert(iterator position, Iterator first, Iterator last); |
| 466 | |
| 467 | //! @pre \c position must be a valid iterator of \c *this in range <tt>[begin(), end())</tt> |
| 468 | //! |
| 469 | //! @brief Erases Value from position. |
| 470 | //! |
| 471 | //! @param position The position of the element which will be erased from the container. |
| 472 | //! |
| 473 | //! @par Throws |
| 474 | //! If Value's move assignment throws. |
| 475 | //! |
| 476 | //! @par Complexity |
| 477 | //! Linear O(N). |
| 478 | iterator erase(iterator position); |
| 479 | |
| 480 | //! @pre |
| 481 | //! @li \c first and \c last must define a valid range |
| 482 | //! @li iterators must be in range <tt>[begin(), end()]</tt> |
| 483 | //! |
| 484 | //! @brief Erases Values from a range <tt>[first, last)</tt>. |
| 485 | //! |
| 486 | //! @param first The position of the first element of a range which will be erased from the container. |
| 487 | //! @param last The position of the one after the last element of a range which will be erased from the container. |
| 488 | //! |
| 489 | //! @par Throws |
| 490 | //! If Value's move assignment throws. |
| 491 | //! |
| 492 | //! @par Complexity |
| 493 | //! Linear O(N). |
| 494 | iterator erase(iterator first, iterator last); |
| 495 | |
| 496 | //! @pre <tt>distance(first, last) <= capacity()</tt> |
| 497 | //! |
| 498 | //! @brief Assigns a range <tt>[first, last)</tt> of Values to this container. |
| 499 | //! |
| 500 | //! @param first The iterator to the first element of a range used to construct new content of this container. |
| 501 | //! @param last The iterator to the one after the last element of a range used to construct new content of this container. |
| 502 | //! |
| 503 | //! @par Throws |
| 504 | //! If Value's copy constructor or copy assignment throws, |
| 505 | //! |
| 506 | //! @par Complexity |
| 507 | //! Linear O(N). |
| 508 | template <typename Iterator> |
| 509 | void assign(Iterator first, Iterator last); |
| 510 | |
| 511 | //! @pre <tt>count <= capacity()</tt> |
| 512 | //! |
| 513 | //! @brief Assigns a count copies of value to this container. |
| 514 | //! |
| 515 | //! @param count The new number of elements which will be container in the container. |
| 516 | //! @param value The value which will be used to copy construct the new content. |
| 517 | //! |
| 518 | //! @par Throws |
| 519 | //! If Value's copy constructor or copy assignment throws. |
| 520 | //! |
| 521 | //! @par Complexity |
| 522 | //! Linear O(N). |
| 523 | void assign(size_type count, value_type const& value); |
| 524 | |
| 525 | //! @pre <tt>size() < capacity()</tt> |
| 526 | //! |
| 527 | //! @brief Inserts a Value constructed with |
| 528 | //! \c std::forward<Args>(args)... in the end of the container. |
| 529 | //! |
| 530 | //! @param args The arguments of the constructor of the new element which will be created at the end of the container. |
| 531 | //! |
| 532 | //! @par Throws |
| 533 | //! If in-place constructor throws or Value's move constructor throws. |
| 534 | //! |
| 535 | //! @par Complexity |
| 536 | //! Constant O(1). |
| 537 | template<class ...Args> |
| 538 | void emplace_back(Args &&...args); |
| 539 | |
| 540 | //! @pre |
| 541 | //! @li \c position must be a valid iterator of \c *this in range <tt>[begin(), end()]</tt> |
| 542 | //! @li <tt>size() < capacity()</tt> |
| 543 | //! |
| 544 | //! @brief Inserts a Value constructed with |
| 545 | //! \c std::forward<Args>(args)... before position |
| 546 | //! |
| 547 | //! @param position The position at which new elements will be inserted. |
| 548 | //! @param args The arguments of the constructor of the new element. |
| 549 | //! |
| 550 | //! @par Throws |
| 551 | //! If in-place constructor throws or if Value's move constructor or move assignment throws. |
| 552 | //! |
| 553 | //! @par Complexity |
| 554 | //! Constant or linear. |
| 555 | template<class ...Args> |
| 556 | iterator emplace(iterator position, Args &&...args); |
| 557 | |
| 558 | //! @brief Removes all elements from the container. |
| 559 | //! |
| 560 | //! @par Throws |
| 561 | //! Nothing. |
| 562 | //! |
| 563 | //! @par Complexity |
| 564 | //! Constant O(1). |
| 565 | void clear(); |
| 566 | |
| 567 | //! @pre <tt>i < size()</tt> |
| 568 | //! |
| 569 | //! @brief Returns reference to the i-th element. |
| 570 | //! |
| 571 | //! @param i The element's index. |
| 572 | //! |
| 573 | //! @return reference to the i-th element |
| 574 | //! from the beginning of the container. |
| 575 | //! |
| 576 | //! @par Throws |
| 577 | //! \c std::out_of_range exception by default. |
| 578 | //! |
| 579 | //! @par Complexity |
| 580 | //! Constant O(1). |
| 581 | reference at(size_type i); |
| 582 | |
| 583 | //! @pre <tt>i < size()</tt> |
| 584 | //! |
| 585 | //! @brief Returns const reference to the i-th element. |
| 586 | //! |
| 587 | //! @param i The element's index. |
| 588 | //! |
| 589 | //! @return const reference to the i-th element |
| 590 | //! from the beginning of the container. |
| 591 | //! |
| 592 | //! @par Throws |
| 593 | //! \c std::out_of_range exception by default. |
| 594 | //! |
| 595 | //! @par Complexity |
| 596 | //! Constant O(1). |
| 597 | const_reference at(size_type i) const; |
| 598 | |
| 599 | //! @pre <tt>i < size()</tt> |
| 600 | //! |
| 601 | //! @brief Returns reference to the i-th element. |
| 602 | //! |
| 603 | //! @param i The element's index. |
| 604 | //! |
| 605 | //! @return reference to the i-th element |
| 606 | //! from the beginning of the container. |
| 607 | //! |
| 608 | //! @par Throws |
| 609 | //! Nothing by default. |
| 610 | //! |
| 611 | //! @par Complexity |
| 612 | //! Constant O(1). |
| 613 | reference operator[](size_type i); |
| 614 | |
| 615 | //! @pre <tt>i < size()</tt> |
| 616 | //! |
| 617 | //! @brief Returns const reference to the i-th element. |
| 618 | //! |
| 619 | //! @param i The element's index. |
| 620 | //! |
| 621 | //! @return const reference to the i-th element |
| 622 | //! from the beginning of the container. |
| 623 | //! |
| 624 | //! @par Throws |
| 625 | //! Nothing by default. |
| 626 | //! |
| 627 | //! @par Complexity |
| 628 | //! Constant O(1). |
| 629 | const_reference operator[](size_type i) const; |
| 630 | |
| 631 | //! @pre \c !empty() |
| 632 | //! |
| 633 | //! @brief Returns reference to the first element. |
| 634 | //! |
| 635 | //! @return reference to the first element |
| 636 | //! from the beginning of the container. |
| 637 | //! |
| 638 | //! @par Throws |
| 639 | //! Nothing by default. |
| 640 | //! |
| 641 | //! @par Complexity |
| 642 | //! Constant O(1). |
| 643 | reference front(); |
| 644 | |
| 645 | //! @pre \c !empty() |
| 646 | //! |
| 647 | //! @brief Returns const reference to the first element. |
| 648 | //! |
| 649 | //! @return const reference to the first element |
| 650 | //! from the beginning of the container. |
| 651 | //! |
| 652 | //! @par Throws |
| 653 | //! Nothing by default. |
| 654 | //! |
| 655 | //! @par Complexity |
| 656 | //! Constant O(1). |
| 657 | const_reference front() const; |
| 658 | |
| 659 | //! @pre \c !empty() |
| 660 | //! |
| 661 | //! @brief Returns reference to the last element. |
| 662 | //! |
| 663 | //! @return reference to the last element |
| 664 | //! from the beginning of the container. |
| 665 | //! |
| 666 | //! @par Throws |
| 667 | //! Nothing by default. |
| 668 | //! |
| 669 | //! @par Complexity |
| 670 | //! Constant O(1). |
| 671 | reference back(); |
| 672 | |
| 673 | //! @pre \c !empty() |
| 674 | //! |
| 675 | //! @brief Returns const reference to the first element. |
| 676 | //! |
| 677 | //! @return const reference to the last element |
| 678 | //! from the beginning of the container. |
| 679 | //! |
| 680 | //! @par Throws |
| 681 | //! Nothing by default. |
| 682 | //! |
| 683 | //! @par Complexity |
| 684 | //! Constant O(1). |
| 685 | const_reference back() const; |
| 686 | |
| 687 | //! @brief Pointer such that <tt>[data(), data() + size())</tt> is a valid range. |
| 688 | //! For a non-empty vector <tt>data() == &front()</tt>. |
| 689 | //! |
| 690 | //! @par Throws |
| 691 | //! Nothing. |
| 692 | //! |
| 693 | //! @par Complexity |
| 694 | //! Constant O(1). |
| 695 | Value * data(); |
| 696 | |
| 697 | //! @brief Const pointer such that <tt>[data(), data() + size())</tt> is a valid range. |
| 698 | //! For a non-empty vector <tt>data() == &front()</tt>. |
| 699 | //! |
| 700 | //! @par Throws |
| 701 | //! Nothing. |
| 702 | //! |
| 703 | //! @par Complexity |
| 704 | //! Constant O(1). |
| 705 | const Value * data() const; |
| 706 | |
| 707 | //! @brief Returns iterator to the first element. |
| 708 | //! |
| 709 | //! @return iterator to the first element contained in the vector. |
| 710 | //! |
| 711 | //! @par Throws |
| 712 | //! Nothing. |
| 713 | //! |
| 714 | //! @par Complexity |
| 715 | //! Constant O(1). |
| 716 | iterator begin(); |
| 717 | |
| 718 | //! @brief Returns const iterator to the first element. |
| 719 | //! |
| 720 | //! @return const_iterator to the first element contained in the vector. |
| 721 | //! |
| 722 | //! @par Throws |
| 723 | //! Nothing. |
| 724 | //! |
| 725 | //! @par Complexity |
| 726 | //! Constant O(1). |
| 727 | const_iterator begin() const; |
| 728 | |
| 729 | //! @brief Returns const iterator to the first element. |
| 730 | //! |
| 731 | //! @return const_iterator to the first element contained in the vector. |
| 732 | //! |
| 733 | //! @par Throws |
| 734 | //! Nothing. |
| 735 | //! |
| 736 | //! @par Complexity |
| 737 | //! Constant O(1). |
| 738 | const_iterator cbegin() const; |
| 739 | |
| 740 | //! @brief Returns iterator to the one after the last element. |
| 741 | //! |
| 742 | //! @return iterator pointing to the one after the last element contained in the vector. |
| 743 | //! |
| 744 | //! @par Throws |
| 745 | //! Nothing. |
| 746 | //! |
| 747 | //! @par Complexity |
| 748 | //! Constant O(1). |
| 749 | iterator end(); |
| 750 | |
| 751 | //! @brief Returns const iterator to the one after the last element. |
| 752 | //! |
| 753 | //! @return const_iterator pointing to the one after the last element contained in the vector. |
| 754 | //! |
| 755 | //! @par Throws |
| 756 | //! Nothing. |
| 757 | //! |
| 758 | //! @par Complexity |
| 759 | //! Constant O(1). |
| 760 | const_iterator end() const; |
| 761 | |
| 762 | //! @brief Returns const iterator to the one after the last element. |
| 763 | //! |
| 764 | //! @return const_iterator pointing to the one after the last element contained in the vector. |
| 765 | //! |
| 766 | //! @par Throws |
| 767 | //! Nothing. |
| 768 | //! |
| 769 | //! @par Complexity |
| 770 | //! Constant O(1). |
| 771 | const_iterator cend() const; |
| 772 | |
| 773 | //! @brief Returns reverse iterator to the first element of the reversed container. |
| 774 | //! |
| 775 | //! @return reverse_iterator pointing to the beginning |
| 776 | //! of the reversed varray. |
| 777 | //! |
| 778 | //! @par Throws |
| 779 | //! Nothing. |
| 780 | //! |
| 781 | //! @par Complexity |
| 782 | //! Constant O(1). |
| 783 | reverse_iterator rbegin(); |
| 784 | |
| 785 | //! @brief Returns const reverse iterator to the first element of the reversed container. |
| 786 | //! |
| 787 | //! @return const_reverse_iterator pointing to the beginning |
| 788 | //! of the reversed varray. |
| 789 | //! |
| 790 | //! @par Throws |
| 791 | //! Nothing. |
| 792 | //! |
| 793 | //! @par Complexity |
| 794 | //! Constant O(1). |
| 795 | const_reverse_iterator rbegin() const; |
| 796 | |
| 797 | //! @brief Returns const reverse iterator to the first element of the reversed container. |
| 798 | //! |
| 799 | //! @return const_reverse_iterator pointing to the beginning |
| 800 | //! of the reversed varray. |
| 801 | //! |
| 802 | //! @par Throws |
| 803 | //! Nothing. |
| 804 | //! |
| 805 | //! @par Complexity |
| 806 | //! Constant O(1). |
| 807 | const_reverse_iterator crbegin() const; |
| 808 | |
| 809 | //! @brief Returns reverse iterator to the one after the last element of the reversed container. |
| 810 | //! |
| 811 | //! @return reverse_iterator pointing to the one after the last element |
| 812 | //! of the reversed varray. |
| 813 | //! |
| 814 | //! @par Throws |
| 815 | //! Nothing. |
| 816 | //! |
| 817 | //! @par Complexity |
| 818 | //! Constant O(1). |
| 819 | reverse_iterator rend(); |
| 820 | |
| 821 | //! @brief Returns const reverse iterator to the one after the last element of the reversed container. |
| 822 | //! |
| 823 | //! @return const_reverse_iterator pointing to the one after the last element |
| 824 | //! of the reversed varray. |
| 825 | //! |
| 826 | //! @par Throws |
| 827 | //! Nothing. |
| 828 | //! |
| 829 | //! @par Complexity |
| 830 | //! Constant O(1). |
| 831 | const_reverse_iterator rend() const; |
| 832 | |
| 833 | //! @brief Returns const reverse iterator to the one after the last element of the reversed container. |
| 834 | //! |
| 835 | //! @return const_reverse_iterator pointing to the one after the last element |
| 836 | //! of the reversed varray. |
| 837 | //! |
| 838 | //! @par Throws |
| 839 | //! Nothing. |
| 840 | //! |
| 841 | //! @par Complexity |
| 842 | //! Constant O(1). |
| 843 | const_reverse_iterator crend() const; |
| 844 | |
| 845 | //! @brief Returns container's capacity. |
| 846 | //! |
| 847 | //! @return container's capacity. |
| 848 | //! |
| 849 | //! @par Throws |
| 850 | //! Nothing. |
| 851 | //! |
| 852 | //! @par Complexity |
| 853 | //! Constant O(1). |
| 854 | static size_type capacity(); |
| 855 | |
| 856 | //! @brief Returns container's capacity. |
| 857 | //! |
| 858 | //! @return container's capacity. |
| 859 | //! |
| 860 | //! @par Throws |
| 861 | //! Nothing. |
| 862 | //! |
| 863 | //! @par Complexity |
| 864 | //! Constant O(1). |
| 865 | static size_type max_size(); |
| 866 | |
| 867 | //! @brief Returns the number of stored elements. |
| 868 | //! |
| 869 | //! @return Number of elements contained in the container. |
| 870 | //! |
| 871 | //! @par Throws |
| 872 | //! Nothing. |
| 873 | //! |
| 874 | //! @par Complexity |
| 875 | //! Constant O(1). |
| 876 | size_type size() const; |
| 877 | |
| 878 | //! @brief Queries if the container contains elements. |
| 879 | //! |
| 880 | //! @return true if the number of elements contained in the |
| 881 | //! container is equal to 0. |
| 882 | //! |
| 883 | //! @par Throws |
| 884 | //! Nothing. |
| 885 | //! |
| 886 | //! @par Complexity |
| 887 | //! Constant O(1). |
| 888 | bool empty() const; |
| 889 | |
| 890 | #endif // BOOST_CONTAINER_DOXYGEN_INVOKED |
| 891 | |
| 892 | }; |
| 893 | |
| 894 | #ifdef BOOST_CONTAINER_DOXYGEN_INVOKED |
| 895 | |
| 896 | //! @brief Checks if contents of two varrays are equal. |
| 897 | //! |
| 898 | //! @ingroup varray_non_member |
| 899 | //! |
| 900 | //! @param x The first varray. |
| 901 | //! @param y The second varray. |
| 902 | //! |
| 903 | //! @return \c true if containers have the same size and elements in both containers are equal. |
| 904 | //! |
| 905 | //! @par Complexity |
| 906 | //! Linear O(N). |
| 907 | template<typename V, std::size_t C1, std::size_t C2> |
| 908 | bool operator== (varray<V, C1> const& x, varray<V, C2> const& y); |
| 909 | |
| 910 | //! @brief Checks if contents of two varrays are not equal. |
| 911 | //! |
| 912 | //! @ingroup varray_non_member |
| 913 | //! |
| 914 | //! @param x The first varray. |
| 915 | //! @param y The second varray. |
| 916 | //! |
| 917 | //! @return \c true if containers have different size or elements in both containers are not equal. |
| 918 | //! |
| 919 | //! @par Complexity |
| 920 | //! Linear O(N). |
| 921 | template<typename V, std::size_t C1, std::size_t C2> |
| 922 | bool operator!= (varray<V, C1> const& x, varray<V, C2> const& y); |
| 923 | |
| 924 | //! @brief Lexicographically compares varrays. |
| 925 | //! |
| 926 | //! @ingroup varray_non_member |
| 927 | //! |
| 928 | //! @param x The first varray. |
| 929 | //! @param y The second varray. |
| 930 | //! |
| 931 | //! @return \c true if x compares lexicographically less than y. |
| 932 | //! |
| 933 | //! @par Complexity |
| 934 | //! Linear O(N). |
| 935 | template<typename V, std::size_t C1, std::size_t C2> |
| 936 | bool operator< (varray<V, C1> const& x, varray<V, C2> const& y); |
| 937 | |
| 938 | //! @brief Lexicographically compares varrays. |
| 939 | //! |
| 940 | //! @ingroup varray_non_member |
| 941 | //! |
| 942 | //! @param x The first varray. |
| 943 | //! @param y The second varray. |
| 944 | //! |
| 945 | //! @return \c true if y compares lexicographically less than x. |
| 946 | //! |
| 947 | //! @par Complexity |
| 948 | //! Linear O(N). |
| 949 | template<typename V, std::size_t C1, std::size_t C2> |
| 950 | bool operator> (varray<V, C1> const& x, varray<V, C2> const& y); |
| 951 | |
| 952 | //! @brief Lexicographically compares varrays. |
| 953 | //! |
| 954 | //! @ingroup varray_non_member |
| 955 | //! |
| 956 | //! @param x The first varray. |
| 957 | //! @param y The second varray. |
| 958 | //! |
| 959 | //! @return \c true if y don't compare lexicographically less than x. |
| 960 | //! |
| 961 | //! @par Complexity |
| 962 | //! Linear O(N). |
| 963 | template<typename V, std::size_t C1, std::size_t C2> |
| 964 | bool operator<= (varray<V, C1> const& x, varray<V, C2> const& y); |
| 965 | |
| 966 | //! @brief Lexicographically compares varrays. |
| 967 | //! |
| 968 | //! @ingroup varray_non_member |
| 969 | //! |
| 970 | //! @param x The first varray. |
| 971 | //! @param y The second varray. |
| 972 | //! |
| 973 | //! @return \c true if x don't compare lexicographically less than y. |
| 974 | //! |
| 975 | //! @par Complexity |
| 976 | //! Linear O(N). |
| 977 | template<typename V, std::size_t C1, std::size_t C2> |
| 978 | bool operator>= (varray<V, C1> const& x, varray<V, C2> const& y); |
| 979 | |
| 980 | //! @brief Swaps contents of two varrays. |
| 981 | //! |
| 982 | //! This function calls varray::swap(). |
| 983 | //! |
| 984 | //! @ingroup varray_non_member |
| 985 | //! |
| 986 | //! @param x The first varray. |
| 987 | //! @param y The second varray. |
| 988 | //! |
| 989 | //! @par Complexity |
| 990 | //! Linear O(N). |
| 991 | template<typename V, std::size_t C1, std::size_t C2> |
| 992 | inline void swap(varray<V, C1> & x, varray<V, C2> & y); |
| 993 | |
| 994 | #endif // BOOST_CONTAINER_DOXYGEN_INVOKED |
| 995 | |
| 996 | }} // namespace boost::container |
| 997 | |
| 998 | #include <boost/container/detail/config_end.hpp> |
| 999 | |
| 1000 | #endif // BOOST_CONTAINER_VARRAY_HPP |