static_vector.hpp 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363
  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