static_vector.hpp 46 KB

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