varray.hpp 31 KB

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