static_vector.hpp 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326
  1. // Boost.Container static_vector
  2. //
  3. // Copyright (c) 2012-2013 Adam Wulkiewicz, Lodz, Poland.
  4. // Copyright (c) 2011-2013 Andrew Hundt.
  5. // Copyright (c) 2013-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_STATIC_VECTOR_HPP
  11. #define BOOST_CONTAINER_STATIC_VECTOR_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 <boost/container/detail/workaround.hpp>
  20. #include <boost/container/detail/type_traits.hpp>
  21. #include <boost/container/vector.hpp>
  22. #include <cstddef>
  23. #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
  24. #include <initializer_list>
  25. #endif
  26. namespace boost { namespace container {
  27. #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
  28. namespace dtl {
  29. template<class T, std::size_t N, std::size_t InplaceAlignment, bool ThrowOnOverflow>
  30. class static_storage_allocator
  31. {
  32. typedef bool_<ThrowOnOverflow> throw_on_overflow_t;
  33. static BOOST_NORETURN inline void on_capacity_overflow(true_type)
  34. {
  35. (throw_bad_alloc)();
  36. }
  37. static inline void on_capacity_overflow(false_type)
  38. {
  39. BOOST_ASSERT_MSG(false, "ERROR: static vector capacity overflow");
  40. }
  41. public:
  42. typedef T value_type;
  43. inline static_storage_allocator() BOOST_NOEXCEPT_OR_NOTHROW
  44. {}
  45. inline static_storage_allocator(const static_storage_allocator &) BOOST_NOEXCEPT_OR_NOTHROW
  46. {}
  47. inline static_storage_allocator & operator=(const static_storage_allocator &) BOOST_NOEXCEPT_OR_NOTHROW
  48. { return *this; }
  49. inline T* internal_storage() const BOOST_NOEXCEPT_OR_NOTHROW
  50. { return const_cast<T*>(static_cast<const T*>(static_cast<const void*>(storage.data))); }
  51. inline T* internal_storage() BOOST_NOEXCEPT_OR_NOTHROW
  52. { return static_cast<T*>(static_cast<void*>(storage.data)); }
  53. static const std::size_t internal_capacity = N;
  54. std::size_t max_size() const
  55. { return N; }
  56. static inline void on_capacity_overflow()
  57. {
  58. (on_capacity_overflow)(throw_on_overflow_t());
  59. }
  60. typedef boost::container::dtl::version_type<static_storage_allocator, 0> version;
  61. inline friend bool operator==(const static_storage_allocator &, const static_storage_allocator &) BOOST_NOEXCEPT_OR_NOTHROW
  62. { return false; }
  63. inline friend bool operator!=(const static_storage_allocator &, const static_storage_allocator &) BOOST_NOEXCEPT_OR_NOTHROW
  64. { return true; }
  65. private:
  66. BOOST_CONTAINER_STATIC_ASSERT_MSG(!InplaceAlignment || (InplaceAlignment & (InplaceAlignment-1)) == 0, "Alignment option must be zero or power of two");
  67. static const std::size_t final_alignment = InplaceAlignment ? InplaceAlignment : dtl::alignment_of<T>::value;
  68. typename dtl::aligned_storage<sizeof(T)*N, final_alignment>::type storage;
  69. };
  70. template<class Options>
  71. struct get_static_vector_opt
  72. {
  73. typedef Options type;
  74. };
  75. template<>
  76. struct get_static_vector_opt<void>
  77. {
  78. typedef static_vector_null_opt type;
  79. };
  80. template <typename T, std::size_t Capacity, class Options>
  81. struct get_static_vector_allocator
  82. {
  83. typedef typename get_static_vector_opt<Options>::type options_t;
  84. typedef dtl::static_storage_allocator
  85. < T
  86. , Capacity
  87. , options_t::inplace_alignment
  88. , options_t::throw_on_overflow
  89. > type;
  90. };
  91. } //namespace dtl {
  92. #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
  93. //!
  94. //!@brief A variable-size array container with fixed capacity.
  95. //!
  96. //!static_vector is a sequence container like boost::container::vector with contiguous storage that can
  97. //!change in size, along with the static allocation, low overhead, and fixed capacity of boost::array.
  98. //!
  99. //!A static_vector is a sequence that supports random access to elements, constant time insertion and
  100. //!removal of elements at the end, and linear time insertion and removal of elements at the beginning or
  101. //!in the middle. The number of elements in a static_vector may vary dynamically up to a fixed capacity
  102. //!because elements are stored within the object itself similarly to an array. However, objects are
  103. //!initialized as they are inserted into static_vector unlike C arrays or std::array which must construct
  104. //!all elements on instantiation. The behavior of static_vector enables the use of statically allocated
  105. //!elements in cases with complex object lifetime requirements that would otherwise not be trivially
  106. //!possible.
  107. //!
  108. //!@par Error Handling
  109. //! If `throw_on_overflow` option is true (default behaviour), insertion beyond the capacity result
  110. //! in throwing bad_alloc() if exceptions are enabled and or calling throw_bad_alloc() if not enabled.
  111. //! If `throw_on_overflow` option is false, insertion beyond capacity results in Undefined Behaviour.
  112. //!
  113. //! out_of_range is thrown if out of bounds access is performed in <code>at()</code> if exceptions are
  114. //! enabled, throw_out_of_range() if not enabled.
  115. //!
  116. //!@tparam T The type of element that will be stored.
  117. //!@tparam Capacity The maximum number of elements static_vector can store, fixed at compile time.
  118. //!@tparam Options A type produced from \c boost::container::static_vector_options. If no option
  119. //! is specified, by default throw_on_overflow<true> option is set.
  120. template <typename T, std::size_t Capacity, class Options BOOST_CONTAINER_DOCONLY(= void) >
  121. class static_vector
  122. : public vector<T, typename dtl::get_static_vector_allocator< T, Capacity, Options>::type>
  123. {
  124. public:
  125. #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
  126. typedef typename dtl::get_static_vector_allocator< T, Capacity, Options>::type allocator_type;
  127. typedef vector<T, allocator_type > base_t;
  128. BOOST_COPYABLE_AND_MOVABLE(static_vector)
  129. template<class U, std::size_t OtherCapacity, class OtherOptions>
  130. friend class static_vector;
  131. public:
  132. #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
  133. public:
  134. //! @brief The type of elements stored in the container.
  135. typedef typename base_t::value_type value_type;
  136. //! @brief The unsigned integral type used by the container.
  137. typedef typename base_t::size_type size_type;
  138. //! @brief The pointers difference type.
  139. typedef typename base_t::difference_type difference_type;
  140. //! @brief The pointer type.
  141. typedef typename base_t::pointer pointer;
  142. //! @brief The const pointer type.
  143. typedef typename base_t::const_pointer const_pointer;
  144. //! @brief The value reference type.
  145. typedef typename base_t::reference reference;
  146. //! @brief The value const reference type.
  147. typedef typename base_t::const_reference const_reference;
  148. //! @brief The iterator type.
  149. typedef typename base_t::iterator iterator;
  150. //! @brief The const iterator type.
  151. typedef typename base_t::const_iterator const_iterator;
  152. //! @brief The reverse iterator type.
  153. typedef typename base_t::reverse_iterator reverse_iterator;
  154. //! @brief The const reverse iterator.
  155. typedef typename base_t::const_reverse_iterator const_reverse_iterator;
  156. //! @brief The capacity/max size of the container
  157. static const size_type static_capacity = Capacity;
  158. //! @brief Constructs an empty static_vector.
  159. //!
  160. //! @par Throws
  161. //! Nothing.
  162. //!
  163. //! @par Complexity
  164. //! Constant O(1).
  165. inline static_vector() BOOST_NOEXCEPT_OR_NOTHROW
  166. : base_t()
  167. {}
  168. //! @pre <tt>count <= capacity()</tt>
  169. //!
  170. //! @brief Constructs a static_vector containing count value initialized values.
  171. //!
  172. //! @param count The number of values which will be contained in the container.
  173. //!
  174. //! @par Throws
  175. //! @li If T's value initialization throws
  176. //! @li If \c throw_on_overflow<true> option is set and the container runs out of capacity.
  177. //!
  178. //! @par Complexity
  179. //! Linear O(N).
  180. inline explicit static_vector(size_type count)
  181. : base_t(count)
  182. {}
  183. //! @pre <tt>count <= capacity()</tt>
  184. //!
  185. //! @brief Constructs a static_vector containing count default initialized values.
  186. //!
  187. //! @param count The number of values which will be contained in the container.
  188. //!
  189. //! @par Throws
  190. //! @li If T's default initialization throws.
  191. //! @li If \c throw_on_overflow<true> option is set and the container runs out of capacity.
  192. //!
  193. //! @par Complexity
  194. //! Linear O(N).
  195. //!
  196. //! @par Note
  197. //! Non-standard extension
  198. inline static_vector(size_type count, default_init_t)
  199. : base_t(count, default_init_t())
  200. {}
  201. //! @pre <tt>count <= capacity()</tt>
  202. //!
  203. //! @brief Constructs a static_vector containing count copies of value.
  204. //!
  205. //! @param count The number of copies of a values that will be contained in the container.
  206. //! @param value The value which will be used to copy construct values.
  207. //!
  208. //! @par Throws
  209. //! @li If T's copy constructor throws.
  210. //! @li If \c throw_on_overflow<true> option is set and the container runs out of capacity.
  211. //!
  212. //! @par Complexity
  213. //! Linear O(N).
  214. inline static_vector(size_type count, value_type const& value)
  215. : base_t(count, value)
  216. {}
  217. //! @pre
  218. //! @li <tt>distance(first, last) <= capacity()</tt>
  219. //! @li Iterator must meet the \c ForwardTraversalIterator concept.
  220. //!
  221. //! @brief Constructs a static_vector containing copy of a range <tt>[first, last)</tt>.
  222. //!
  223. //! @param first The iterator to the first element in range.
  224. //! @param last The iterator to the one after the last element in range.
  225. //!
  226. //! @par Throws
  227. //! @li If T's constructor taking a dereferenced Iterator throws.
  228. //! @li If \c throw_on_overflow<true> option is set and the container runs out of capacity.
  229. //!
  230. //! @par Complexity
  231. //! Linear O(N).
  232. template <typename Iterator>
  233. inline static_vector(Iterator first, Iterator last)
  234. : base_t(first, last)
  235. {}
  236. #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
  237. //! @pre
  238. //! @li <tt>distance(il.begin(), il.end()) <= capacity()</tt>
  239. //!
  240. //! @brief Constructs a static_vector containing copy of a range <tt>[il.begin(), il.end())</tt>.
  241. //!
  242. //! @param il std::initializer_list with values to initialize vector.
  243. //!
  244. //! @par Throws
  245. //! @li If T's constructor taking a dereferenced std::initializer_list throws.
  246. //! @li If \c throw_on_overflow<true> option is set and the container runs out of capacity.
  247. //!
  248. //! @par Complexity
  249. //! Linear O(N).
  250. inline static_vector(std::initializer_list<value_type> il)
  251. : base_t(il)
  252. {}
  253. #endif
  254. //! @brief Constructs a copy of other static_vector.
  255. //!
  256. //! @param other The static_vector which content will be copied to this one.
  257. //!
  258. //! @par Throws
  259. //! If T's copy constructor throws.
  260. //!
  261. //! @par Complexity
  262. //! Linear O(N).
  263. inline static_vector(static_vector const& other)
  264. : base_t(other)
  265. {}
  266. inline static_vector(static_vector const& other, const allocator_type &)
  267. : base_t(other)
  268. {}
  269. inline static_vector(BOOST_RV_REF(static_vector) other, const allocator_type &)
  270. BOOST_NOEXCEPT_IF(boost::container::dtl::is_nothrow_move_constructible<value_type>::value)
  271. : base_t(BOOST_MOVE_BASE(base_t, other))
  272. {}
  273. inline explicit static_vector(const allocator_type &)
  274. : base_t()
  275. {}
  276. //! @pre <tt>other.size() <= capacity()</tt>.
  277. //!
  278. //! @brief Constructs a copy of other static_vector.
  279. //!
  280. //! @param other The static_vector which content will be copied to this one.
  281. //!
  282. //! @par Throws
  283. //! @li If T's copy constructor throws.
  284. //! @li If \c throw_on_overflow<true> option is set and the container runs out of capacity.
  285. //!
  286. //! @par Complexity
  287. //! Linear O(N).
  288. template <std::size_t C, class O>
  289. inline static_vector(static_vector<T, C, O> const& other)
  290. : base_t(other)
  291. {}
  292. //! @brief Move constructor. Moves Values stored in the other static_vector to this one.
  293. //!
  294. //! @param other The static_vector which content will be moved to this one.
  295. //!
  296. //! @par Throws
  297. //! @li If \c has_nothrow_move<T>::value is \c true and T's move constructor throws.
  298. //! @li If \c has_nothrow_move<T>::value is \c false and T's copy constructor throws.
  299. //!
  300. //! @par Complexity
  301. //! Linear O(N).
  302. inline static_vector(BOOST_RV_REF(static_vector) other)
  303. BOOST_NOEXCEPT_IF(boost::container::dtl::is_nothrow_move_constructible<value_type>::value)
  304. : base_t(BOOST_MOVE_BASE(base_t, other))
  305. {}
  306. //! @pre <tt>other.size() <= capacity()</tt>
  307. //!
  308. //! @brief Move constructor. Moves Values stored in the other static_vector to this one.
  309. //!
  310. //! @param other The static_vector which content will be moved to this one.
  311. //!
  312. //! @par Throws
  313. //! @li If \c has_nothrow_move<T>::value is \c true and T's move constructor throws.
  314. //! @li If \c has_nothrow_move<T>::value is \c false and T's copy constructor throws.
  315. //! @li If \c throw_on_overflow<true> option is set and the container runs out of capacity.
  316. //!
  317. //! @par Complexity
  318. //! Linear O(N).
  319. template <std::size_t C, class O>
  320. inline static_vector(BOOST_RV_REF_BEG static_vector<T, C, O> BOOST_RV_REF_END other)
  321. : base_t(BOOST_MOVE_BASE(typename static_vector<T BOOST_MOVE_I C>::base_t, other))
  322. {}
  323. //! @brief Copy assigns Values stored in the other static_vector to this one.
  324. //!
  325. //! @param other The static_vector which content will be copied to this one.
  326. //!
  327. //! @par Throws
  328. //! If T's copy constructor or copy assignment throws.
  329. //!
  330. //! @par Complexity
  331. //! Linear O(N).
  332. inline static_vector & operator=(BOOST_COPY_ASSIGN_REF(static_vector) other)
  333. {
  334. return static_cast<static_vector&>(base_t::operator=(static_cast<base_t const&>(other)));
  335. }
  336. #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
  337. //! @brief Copy assigns Values stored in std::initializer_list to *this.
  338. //!
  339. //! @param il The std::initializer_list which content will be copied to this one.
  340. //!
  341. //! @par Throws
  342. //! @li If T's copy constructor or copy assignment throws.
  343. //! @li If \c throw_on_overflow<true> option is set and the container runs out of capacity.
  344. //!
  345. //! @par Complexity
  346. //! Linear O(N).
  347. inline static_vector & operator=(std::initializer_list<value_type> il)
  348. { return static_cast<static_vector&>(base_t::operator=(il)); }
  349. #endif
  350. //! @pre <tt>other.size() <= capacity()</tt>
  351. //!
  352. //! @brief Copy assigns Values stored in the other static_vector to this one.
  353. //!
  354. //! @param other The static_vector which content will be copied to this one.
  355. //!
  356. //! @par Throws
  357. //! @li If T's copy constructor or copy assignment throws.
  358. //! @li If \c throw_on_overflow<true> option is set and the container runs out of capacity.
  359. //!
  360. //! @par Complexity
  361. //! Linear O(N).
  362. template <std::size_t C, class O>
  363. inline static_vector & operator=(static_vector<T, C, O> const& other)
  364. {
  365. return static_cast<static_vector&>(base_t::operator=
  366. (static_cast<typename static_vector<T, C, O>::base_t const&>(other)));
  367. }
  368. //! @brief Move assignment. Moves Values stored in the other static_vector to this one.
  369. //!
  370. //! @param other The static_vector which content will be moved to this one.
  371. //!
  372. //! @par Throws
  373. //! @li If \c has_nothrow_move<T>::value is \c true and T's move constructor or move assignment throws.
  374. //! @li If \c has_nothrow_move<T>::value is \c false and T's copy constructor or copy assignment throws.
  375. //!
  376. //! @par Complexity
  377. //! Linear O(N).
  378. inline static_vector & operator=(BOOST_RV_REF(static_vector) other)
  379. BOOST_NOEXCEPT_IF(boost::container::dtl::is_nothrow_move_assignable<value_type>::value)
  380. {
  381. return static_cast<static_vector&>(base_t::operator=(BOOST_MOVE_BASE(base_t, other)));
  382. }
  383. //! @pre <tt>other.size() <= capacity()</tt>
  384. //!
  385. //! @brief Move assignment. Moves Values stored in the other static_vector to this one.
  386. //!
  387. //! @param other The static_vector which content will be moved to this one.
  388. //!
  389. //! @par Throws
  390. //! @li If \c has_nothrow_move<T>::value is \c true and T's move constructor or move assignment throws.
  391. //! @li If \c has_nothrow_move<T>::value is \c false and T's copy constructor or copy assignment throws.
  392. //! @li If \c throw_on_overflow<true> option is set and the container runs out of capacity.
  393. //!
  394. //! @par Complexity
  395. //! Linear O(N).
  396. template <std::size_t C, class O>
  397. inline static_vector & operator=(BOOST_RV_REF_BEG static_vector<T, C, O> BOOST_RV_REF_END other)
  398. {
  399. return static_cast<static_vector&>(base_t::operator=
  400. (BOOST_MOVE_BASE(typename static_vector<T BOOST_MOVE_I C>::base_t, other)));
  401. }
  402. #ifdef BOOST_CONTAINER_DOXYGEN_INVOKED
  403. //! @brief Destructor. Destroys Values stored in this container.
  404. //!
  405. //! @par Throws
  406. //! Nothing
  407. //!
  408. //! @par Complexity
  409. //! Linear O(N).
  410. ~static_vector();
  411. //! @brief Swaps contents of the other static_vector and this one.
  412. //!
  413. //! @param other The static_vector which content will be swapped with this one's content.
  414. //!
  415. //! @par Throws
  416. //! @li If \c has_nothrow_move<T>::value is \c true and T's move constructor or move assignment throws,
  417. //! @li If \c has_nothrow_move<T>::value is \c false and T's copy constructor or copy assignment throws,
  418. //!
  419. //! @par Complexity
  420. //! Linear O(N).
  421. void swap(static_vector & other);
  422. //! @pre <tt>other.size() <= capacity() && size() <= other.capacity()</tt>
  423. //!
  424. //! @brief Swaps contents of the other static_vector and this one.
  425. //!
  426. //! @param other The static_vector which content will be swapped with this one's content.
  427. //!
  428. //! @par Throws
  429. //! @li If \c has_nothrow_move<T>::value is \c true and T's move constructor or move assignment throws,
  430. //! @li If \c has_nothrow_move<T>::value is \c false and T's copy constructor or copy assignment throws,
  431. //! @li If \c throw_on_overflow<true> option is set and the container runs out of capacity.
  432. //!
  433. //! @par Complexity
  434. //! Linear O(N).
  435. template <std::size_t C, class O>
  436. void swap(static_vector<T, C, O> & other);
  437. //! @pre <tt>count <= capacity()</tt>
  438. //!
  439. //! @brief Inserts or erases elements at the end such that
  440. //! the size becomes count. New elements are value initialized.
  441. //!
  442. //! @param count The number of elements which will be stored in the container.
  443. //!
  444. //! @par Throws
  445. //! @li If T's value initialization throws.
  446. //! @li If \c throw_on_overflow<true> option is set and the container runs out of capacity.
  447. //!
  448. //! @par Complexity
  449. //! Linear O(N).
  450. void resize(size_type count);
  451. //! @pre <tt>count <= capacity()</tt>
  452. //!
  453. //! @brief Inserts or erases elements at the end such that
  454. //! the size becomes count. New elements are default initialized.
  455. //!
  456. //! @param count The number of elements which will be stored in the container.
  457. //!
  458. //! @par Throws
  459. //! @li If T's default initialization throws.
  460. //! @li If \c throw_on_overflow<true> option is set and the container runs out of capacity.
  461. //!
  462. //! @par Complexity
  463. //! Linear O(N).
  464. //!
  465. //! @par Note
  466. //! Non-standard extension
  467. void resize(size_type count, default_init_t);
  468. //! @pre <tt>count <= capacity()</tt>
  469. //!
  470. //! @brief Inserts or erases elements at the end such that
  471. //! the size becomes count. New elements are copy constructed from value.
  472. //!
  473. //! @param count The number of elements which will be stored in the container.
  474. //! @param value The value used to copy construct the new element.
  475. //!
  476. //! @par Throws
  477. //! @li If T's copy constructor throws.
  478. //! @li If \c throw_on_overflow<true> option is set and the container runs out of capacity.
  479. //!
  480. //! @par Complexity
  481. //! Linear O(N).
  482. void resize(size_type count, value_type const& value);
  483. //! @pre <tt>count <= capacity()</tt>
  484. //!
  485. //! @brief This call has no effect because the Capacity of this container is constant.
  486. //!
  487. //! @param count The number of elements which the container should be able to contain.
  488. //!
  489. //! @par Throws
  490. //! If \c throw_on_overflow<true> option is set and the container runs out of capacity.
  491. //!
  492. //! @par Complexity
  493. //! Constant O(1).
  494. void reserve(size_type count);
  495. //! @pre <tt>size() < capacity()</tt>
  496. //!
  497. //! @brief Adds a copy of value at the end.
  498. //!
  499. //! @param value The value used to copy construct the new element.
  500. //!
  501. //! @par Throws
  502. //! @li If T's copy constructor throws.
  503. //! @li If \c throw_on_overflow<true> option is set and the container runs out of capacity.
  504. //!
  505. //! @par Complexity
  506. //! Constant O(1).
  507. void push_back(value_type const& value);
  508. //! @pre <tt>size() < capacity()</tt>
  509. //!
  510. //! @brief Moves value to the end.
  511. //!
  512. //! @param value The value to move construct the new element.
  513. //!
  514. //! @par Throws
  515. //! @li If T's move constructor throws.
  516. //! @li If \c throw_on_overflow<true> option is set and the container runs out of capacity.
  517. //!
  518. //! @par Complexity
  519. //! Constant O(1).
  520. void push_back(BOOST_RV_REF(value_type) value);
  521. //! @pre <tt>!empty()</tt>
  522. //!
  523. //! @brief Destroys last value and decreases the size.
  524. //!
  525. //! @par Throws
  526. //! Nothing.
  527. //!
  528. //! @par Complexity
  529. //! Constant O(1).
  530. void pop_back() BOOST_NOEXCEPT_OR_NOTHROW;
  531. //! @pre
  532. //! @li \c p must be a valid iterator of \c *this in range <tt>[begin(), end()]</tt>.
  533. //! @li <tt>size() < capacity()</tt>
  534. //!
  535. //! @brief Inserts a copy of element at p.
  536. //!
  537. //! @param p The position at which the new value will be inserted.
  538. //! @param value The value used to copy construct the new element.
  539. //!
  540. //! @par Throws
  541. //! @li If T's copy constructor or copy assignment throws
  542. //! @li If T's move constructor or move assignment throws.
  543. //! @li If \c throw_on_overflow<true> option is set and the container runs out of capacity.
  544. //!
  545. //! @par Complexity
  546. //! Constant or linear.
  547. iterator insert(const_iterator p, value_type const& value);
  548. //! @pre
  549. //! @li \c p must be a valid iterator of \c *this in range <tt>[begin(), end()]</tt>.
  550. //! @li <tt>size() < capacity()</tt>
  551. //!
  552. //! @brief Inserts a move-constructed element at p.
  553. //!
  554. //! @param p The position at which the new value will be inserted.
  555. //! @param value The value used to move construct the new element.
  556. //!
  557. //! @par Throws
  558. //! @li If T's move constructor or move assignment throws.
  559. //! @li If \c throw_on_overflow<true> option is set and the container runs out of capacity.
  560. //!
  561. //! @par Complexity
  562. //! Constant or linear.
  563. iterator insert(const_iterator p, BOOST_RV_REF(value_type) value);
  564. //! @pre
  565. //! @li \c p must be a valid iterator of \c *this in range <tt>[begin(), end()]</tt>.
  566. //! @li <tt>size() + count <= capacity()</tt>
  567. //!
  568. //! @brief Inserts a count copies of value at p.
  569. //!
  570. //! @param p The position at which new elements will be inserted.
  571. //! @param count The number of new elements which will be inserted.
  572. //! @param value The value used to copy construct new elements.
  573. //!
  574. //! @par Throws
  575. //! @li If T's copy constructor or copy assignment throws.
  576. //! @li If T's move constructor or move assignment throws.
  577. //! @li If \c throw_on_overflow<true> option is set and the container runs out of capacity.
  578. //!
  579. //! @par Complexity
  580. //! Linear O(N).
  581. iterator insert(const_iterator p, size_type count, value_type const& value);
  582. //! @pre
  583. //! @li \c p must be a valid iterator of \c *this in range <tt>[begin(), end()]</tt>.
  584. //! @li <tt>distance(first, last) <= capacity()</tt>
  585. //! @li \c Iterator must meet the \c ForwardTraversalIterator concept.
  586. //!
  587. //! @brief Inserts a copy of a range <tt>[first, last)</tt> at p.
  588. //!
  589. //! @param p The position at which new elements will be inserted.
  590. //! @param first The iterator to the first element of a range used to construct new elements.
  591. //! @param last The iterator to the one after the last element of a range used to construct new elements.
  592. //!
  593. //! @par Throws
  594. //! @li If T's constructor and assignment taking a dereferenced \c Iterator.
  595. //! @li If T's move constructor or move assignment throws.
  596. //! @li If \c throw_on_overflow<true> option is set and the container runs out of capacity.
  597. //!
  598. //! @par Complexity
  599. //! Linear O(N).
  600. template <typename Iterator>
  601. iterator insert(const_iterator p, Iterator first, Iterator last);
  602. //! @pre
  603. //! @li \c p must be a valid iterator of \c *this in range <tt>[begin(), end()]</tt>.
  604. //! @li <tt>distance(il.begin(), il.end()) <= capacity()</tt>
  605. //!
  606. //! @brief Inserts a copy of a range <tt>[il.begin(), il.end())</tt> at p.
  607. //!
  608. //! @param p The position at which new elements will be inserted.
  609. //! @param il The std::initializer_list which contains elements that will be inserted.
  610. //!
  611. //! @par Throws
  612. //! @li If T's constructor and assignment taking a dereferenced std::initializer_list iterator.
  613. //! @li If \c throw_on_overflow<true> option is set and the container runs out of capacity.
  614. //!
  615. //! @par Complexity
  616. //! Linear O(N).
  617. iterator insert(const_iterator p, std::initializer_list<value_type> il);
  618. //! @pre \c p must be a valid iterator of \c *this in range <tt>[begin(), end())</tt>
  619. //!
  620. //! @brief Erases T from p.
  621. //!
  622. //! @param p The position of the element which will be erased from the container.
  623. //!
  624. //! @par Throws
  625. //! If T's move assignment throws.
  626. //!
  627. //! @par Complexity
  628. //! Linear O(N).
  629. iterator erase(const_iterator p);
  630. //! @pre
  631. //! @li \c first and \c last must define a valid range
  632. //! @li iterators must be in range <tt>[begin(), end()]</tt>
  633. //!
  634. //! @brief Erases Values from a range <tt>[first, last)</tt>.
  635. //!
  636. //! @param first The position of the first element of a range which will be erased from the container.
  637. //! @param last The position of the one after the last element of a range which will be erased from the container.
  638. //!
  639. //! @par Throws
  640. //! If T's move assignment throws.
  641. //!
  642. //! @par Complexity
  643. //! Linear O(N).
  644. iterator erase(const_iterator first, const_iterator last);
  645. //! @pre <tt>distance(first, last) <= capacity()</tt>
  646. //!
  647. //! @brief Assigns a range <tt>[first, last)</tt> of Values to this container.
  648. //!
  649. //! @param first The iterator to the first element of a range used to construct new content of this container.
  650. //! @param last The iterator to the one after the last element of a range used to construct new content of this container.
  651. //!
  652. //! @par Throws
  653. //! @li If T's copy constructor or copy assignment throws,
  654. //! @li If \c throw_on_overflow<true> option is set and the container runs out of capacity.
  655. //!
  656. //! @par Complexity
  657. //! Linear O(N).
  658. template <typename Iterator>
  659. void assign(Iterator first, Iterator last);
  660. //! @pre <tt>distance(il.begin(), il.end()) <= capacity()</tt>
  661. //!
  662. //! @brief Assigns a range <tt>[il.begin(), il.end())</tt> of Values to this container.
  663. //!
  664. //! @param il std::initializer_list with values used to construct new content of this container.
  665. //!
  666. //! @par Throws
  667. //! @li If T's copy constructor or copy assignment throws,
  668. //! @li If \c throw_on_overflow<true> option is set and the container runs out of capacity.
  669. //!
  670. //! @par Complexity
  671. //! Linear O(N).
  672. void assign(std::initializer_list<value_type> il);
  673. //! @pre <tt>count <= capacity()</tt>
  674. //!
  675. //! @brief Assigns a count copies of value to this container.
  676. //!
  677. //! @param count The new number of elements which will be container in the container.
  678. //! @param value The value which will be used to copy construct the new content.
  679. //!
  680. //! @par Throws
  681. //! @li If T's copy constructor or copy assignment throws.
  682. //! @li If \c throw_on_overflow<true> option is set and the container runs out of capacity.
  683. //!
  684. //! @par Complexity
  685. //! Linear O(N).
  686. void assign(size_type count, value_type const& value);
  687. //! @pre <tt>size() < capacity()</tt>
  688. //!
  689. //! @brief Inserts a T constructed with
  690. //! \c std::forward<Args>(args)... in the end of the container.
  691. //!
  692. //! @return A reference to the created object.
  693. //!
  694. //! @param args The arguments of the constructor of the new element which will be created at the end of the container.
  695. //!
  696. //! @par Throws
  697. //! @li If in-place constructor throws or T's move constructor throws.
  698. //! @li If \c throw_on_overflow<true> option is set and the container runs out of capacity.
  699. //!
  700. //! @par Complexity
  701. //! Constant O(1).
  702. template<class ...Args>
  703. reference emplace_back(Args &&...args);
  704. //! @pre
  705. //! @li \c p must be a valid iterator of \c *this in range <tt>[begin(), end()]</tt>
  706. //! @li <tt>size() < capacity()</tt>
  707. //!
  708. //! @brief Inserts a T constructed with
  709. //! \c std::forward<Args>(args)... before p
  710. //!
  711. //! @param p The position at which new elements will be inserted.
  712. //! @param args The arguments of the constructor of the new element.
  713. //!
  714. //! @par Throws
  715. //! @li If in-place constructor throws or if T's move constructor or move assignment throws.
  716. //! @li If \c throw_on_overflow<true> option is set and the container runs out of capacity.
  717. //!
  718. //! @par Complexity
  719. //! Constant or linear.
  720. template<class ...Args>
  721. iterator emplace(const_iterator p, Args &&...args);
  722. //! @brief Removes all elements from the container.
  723. //!
  724. //! @par Throws
  725. //! Nothing.
  726. //!
  727. //! @par Complexity
  728. //! Constant O(1).
  729. void clear() BOOST_NOEXCEPT_OR_NOTHROW;
  730. //! @pre <tt>i < size()</tt>
  731. //!
  732. //! @brief Returns reference to the i-th element.
  733. //!
  734. //! @param i The element's index.
  735. //!
  736. //! @return reference to the i-th element
  737. //! from the beginning of the container.
  738. //!
  739. //! @par Throws
  740. //! \c out_of_range exception by default.
  741. //!
  742. //! @par Complexity
  743. //! Constant O(1).
  744. reference at(size_type i);
  745. //! @pre <tt>i < size()</tt>
  746. //!
  747. //! @brief Returns const reference to the i-th element.
  748. //!
  749. //! @param i The element's index.
  750. //!
  751. //! @return const reference to the i-th element
  752. //! from the beginning of the container.
  753. //!
  754. //! @par Throws
  755. //! \c out_of_range exception by default.
  756. //!
  757. //! @par Complexity
  758. //! Constant O(1).
  759. const_reference at(size_type i) const;
  760. //! @pre <tt>i < size()</tt>
  761. //!
  762. //! @brief Returns reference to the i-th element.
  763. //!
  764. //! @param i The element's index.
  765. //!
  766. //! @return reference to the i-th element
  767. //! from the beginning of the container.
  768. //!
  769. //! @par Throws
  770. //! Nothing.
  771. //!
  772. //! @par Complexity
  773. //! Constant O(1).
  774. reference operator[](size_type i) BOOST_NOEXCEPT_OR_NOTHROW;
  775. //! @pre <tt>i < size()</tt>
  776. //!
  777. //! @brief Returns const reference to the i-th element.
  778. //!
  779. //! @param i The element's index.
  780. //!
  781. //! @return const reference to the i-th element
  782. //! from the beginning of the container.
  783. //!
  784. //! @par Throws
  785. //! Nothing.
  786. //!
  787. //! @par Complexity
  788. //! Constant O(1).
  789. const_reference operator[](size_type i) const BOOST_NOEXCEPT_OR_NOTHROW;
  790. //! @pre <tt>i =< size()</tt>
  791. //!
  792. //! @brief Returns a iterator to the i-th element.
  793. //!
  794. //! @param i The element's index.
  795. //!
  796. //! @return a iterator to the i-th element.
  797. //!
  798. //! @par Throws
  799. //! Nothing.
  800. //!
  801. //! @par Complexity
  802. //! Constant O(1).
  803. iterator nth(size_type i) BOOST_NOEXCEPT_OR_NOTHROW;
  804. //! @pre <tt>i =< size()</tt>
  805. //!
  806. //! @brief Returns a const_iterator to the i-th element.
  807. //!
  808. //! @param i The element's index.
  809. //!
  810. //! @return a const_iterator to the i-th element.
  811. //!
  812. //! @par Throws
  813. //! Nothing by default.
  814. //!
  815. //! @par Complexity
  816. //! Constant O(1).
  817. const_iterator nth(size_type i) const BOOST_NOEXCEPT_OR_NOTHROW;
  818. //! @pre <tt>begin() <= p <= end()</tt>
  819. //!
  820. //! @brief Returns the index of the element pointed by p.
  821. //!
  822. //! @param p An iterator to the element.
  823. //!
  824. //! @return The index of the element pointed by p.
  825. //!
  826. //! @par Throws
  827. //! Nothing.
  828. //!
  829. //! @par Complexity
  830. //! Constant O(1).
  831. size_type index_of(iterator p) BOOST_NOEXCEPT_OR_NOTHROW;
  832. //! @pre <tt>begin() <= p <= end()</tt>
  833. //!
  834. //! @brief Returns the index of the element pointed by p.
  835. //!
  836. //! @param p A const_iterator to the element.
  837. //!
  838. //! @return a const_iterator to the i-th element.
  839. //!
  840. //! @par Throws
  841. //! Nothing.
  842. //!
  843. //! @par Complexity
  844. //! Constant O(1).
  845. size_type index_of(const_iterator p) const BOOST_NOEXCEPT_OR_NOTHROW;
  846. //! @pre \c !empty()
  847. //!
  848. //! @brief Returns reference to the first element.
  849. //!
  850. //! @return reference to the first element
  851. //! from the beginning of the container.
  852. //!
  853. //! @par Throws
  854. //! Nothing.
  855. //!
  856. //! @par Complexity
  857. //! Constant O(1).
  858. reference front() BOOST_NOEXCEPT_OR_NOTHROW;
  859. //! @pre \c !empty()
  860. //!
  861. //! @brief Returns const reference to the first element.
  862. //!
  863. //! @return const reference to the first element
  864. //! from the beginning of the container.
  865. //!
  866. //! @par Throws
  867. //! Nothing.
  868. //!
  869. //! @par Complexity
  870. //! Constant O(1).
  871. const_reference front() const BOOST_NOEXCEPT_OR_NOTHROW;
  872. //! @pre \c !empty()
  873. //!
  874. //! @brief Returns reference to the last element.
  875. //!
  876. //! @return reference to the last element
  877. //! from the beginning of the container.
  878. //!
  879. //! @par Throws
  880. //! Nothing.
  881. //!
  882. //! @par Complexity
  883. //! Constant O(1).
  884. reference back() BOOST_NOEXCEPT_OR_NOTHROW;
  885. //! @pre \c !empty()
  886. //!
  887. //! @brief Returns const reference to the first element.
  888. //!
  889. //! @return const reference to the last element
  890. //! from the beginning of the container.
  891. //!
  892. //! @par Throws
  893. //! Nothing.
  894. //!
  895. //! @par Complexity
  896. //! Constant O(1).
  897. const_reference back() const BOOST_NOEXCEPT_OR_NOTHROW;
  898. //! @brief Pointer such that <tt>[data(), data() + size())</tt> is a valid range.
  899. //! For a non-empty vector <tt>data() == &front()</tt>.
  900. //!
  901. //! @par Throws
  902. //! Nothing.
  903. //!
  904. //! @par Complexity
  905. //! Constant O(1).
  906. T * data() BOOST_NOEXCEPT_OR_NOTHROW;
  907. //! @brief Const pointer such that <tt>[data(), data() + size())</tt> is a valid range.
  908. //! For a non-empty vector <tt>data() == &front()</tt>.
  909. //!
  910. //! @par Throws
  911. //! Nothing.
  912. //!
  913. //! @par Complexity
  914. //! Constant O(1).
  915. const T * data() const BOOST_NOEXCEPT_OR_NOTHROW;
  916. //! @brief Returns iterator to the first element.
  917. //!
  918. //! @return iterator to the first element contained in the vector.
  919. //!
  920. //! @par Throws
  921. //! Nothing.
  922. //!
  923. //! @par Complexity
  924. //! Constant O(1).
  925. iterator begin() BOOST_NOEXCEPT_OR_NOTHROW;
  926. //! @brief Returns const iterator to the first element.
  927. //!
  928. //! @return const_iterator to the first element contained in the vector.
  929. //!
  930. //! @par Throws
  931. //! Nothing.
  932. //!
  933. //! @par Complexity
  934. //! Constant O(1).
  935. const_iterator begin() const BOOST_NOEXCEPT_OR_NOTHROW;
  936. //! @brief Returns const iterator to the first element.
  937. //!
  938. //! @return const_iterator to the first element contained in the vector.
  939. //!
  940. //! @par Throws
  941. //! Nothing.
  942. //!
  943. //! @par Complexity
  944. //! Constant O(1).
  945. const_iterator cbegin() const BOOST_NOEXCEPT_OR_NOTHROW;
  946. //! @brief Returns iterator to the one after the last element.
  947. //!
  948. //! @return iterator pointing to the one after the last element contained in the vector.
  949. //!
  950. //! @par Throws
  951. //! Nothing.
  952. //!
  953. //! @par Complexity
  954. //! Constant O(1).
  955. iterator end() BOOST_NOEXCEPT_OR_NOTHROW;
  956. //! @brief Returns const iterator to the one after the last element.
  957. //!
  958. //! @return const_iterator pointing to the one after the last element contained in the vector.
  959. //!
  960. //! @par Throws
  961. //! Nothing.
  962. //!
  963. //! @par Complexity
  964. //! Constant O(1).
  965. const_iterator end() const BOOST_NOEXCEPT_OR_NOTHROW;
  966. //! @brief Returns const iterator to the one after the last element.
  967. //!
  968. //! @return const_iterator pointing to the one after the last element contained in the vector.
  969. //!
  970. //! @par Throws
  971. //! Nothing.
  972. //!
  973. //! @par Complexity
  974. //! Constant O(1).
  975. const_iterator cend() const BOOST_NOEXCEPT_OR_NOTHROW;
  976. //! @brief Returns reverse iterator to the first element of the reversed container.
  977. //!
  978. //! @return reverse_iterator pointing to the beginning
  979. //! of the reversed static_vector.
  980. //!
  981. //! @par Throws
  982. //! Nothing.
  983. //!
  984. //! @par Complexity
  985. //! Constant O(1).
  986. reverse_iterator rbegin() BOOST_NOEXCEPT_OR_NOTHROW;
  987. //! @brief Returns const reverse iterator to the first element of the reversed container.
  988. //!
  989. //! @return const_reverse_iterator pointing to the beginning
  990. //! of the reversed static_vector.
  991. //!
  992. //! @par Throws
  993. //! Nothing.
  994. //!
  995. //! @par Complexity
  996. //! Constant O(1).
  997. const_reverse_iterator rbegin() const BOOST_NOEXCEPT_OR_NOTHROW;
  998. //! @brief Returns const reverse iterator to the first element of the reversed container.
  999. //!
  1000. //! @return const_reverse_iterator pointing to the beginning
  1001. //! of the reversed static_vector.
  1002. //!
  1003. //! @par Throws
  1004. //! Nothing.
  1005. //!
  1006. //! @par Complexity
  1007. //! Constant O(1).
  1008. const_reverse_iterator crbegin() const BOOST_NOEXCEPT_OR_NOTHROW;
  1009. //! @brief Returns reverse iterator to the one after the last element of the reversed container.
  1010. //!
  1011. //! @return reverse_iterator pointing to the one after the last element
  1012. //! of the reversed static_vector.
  1013. //!
  1014. //! @par Throws
  1015. //! Nothing.
  1016. //!
  1017. //! @par Complexity
  1018. //! Constant O(1).
  1019. reverse_iterator rend() BOOST_NOEXCEPT_OR_NOTHROW;
  1020. //! @brief Returns const reverse iterator to the one after the last element of the reversed container.
  1021. //!
  1022. //! @return const_reverse_iterator pointing to the one after the last element
  1023. //! of the reversed static_vector.
  1024. //!
  1025. //! @par Throws
  1026. //! Nothing.
  1027. //!
  1028. //! @par Complexity
  1029. //! Constant O(1).
  1030. const_reverse_iterator rend() const BOOST_NOEXCEPT_OR_NOTHROW;
  1031. //! @brief Returns const reverse iterator to the one after the last element of the reversed container.
  1032. //!
  1033. //! @return const_reverse_iterator pointing to the one after the last element
  1034. //! of the reversed static_vector.
  1035. //!
  1036. //! @par Throws
  1037. //! Nothing.
  1038. //!
  1039. //! @par Complexity
  1040. //! Constant O(1).
  1041. const_reverse_iterator crend() const BOOST_NOEXCEPT_OR_NOTHROW;
  1042. #endif //#ifdef BOOST_CONTAINER_DOXYGEN_INVOKED
  1043. //! @brief Returns container's capacity.
  1044. //!
  1045. //! @return container's capacity.
  1046. //!
  1047. //! @par Throws
  1048. //! Nothing.
  1049. //!
  1050. //! @par Complexity
  1051. //! Constant O(1).
  1052. inline static size_type capacity() BOOST_NOEXCEPT_OR_NOTHROW
  1053. { return static_capacity; }
  1054. //! @brief Returns container's capacity.
  1055. //!
  1056. //! @return container's capacity.
  1057. //!
  1058. //! @par Throws
  1059. //! Nothing.
  1060. //!
  1061. //! @par Complexity
  1062. //! Constant O(1).
  1063. inline static size_type max_size() BOOST_NOEXCEPT_OR_NOTHROW
  1064. { return static_capacity; }
  1065. #ifdef BOOST_CONTAINER_DOXYGEN_INVOKED
  1066. //! @brief Returns the number of stored elements.
  1067. //!
  1068. //! @return Number of elements contained in the container.
  1069. //!
  1070. //! @par Throws
  1071. //! Nothing.
  1072. //!
  1073. //! @par Complexity
  1074. //! Constant O(1).
  1075. size_type size() const BOOST_NOEXCEPT_OR_NOTHROW;
  1076. //! @brief Queries if the container contains elements.
  1077. //!
  1078. //! @return true if the number of elements contained in the
  1079. //! container is equal to 0.
  1080. //!
  1081. //! @par Throws
  1082. //! Nothing.
  1083. //!
  1084. //! @par Complexity
  1085. //! Constant O(1).
  1086. bool empty() const BOOST_NOEXCEPT_OR_NOTHROW;
  1087. #else
  1088. inline friend void swap(static_vector &x, static_vector &y)
  1089. BOOST_NOEXCEPT_IF(BOOST_NOEXCEPT(x.swap(y)))
  1090. {
  1091. x.swap(y);
  1092. }
  1093. #endif // BOOST_CONTAINER_DOXYGEN_INVOKED
  1094. };
  1095. #ifdef BOOST_CONTAINER_DOXYGEN_INVOKED
  1096. //! @brief Checks if contents of two static_vectors are equal.
  1097. //!
  1098. //! @ingroup static_vector_non_member
  1099. //!
  1100. //! @param x The first static_vector.
  1101. //! @param y The second static_vector.
  1102. //!
  1103. //! @return \c true if containers have the same size and elements in both containers are equal.
  1104. //!
  1105. //! @par Complexity
  1106. //! Linear O(N).
  1107. template<typename V, std::size_t C1, std::size_t C2, class O1, class O2>
  1108. bool operator== (static_vector<V, C1, O1> const& x, static_vector<V, C2, O2> const& y);
  1109. //! @brief Checks if contents of two static_vectors are not equal.
  1110. //!
  1111. //! @ingroup static_vector_non_member
  1112. //!
  1113. //! @param x The first static_vector.
  1114. //! @param y The second static_vector.
  1115. //!
  1116. //! @return \c true if containers have different size or elements in both containers are not equal.
  1117. //!
  1118. //! @par Complexity
  1119. //! Linear O(N).
  1120. template<typename V, std::size_t C1, std::size_t C2, class O1, class O2>
  1121. bool operator!= (static_vector<V, C1, O1> const& x, static_vector<V, C2, O2> const& y);
  1122. //! @brief Lexicographically compares static_vectors.
  1123. //!
  1124. //! @ingroup static_vector_non_member
  1125. //!
  1126. //! @param x The first static_vector.
  1127. //! @param y The second static_vector.
  1128. //!
  1129. //! @return \c true if x compares lexicographically less than y.
  1130. //!
  1131. //! @par Complexity
  1132. //! Linear O(N).
  1133. template<typename V, std::size_t C1, std::size_t C2, class O1, class O2>
  1134. bool operator< (static_vector<V, C1, O1> const& x, static_vector<V, C2, O2> const& y);
  1135. //! @brief Lexicographically compares static_vectors.
  1136. //!
  1137. //! @ingroup static_vector_non_member
  1138. //!
  1139. //! @param x The first static_vector.
  1140. //! @param y The second static_vector.
  1141. //!
  1142. //! @return \c true if y compares lexicographically less than x.
  1143. //!
  1144. //! @par Complexity
  1145. //! Linear O(N).
  1146. template<typename V, std::size_t C1, std::size_t C2, class O1, class O2>
  1147. bool operator> (static_vector<V, C1, O1> const& x, static_vector<V, C2, O2> const& y);
  1148. //! @brief Lexicographically compares static_vectors.
  1149. //!
  1150. //! @ingroup static_vector_non_member
  1151. //!
  1152. //! @param x The first static_vector.
  1153. //! @param y The second static_vector.
  1154. //!
  1155. //! @return \c true if y don't compare lexicographically less than x.
  1156. //!
  1157. //! @par Complexity
  1158. //! Linear O(N).
  1159. template<typename V, std::size_t C1, std::size_t C2, class O1, class O2>
  1160. bool operator<= (static_vector<V, C1, O1> const& x, static_vector<V, C2, O2> const& y);
  1161. //! @brief Lexicographically compares static_vectors.
  1162. //!
  1163. //! @ingroup static_vector_non_member
  1164. //!
  1165. //! @param x The first static_vector.
  1166. //! @param y The second static_vector.
  1167. //!
  1168. //! @return \c true if x don't compare lexicographically less than y.
  1169. //!
  1170. //! @par Complexity
  1171. //! Linear O(N).
  1172. template<typename V, std::size_t C1, std::size_t C2, class O1, class O2>
  1173. bool operator>= (static_vector<V, C1, O1> const& x, static_vector<V, C2, O2> const& y);
  1174. //! @brief Swaps contents of two static_vectors.
  1175. //!
  1176. //! This function calls static_vector::swap().
  1177. //!
  1178. //! @ingroup static_vector_non_member
  1179. //!
  1180. //! @param x The first static_vector.
  1181. //! @param y The second static_vector.
  1182. //!
  1183. //! @par Complexity
  1184. //! Linear O(N).
  1185. template<typename V, std::size_t C1, std::size_t C2, class O1, class O2>
  1186. inline void swap(static_vector<V, C1, O1> & x, static_vector<V, C2, O2> & y)
  1187. BOOST_NOEXCEPT_IF(BOOST_NOEXCEPT(x.swap(y)));
  1188. #else
  1189. template<typename V, std::size_t C1, std::size_t C2, class O1, class O2>
  1190. inline void swap(static_vector<V, C1, O1> & x, static_vector<V, C2, O2> & y
  1191. , typename dtl::enable_if_c< C1 != C2>::type * = 0)
  1192. BOOST_NOEXCEPT_IF(BOOST_NOEXCEPT(x.swap(y)))
  1193. {
  1194. x.swap(y);
  1195. }
  1196. #endif // BOOST_CONTAINER_DOXYGEN_INVOKED
  1197. }} // namespace boost::container
  1198. #include <boost/container/detail/config_end.hpp>
  1199. #endif // BOOST_CONTAINER_STATIC_VECTOR_HPP