array.hpp 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792
  1. //
  2. // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com)
  3. //
  4. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. //
  7. // Official repository: https://github.com/boostorg/json
  8. //
  9. #ifndef BOOST_JSON_ARRAY_HPP
  10. #define BOOST_JSON_ARRAY_HPP
  11. #include <boost/json/detail/config.hpp>
  12. #include <boost/json/detail/array.hpp>
  13. #include <boost/json/kind.hpp>
  14. #include <boost/json/pilfer.hpp>
  15. #include <boost/json/storage_ptr.hpp>
  16. #include <boost/system/result.hpp>
  17. #include <cstdlib>
  18. #include <initializer_list>
  19. #include <iterator>
  20. namespace boost {
  21. namespace json {
  22. #ifndef BOOST_JSON_DOCS
  23. class value;
  24. class value_ref;
  25. #endif
  26. /** A dynamically sized array of JSON values
  27. This is the type used to represent a JSON array as
  28. a modifiable container. The interface and performance
  29. characteristics are modeled after `std::vector<value>`.
  30. \n
  31. Elements are stored contiguously, which means that
  32. they can be accessed not only through iterators, but
  33. also using offsets to regular pointers to elements. A
  34. pointer to an element of an @ref array may be passed to
  35. any function that expects a pointer to @ref value.
  36. \n
  37. The storage of the array is handled automatically, being
  38. expanded and contracted as needed. Arrays usually occupy
  39. more space than array language constructs, because more
  40. memory is allocated to handle future growth. This way an
  41. array does not need to reallocate each time an element
  42. is inserted, but only when the additional memory is used
  43. up. The total amount of allocated memory can be queried
  44. using the @ref capacity function. Extra memory can be
  45. relinquished by calling @ref shrink_to_fit.
  46. \n
  47. Reallocations are usually costly operations in terms of
  48. performance. The @ref reserve function can be used to
  49. eliminate reallocations if the number of elements is
  50. known beforehand.
  51. \n
  52. The complexity (efficiency) of common operations on
  53. arrays is as follows:
  54. @li Random access - constant *O(1)*.
  55. @li Insertion or removal of elements at the
  56. end - amortized constant *O(1)*.
  57. @li Insertion or removal of elements - linear in
  58. the distance to the end of the array *O(n)*.
  59. @par Allocators
  60. All elements stored in the container, and their
  61. children if any, will use the same memory resource
  62. that was used to construct the container.
  63. @par Thread Safety
  64. Non-const member functions may not be called
  65. concurrently with any other member functions.
  66. @par Satisfies
  67. <a href="https://en.cppreference.com/w/cpp/named_req/ContiguousContainer"><em>ContiguousContainer</em></a>,
  68. <a href="https://en.cppreference.com/w/cpp/named_req/ReversibleContainer"><em>ReversibleContainer</em></a>, and
  69. <a href="https://en.cppreference.com/w/cpp/named_req/SequenceContainer"><em>SequenceContainer</em></a>.
  70. */
  71. class array
  72. {
  73. struct table;
  74. class revert_construct;
  75. class revert_insert;
  76. friend class value;
  77. storage_ptr sp_; // must come first
  78. kind k_ = kind::array; // must come second
  79. table* t_;
  80. BOOST_JSON_DECL
  81. static table empty_;
  82. inline
  83. static
  84. void
  85. relocate(
  86. value* dest,
  87. value* src,
  88. std::size_t n) noexcept;
  89. inline
  90. void
  91. destroy(
  92. value* first,
  93. value* last) noexcept;
  94. BOOST_JSON_DECL
  95. void
  96. destroy() noexcept;
  97. BOOST_JSON_DECL
  98. explicit
  99. array(detail::unchecked_array&& ua);
  100. public:
  101. /// Associated [Allocator](https://en.cppreference.com/w/cpp/named_req/Allocator)
  102. using allocator_type = container::pmr::polymorphic_allocator<value>;
  103. /// The type used to represent unsigned integers
  104. using size_type = std::size_t;
  105. /// The type of each element
  106. using value_type = value;
  107. /// The type used to represent signed integers
  108. using difference_type = std::ptrdiff_t;
  109. /// A reference to an element
  110. using reference = value&;
  111. /// A const reference to an element
  112. using const_reference = value const&;
  113. /// A pointer to an element
  114. using pointer = value*;
  115. /// A const pointer to an element
  116. using const_pointer = value const*;
  117. /// A random access iterator to an element
  118. using iterator = value*;
  119. /// A random access const iterator to an element
  120. using const_iterator = value const*;
  121. /// A reverse random access iterator to an element
  122. using reverse_iterator =
  123. std::reverse_iterator<iterator>;
  124. /// A reverse random access const iterator to an element
  125. using const_reverse_iterator =
  126. std::reverse_iterator<const_iterator>;
  127. //------------------------------------------------------
  128. /** Destructor.
  129. The destructor for each element is called if needed,
  130. any used memory is deallocated, and shared ownership
  131. of the `boost::container::pmr::memory_resource` is released.
  132. @par Complexity
  133. Constant, or linear in @ref size().
  134. @par Exception Safety
  135. No-throw guarantee.
  136. */
  137. BOOST_JSON_DECL
  138. ~array() noexcept;
  139. //------------------------------------------------------
  140. /** Constructor.
  141. The constructed array is empty with zero
  142. capacity, using the [default memory resource].
  143. @par Complexity
  144. Constant.
  145. @par Exception Safety
  146. No-throw guarantee.
  147. [default memory resource]: json/allocators/storage_ptr.html#json.allocators.storage_ptr.default_memory_resource
  148. */
  149. array() noexcept
  150. : t_(&empty_)
  151. {
  152. }
  153. /** Constructor.
  154. The constructed array is empty with zero
  155. capacity, using the specified memory resource.
  156. @par Complexity
  157. Constant.
  158. @par Exception Safety
  159. No-throw guarantee.
  160. @param sp A pointer to the `boost::container::pmr::memory_resource`
  161. to use. The container will acquire shared
  162. ownership of the memory resource.
  163. */
  164. explicit
  165. array(storage_ptr sp) noexcept
  166. : sp_(std::move(sp))
  167. , k_(kind::array)
  168. , t_(&empty_)
  169. {
  170. }
  171. /** Constructor.
  172. The array is constructed with `count`
  173. copies of the value `v`, using the
  174. specified memory resource.
  175. @par Complexity
  176. Linear in `count`
  177. @par Exception Safety
  178. Strong guarantee.
  179. Calls to `memory_resource::allocate` may throw.
  180. @param count The number of copies to insert.
  181. @param v The value to be inserted.
  182. @param sp A pointer to the `boost::container::pmr::memory_resource`
  183. to use. The container will acquire shared
  184. ownership of the memory resource.
  185. */
  186. BOOST_JSON_DECL
  187. array(
  188. std::size_t count,
  189. value const& v,
  190. storage_ptr sp = {});
  191. /** Constructor.
  192. The array is constructed with `count` null values,
  193. using the specified memory resource.
  194. @par Complexity
  195. Linear in `count`
  196. @par Exception Safety
  197. Strong guarantee.
  198. Calls to `memory_resource::allocate` may throw.
  199. @param count The number of nulls to insert.
  200. @param sp A pointer to the `boost::container::pmr::memory_resource`
  201. to use. The container will acquire shared
  202. ownership of the memory resource.
  203. */
  204. BOOST_JSON_DECL
  205. array(
  206. std::size_t count,
  207. storage_ptr sp = {});
  208. /** Constructor.
  209. The array is constructed with the elements
  210. in the range `{first, last)`, preserving order,
  211. using the specified memory resource.
  212. @par Constraints
  213. @code
  214. std::is_constructible_v<value, std::iterator_traits<InputIt>::reference>
  215. @endcode
  216. @par Complexity
  217. Linear in `std::distance(first, last)`
  218. @par Exception Safety
  219. Strong guarantee.
  220. Calls to `memory_resource::allocate` may throw.
  221. @param first An input iterator pointing to the
  222. first element to insert, or pointing to the end
  223. of the range.
  224. @param last An input iterator pointing to the end
  225. of the range.
  226. @param sp A pointer to the `boost::container::pmr::memory_resource`
  227. to use. The container will acquire shared
  228. ownership of the memory resource.
  229. @tparam InputIt a type satisfying the requirements
  230. of __InputIterator__.
  231. */
  232. template<
  233. class InputIt
  234. #ifndef BOOST_JSON_DOCS
  235. ,class = typename std::enable_if<
  236. std::is_constructible<value,
  237. typename std::iterator_traits<
  238. InputIt>::reference>::value>::type
  239. #endif
  240. >
  241. array(
  242. InputIt first, InputIt last,
  243. storage_ptr sp = {});
  244. /** Copy constructor.
  245. The array is constructed with a copy of the
  246. contents of `other`, using `other`'s memory resource.
  247. @par Complexity
  248. Linear in `other.size()`.
  249. @par Exception Safety
  250. Strong guarantee.
  251. Calls to `memory_resource::allocate` may throw.
  252. @param other The array to copy
  253. */
  254. BOOST_JSON_DECL
  255. array(array const& other);
  256. /** Copy constructor.
  257. The array is constructed with a copy of the
  258. contents of `other`, using the specified memory resource.
  259. @par Complexity
  260. Linear in `other.size()`.
  261. @par Exception Safety
  262. Strong guarantee.
  263. Calls to `memory_resource::allocate` may throw.
  264. @param other The array to copy
  265. @param sp A pointer to the `boost::container::pmr::memory_resource`
  266. to use. The container will acquire shared
  267. ownership of the memory resource.
  268. */
  269. BOOST_JSON_DECL
  270. array(
  271. array const& other,
  272. storage_ptr sp);
  273. /** Pilfer constructor.
  274. The array is constructed by acquiring ownership
  275. of the contents of `other` using pilfer semantics.
  276. This is more efficient than move construction, when
  277. it is known that the moved-from object will be
  278. immediately destroyed afterwards.
  279. @par Complexity
  280. Constant.
  281. @par Exception Safety
  282. No-throw guarantee.
  283. @param other The value to pilfer. After pilfer
  284. construction, `other` is not in a usable state
  285. and may only be destroyed.
  286. @see @ref pilfer,
  287. <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0308r0.html">
  288. Valueless Variants Considered Harmful</a>
  289. */
  290. array(pilfered<array> other) noexcept
  291. : sp_(std::move(other.get().sp_))
  292. , t_(detail::exchange(
  293. other.get().t_, &empty_))
  294. {
  295. }
  296. /** Move constructor.
  297. The array is constructed by acquiring ownership of
  298. the contents of `other` and shared ownership of
  299. `other`'s memory resource.
  300. @note
  301. After construction, the moved-from array behaves
  302. as if newly constructed with its current storage
  303. pointer.
  304. @par Complexity
  305. Constant.
  306. @par Exception Safety
  307. No-throw guarantee.
  308. @param other The container to move
  309. */
  310. array(array&& other) noexcept
  311. : sp_(other.sp_)
  312. , t_(detail::exchange(
  313. other.t_, &empty_))
  314. {
  315. }
  316. /** Move constructor.
  317. The array is constructed with the contents of
  318. `other` by move semantics, using the specified
  319. memory resource:
  320. @li If `*other.storage() == *sp`, ownership of
  321. the underlying memory is transferred in constant
  322. time, with no possibility of exceptions.
  323. After construction, the moved-from array behaves
  324. as if newly constructed with its current storage
  325. pointer.
  326. @li If `*other.storage() != *sp`, an
  327. element-wise copy is performed, which may throw.
  328. In this case, the moved-from array is not
  329. changed.
  330. @par Complexity
  331. At most, linear in `other.size()`.
  332. @par Exception Safety
  333. Strong guarantee.
  334. Calls to `memory_resource::allocate` may throw.
  335. @param other The container to move
  336. @param sp A pointer to the `boost::container::pmr::memory_resource`
  337. to use. The container will acquire shared
  338. ownership of the memory resource.
  339. */
  340. BOOST_JSON_DECL
  341. array(
  342. array&& other,
  343. storage_ptr sp);
  344. /** Constructor.
  345. The array is constructed with a copy of the values
  346. in the initializer-list in order, using the
  347. specified memory resource.
  348. @par Complexity
  349. Linear in `init.size()`.
  350. @par Exception Safety
  351. Strong guarantee.
  352. Calls to `memory_resource::allocate` may throw.
  353. @param init The initializer list to insert
  354. @param sp A pointer to the `boost::container::pmr::memory_resource`
  355. to use. The container will acquire shared
  356. ownership of the memory resource.
  357. */
  358. BOOST_JSON_DECL
  359. array(
  360. std::initializer_list<value_ref> init,
  361. storage_ptr sp = {});
  362. //------------------------------------------------------
  363. /** Copy assignment.
  364. The contents of the array are replaced with an
  365. element-wise copy of `other`.
  366. @par Complexity
  367. Linear in @ref size() plus `other.size()`.
  368. @par Exception Safety
  369. Strong guarantee.
  370. Calls to `memory_resource::allocate` may throw.
  371. @param other The array to copy.
  372. */
  373. BOOST_JSON_DECL
  374. array&
  375. operator=(array const& other);
  376. /** Move assignment.
  377. The contents of the array are replaced with the
  378. contents of `other` using move semantics:
  379. @li If `*other.storage() == *sp`, ownership of
  380. the underlying memory is transferred in constant
  381. time, with no possibility of exceptions.
  382. After assignment, the moved-from array behaves
  383. as if newly constructed with its current storage
  384. pointer.
  385. @li If `*other.storage() != *sp`, an
  386. element-wise copy is performed, which may throw.
  387. In this case, the moved-from array is not
  388. changed.
  389. @par Complexity
  390. Constant, or linear in
  391. `this->size()` plus `other.size()`.
  392. @par Exception Safety
  393. Strong guarantee.
  394. Calls to `memory_resource::allocate` may throw.
  395. @param other The array to move.
  396. */
  397. BOOST_JSON_DECL
  398. array&
  399. operator=(array&& other);
  400. /** Assignment.
  401. The contents of the array are replaced with a
  402. copy of the values in the initializer-list.
  403. @par Complexity
  404. Linear in `this->size()` plus `init.size()`.
  405. @par Exception Safety
  406. Strong guarantee.
  407. Calls to `memory_resource::allocate` may throw.
  408. @param init The initializer list to copy.
  409. */
  410. BOOST_JSON_DECL
  411. array&
  412. operator=(
  413. std::initializer_list<value_ref> init);
  414. //------------------------------------------------------
  415. /** Return the associated memory resource.
  416. This function returns the `boost::container::pmr::memory_resource` used
  417. by the container.
  418. @par Complexity
  419. Constant.
  420. @par Exception Safety
  421. No-throw guarantee.
  422. */
  423. storage_ptr const&
  424. storage() const noexcept
  425. {
  426. return sp_;
  427. }
  428. /** Return the associated allocator.
  429. This function returns an instance of @ref allocator_type constructed
  430. from the associated `boost::container::pmr::memory_resource`.
  431. @par Complexity
  432. Constant.
  433. @par Exception Safety
  434. No-throw guarantee.
  435. */
  436. allocator_type
  437. get_allocator() const noexcept
  438. {
  439. return sp_.get();
  440. }
  441. //------------------------------------------------------
  442. //
  443. // Element access
  444. //
  445. //------------------------------------------------------
  446. /** Access an element, with bounds checking.
  447. Returns `boost::system::result` containing a reference to the element
  448. specified at location `pos`, if `pos` is within the range of the
  449. container. Otherwise the result contains an `error_code`.
  450. @par Exception Safety
  451. No-throw guarantee.
  452. @param pos A zero-based index.
  453. @par Complexity
  454. Constant.
  455. */
  456. /** @{ */
  457. BOOST_JSON_DECL
  458. system::result<value&>
  459. try_at(std::size_t pos) noexcept;
  460. BOOST_JSON_DECL
  461. system::result<value const&>
  462. try_at(std::size_t pos) const noexcept;
  463. /** @} */
  464. /** Access an element, with bounds checking.
  465. Returns a reference to the element specified at
  466. location `pos`, with bounds checking. If `pos` is
  467. not within the range of the container, an exception
  468. of type `boost::system::system_error` is thrown.
  469. @par Complexity
  470. Constant.
  471. @param pos A zero-based index.
  472. @param loc `source_location` to use in thrown exception; the source
  473. location of the call site by default.
  474. @throw `boost::system::system_error` `pos >= size()`.
  475. */
  476. /** @{ */
  477. inline
  478. value&
  479. at(
  480. std::size_t pos,
  481. source_location const& loc = BOOST_CURRENT_LOCATION) &;
  482. inline
  483. value&&
  484. at(
  485. std::size_t pos,
  486. source_location const& loc = BOOST_CURRENT_LOCATION) &&;
  487. BOOST_JSON_DECL
  488. value const&
  489. at(
  490. std::size_t pos,
  491. source_location const& loc = BOOST_CURRENT_LOCATION) const&;
  492. /** @} */
  493. /** Access an element.
  494. Returns a reference to the element specified at
  495. location `pos`. No bounds checking is performed.
  496. @par Precondition
  497. `pos < size()`
  498. @par Complexity
  499. Constant.
  500. @param pos A zero-based index
  501. */
  502. /** @{ */
  503. inline
  504. value&
  505. operator[](std::size_t pos) & noexcept;
  506. inline
  507. value&&
  508. operator[](std::size_t pos) && noexcept;
  509. inline
  510. value const&
  511. operator[](std::size_t pos) const& noexcept;
  512. /** @} */
  513. /** Access the first element.
  514. Returns a reference to the first element.
  515. @par Precondition
  516. `not empty()`
  517. @par Complexity
  518. Constant.
  519. */
  520. /** @{ */
  521. inline
  522. value&
  523. front() & noexcept;
  524. inline
  525. value&&
  526. front() && noexcept;
  527. inline
  528. value const&
  529. front() const& noexcept;
  530. /** @} */
  531. /** Access the last element.
  532. Returns a reference to the last element.
  533. @par Precondition
  534. `not empty()`
  535. @par Complexity
  536. Constant.
  537. */
  538. /** @{ */
  539. inline
  540. value&
  541. back() & noexcept;
  542. inline
  543. value&&
  544. back() && noexcept;
  545. inline
  546. value const&
  547. back() const& noexcept;
  548. /** @} */
  549. /** Access the underlying array directly.
  550. Returns a pointer to the underlying array serving
  551. as element storage. The value returned is such that
  552. the range `{data(), data() + size())` is always a
  553. valid range, even if the container is empty.
  554. @par Complexity
  555. Constant.
  556. @par Exception Safety
  557. No-throw guarantee.
  558. @note
  559. If `size() == 0`, the function may or may not return
  560. a null pointer.
  561. */
  562. inline
  563. value*
  564. data() noexcept;
  565. /** Access the underlying array directly.
  566. Returns a pointer to the underlying array serving
  567. as element storage. The value returned is such that
  568. the range `{data(), data() + size())` is always a
  569. valid range, even if the container is empty.
  570. @par Complexity
  571. Constant.
  572. @par Exception Safety
  573. No-throw guarantee.
  574. @note
  575. If `size() == 0`, the function may or may not return
  576. a null pointer.
  577. */
  578. inline
  579. value const*
  580. data() const noexcept;
  581. /** Return a pointer to an element, or nullptr if the index is invalid
  582. This function returns a pointer to the element
  583. at index `pos` when the index is less then the size
  584. of the container. Otherwise it returns null.
  585. @par Example
  586. @code
  587. if( auto p = arr.if_contains( 1 ) )
  588. std::cout << *p;
  589. @endcode
  590. @par Complexity
  591. Constant.
  592. @par Exception Safety
  593. No-throw guarantee.
  594. @param pos The index of the element to return.
  595. */
  596. inline
  597. value const*
  598. if_contains(std::size_t pos) const noexcept;
  599. /** Return a pointer to an element, or nullptr if the index is invalid
  600. This function returns a pointer to the element
  601. at index `pos` when the index is less then the size
  602. of the container. Otherwise it returns null.
  603. @par Example
  604. @code
  605. if( auto p = arr.if_contains( 1 ) )
  606. std::cout << *p;
  607. @endcode
  608. @par Complexity
  609. Constant.
  610. @par Exception Safety
  611. No-throw guarantee.
  612. @param pos The index of the element to return.
  613. */
  614. inline
  615. value*
  616. if_contains(std::size_t pos) noexcept;
  617. //------------------------------------------------------
  618. //
  619. // Iterators
  620. //
  621. //------------------------------------------------------
  622. /** Return an iterator to the first element.
  623. If the container is empty, @ref end() is returned.
  624. @par Complexity
  625. Constant.
  626. @par Exception Safety
  627. No-throw guarantee.
  628. */
  629. inline
  630. iterator
  631. begin() noexcept;
  632. /** Return a const iterator to the first element.
  633. If the container is empty, @ref end() is returned.
  634. @par Complexity
  635. Constant.
  636. @par Exception Safety
  637. No-throw guarantee.
  638. */
  639. inline
  640. const_iterator
  641. begin() const noexcept;
  642. /** Return a const iterator to the first element.
  643. If the container is empty, @ref cend() is returned.
  644. @par Complexity
  645. Constant.
  646. @par Exception Safety
  647. No-throw guarantee.
  648. */
  649. inline
  650. const_iterator
  651. cbegin() const noexcept;
  652. /** Return an iterator to the element following the last element.
  653. The element acts as a placeholder; attempting
  654. to access it results in undefined behavior.
  655. @par Complexity
  656. Constant.
  657. @par Exception Safety
  658. No-throw guarantee.
  659. */
  660. inline
  661. iterator
  662. end() noexcept;
  663. /** Return a const iterator to the element following the last element.
  664. The element acts as a placeholder; attempting
  665. to access it results in undefined behavior.
  666. @par Complexity
  667. Constant.
  668. @par Exception Safety
  669. No-throw guarantee.
  670. */
  671. inline
  672. const_iterator
  673. end() const noexcept;
  674. /** Return a const iterator to the element following the last element.
  675. The element acts as a placeholder; attempting
  676. to access it results in undefined behavior.
  677. @par Complexity
  678. Constant.
  679. @par Exception Safety
  680. No-throw guarantee.
  681. */
  682. inline
  683. const_iterator
  684. cend() const noexcept;
  685. /** Return a reverse iterator to the first element of the reversed container.
  686. The pointed-to element corresponds to the
  687. last element of the non-reversed container.
  688. If the container is empty, @ref rend() is returned.
  689. @par Complexity
  690. Constant.
  691. @par Exception Safety
  692. No-throw guarantee.
  693. */
  694. inline
  695. reverse_iterator
  696. rbegin() noexcept;
  697. /** Return a const reverse iterator to the first element of the reversed container.
  698. The pointed-to element corresponds to the
  699. last element of the non-reversed container.
  700. If the container is empty, @ref rend() is returned.
  701. @par Complexity
  702. Constant.
  703. @par Exception Safety
  704. No-throw guarantee.
  705. */
  706. inline
  707. const_reverse_iterator
  708. rbegin() const noexcept;
  709. /** Return a const reverse iterator to the first element of the reversed container.
  710. The pointed-to element corresponds to the
  711. last element of the non-reversed container.
  712. If the container is empty, @ref crend() is returned.
  713. @par Complexity
  714. Constant.
  715. @par Exception Safety
  716. No-throw guarantee.
  717. */
  718. inline
  719. const_reverse_iterator
  720. crbegin() const noexcept;
  721. /** Return a reverse iterator to the element following the last element of the reversed container.
  722. The pointed-to element corresponds to the element
  723. preceding the first element of the non-reversed container.
  724. The element acts as a placeholder; attempting
  725. to access it results in undefined behavior.
  726. @par Complexity
  727. Constant.
  728. @par Exception Safety
  729. No-throw guarantee.
  730. */
  731. inline
  732. reverse_iterator
  733. rend() noexcept;
  734. /** Return a const reverse iterator to the element following the last element of the reversed container.
  735. The pointed-to element corresponds to the element
  736. preceding the first element of the non-reversed container.
  737. The element acts as a placeholder; attempting
  738. to access it results in undefined behavior.
  739. @par Complexity
  740. Constant.
  741. @par Exception Safety
  742. No-throw guarantee.
  743. */
  744. inline
  745. const_reverse_iterator
  746. rend() const noexcept;
  747. /** Return a const reverse iterator to the element following the last element of the reversed container.
  748. The pointed-to element corresponds to the element
  749. preceding the first element of the non-reversed container.
  750. The element acts as a placeholder; attempting
  751. to access it results in undefined behavior.
  752. @par Complexity
  753. Constant.
  754. @par Exception Safety
  755. No-throw guarantee.
  756. */
  757. inline
  758. const_reverse_iterator
  759. crend() const noexcept;
  760. //------------------------------------------------------
  761. //
  762. // Capacity
  763. //
  764. //------------------------------------------------------
  765. /** Return the number of elements in the array.
  766. This returns the number of elements in the array.
  767. The value returned may be different from the number
  768. returned from @ref capacity.
  769. @par Complexity
  770. Constant.
  771. @par Exception Safety
  772. No-throw guarantee.
  773. */
  774. inline
  775. std::size_t
  776. size() const noexcept;
  777. /** Return the maximum number of elements any array can hold.
  778. The maximum is an implementation-defined number.
  779. This value is a theoretical limit; at runtime,
  780. the actual maximum size may be less due to
  781. resource limits.
  782. @par Complexity
  783. Constant.
  784. @par Exception Safety
  785. No-throw guarantee.
  786. */
  787. static
  788. inline
  789. constexpr
  790. std::size_t
  791. max_size() noexcept;
  792. /** Return the number of elements that can be held in currently allocated memory.
  793. This number may be larger than the value returned
  794. by @ref size().
  795. @par Complexity
  796. Constant.
  797. @par Exception Safety
  798. No-throw guarantee.
  799. */
  800. inline
  801. std::size_t
  802. capacity() const noexcept;
  803. /** Check if the array has no elements.
  804. Returns `true` if there are no elements in the
  805. array, i.e. @ref size() returns 0.
  806. @par Complexity
  807. Constant.
  808. @par Exception Safety
  809. No-throw guarantee.
  810. */
  811. inline
  812. bool
  813. empty() const noexcept;
  814. /** Increase the capacity to at least a certain amount.
  815. This increases the @ref capacity() to a value
  816. that is greater than or equal to `new_capacity`.
  817. If `new_capacity > capacity()`, new memory is
  818. allocated. Otherwise, the call has no effect.
  819. The number of elements and therefore the
  820. @ref size() of the container is not changed.
  821. \n
  822. If new memory is allocated, all iterators
  823. including any past-the-end iterators, and all
  824. references to the elements are invalidated.
  825. Otherwise, no iterators or references are
  826. invalidated.
  827. @par Complexity
  828. At most, linear in @ref size().
  829. @par Exception Safety
  830. Strong guarantee.
  831. Calls to `memory_resource::allocate` may throw.
  832. @param new_capacity The new capacity of the array.
  833. @throw `boost::system::system_error` `new_capacity > max_size()`.
  834. */
  835. inline
  836. void
  837. reserve(std::size_t new_capacity);
  838. /** Request the removal of unused capacity.
  839. This performs a non-binding request to reduce the
  840. capacity to the current size. The request may or
  841. may not be fulfilled. If reallocation occurs, all
  842. iterators including any past-the-end iterators,
  843. and all references to the elements are invalidated.
  844. Otherwise, no iterators or references are
  845. invalidated.
  846. @par Complexity
  847. At most, linear in @ref size().
  848. @par Exception Safety
  849. No-throw guarantee.
  850. */
  851. BOOST_JSON_DECL
  852. void
  853. shrink_to_fit() noexcept;
  854. //------------------------------------------------------
  855. //
  856. // Modifiers
  857. //
  858. //------------------------------------------------------
  859. /** Clear the contents.
  860. Erases all elements from the container. After this
  861. call, @ref size() returns zero but @ref capacity()
  862. is unchanged. All references, pointers, or iterators
  863. referring to contained elements are invalidated. Any
  864. past-the-end iterators are also invalidated.
  865. @par Complexity
  866. Linear in @ref size().
  867. @par Exception Safety
  868. No-throw guarantee.
  869. */
  870. BOOST_JSON_DECL
  871. void
  872. clear() noexcept;
  873. /** Insert elements before the specified location.
  874. This inserts a copy of `v` before `pos`.
  875. If `capacity() < size() + 1`, a reallocation
  876. occurs first, and all iterators and references
  877. are invalidated.
  878. Otherwise, only the iterators and references from
  879. the insertion point forward are invalidated. All
  880. past-the-end iterators are also invalidated.
  881. @par Complexity
  882. Constant plus linear in `std::distance(pos, end())`.
  883. @par Exception Safety
  884. Strong guarantee.
  885. Calls to `memory_resource::allocate` may throw.
  886. @param pos Iterator before which the content will
  887. be inserted. This may be the @ref end() iterator.
  888. @param v The value to insert. A copy will be made
  889. using container's associated `boost::container::pmr::memory_resource`.
  890. @return An iterator to the inserted value
  891. */
  892. BOOST_JSON_DECL
  893. iterator
  894. insert(
  895. const_iterator pos,
  896. value const& v);
  897. /** Insert elements before the specified location.
  898. This inserts `v` before `pos` via move-construction.
  899. If `capacity() < size() + 1`, a reallocation occurs
  900. first, and all iterators and references are
  901. invalidated.
  902. Otherwise, only the iterators and references from
  903. the insertion point forward are invalidated. All
  904. past-the-end iterators are also invalidated.
  905. @par Complexity
  906. Constant plus linear in `std::distance(pos, end())`.
  907. @par Exception Safety
  908. Strong guarantee.
  909. Calls to `memory_resource::allocate` may throw.
  910. @param pos Iterator before which the content will
  911. be inserted. This may be the @ref end() iterator.
  912. @param v The value to insert. Ownership of the
  913. value will be transferred via move construction,
  914. using the container's
  915. associated `boost::container::pmr::memory_resource`.
  916. @return An iterator to the inserted value
  917. */
  918. BOOST_JSON_DECL
  919. iterator
  920. insert(
  921. const_iterator pos,
  922. value&& v);
  923. /** Insert elements before the specified location.
  924. This inserts `count` copies of `v` before `pos`.
  925. If `capacity() < size() + count`, a reallocation
  926. occurs first, and all iterators and references are
  927. invalidated.
  928. Otherwise, only the iterators and references from
  929. the insertion point forward are invalidated. All
  930. past-the-end iterators are also invalidated.
  931. @par Complexity
  932. Linear in `count + std::distance(pos, end())`.
  933. @par Exception Safety
  934. Strong guarantee.
  935. Calls to `memory_resource::allocate` may throw.
  936. @param pos Iterator before which the content will
  937. be inserted. This may be the @ref end() iterator.
  938. @param count The number of copies to insert.
  939. @param v The value to insert. Copies will be made
  940. using the container's
  941. associated `boost::container::pmr::memory_resource`.
  942. @return An iterator to the first inserted value,
  943. or `pos` if `count == 0`.
  944. */
  945. BOOST_JSON_DECL
  946. iterator
  947. insert(
  948. const_iterator pos,
  949. std::size_t count,
  950. value const& v);
  951. /** Insert elements before the specified location.
  952. The elements in the range `{first, last)` are
  953. inserted in order.
  954. If `capacity() < size() + std::distance(first, last)`,
  955. a reallocation occurs first, and all iterators and
  956. references are invalidated.
  957. Otherwise, only the iterators and references from
  958. the insertion point forward are invalidated. All
  959. past-the-end iterators are also invalidated.
  960. @par Precondition
  961. `first` and `last` are not iterators into `*this`.
  962. @par Constraints
  963. @code
  964. not std::is_convertible_v<InputIt, value>
  965. @endcode
  966. @par Mandates
  967. @code
  968. std::is_constructible_v<value, std::iterator_traits<InputIt>::reference>
  969. @endcode
  970. @par Complexity
  971. Linear in `std::distance(first, last) + std::distance(pos, end())`.
  972. @par Exception Safety
  973. Strong guarantee.
  974. Calls to `memory_resource::allocate` may throw.
  975. @return An iterator to the first inserted value, or
  976. `pos` if `first == last`.
  977. @param pos Iterator before which the content will
  978. be inserted. This may be the @ref end() iterator.
  979. @param first An input iterator pointing to the first
  980. element to insert, or pointing to the end of the range.
  981. @param last An input iterator pointing to the end
  982. of the range.
  983. @tparam InputIt a type satisfying the requirements
  984. of __InputIterator__.
  985. */
  986. template<
  987. class InputIt
  988. #ifndef BOOST_JSON_DOCS
  989. ,class = typename std::enable_if<
  990. std::is_constructible<value,
  991. typename std::iterator_traits<
  992. InputIt>::reference>::value>::type
  993. #endif
  994. >
  995. iterator
  996. insert(
  997. const_iterator pos,
  998. InputIt first, InputIt last);
  999. /** Insert elements before the specified location.
  1000. The elements in the initializer list `init` are
  1001. inserted in order.
  1002. If `capacity() < size() + init.size()`,
  1003. a reallocation occurs first, and all iterators and
  1004. references are invalidated.
  1005. Otherwise, only the iterators and references from
  1006. the insertion point forward are invalidated. All
  1007. past-the-end iterators are also invalidated.
  1008. @par Complexity
  1009. Linear in `init.size() + std::distance(pos, end())`.
  1010. @par Exception Safety
  1011. Strong guarantee.
  1012. Calls to `memory_resource::allocate` may throw.
  1013. @param pos Iterator before which the content will
  1014. be inserted. This may be the @ref end() iterator.
  1015. @param init The initializer list to insert
  1016. @return An iterator to the first inserted value, or
  1017. `pos` if `init.size() == 0`.
  1018. */
  1019. BOOST_JSON_DECL
  1020. iterator
  1021. insert(
  1022. const_iterator pos,
  1023. std::initializer_list<value_ref> init);
  1024. /** Insert a constructed element in-place.
  1025. Inserts a new element into the container directly before
  1026. `pos`. The element is constructed using placement-new
  1027. with the parameter `std::forward<Arg>(arg)`.
  1028. If `capacity() < size() + 1`,
  1029. a reallocation occurs first, and all iterators and
  1030. references are invalidated.
  1031. Otherwise, only the iterators and references from
  1032. the insertion point forward are invalidated. All
  1033. past-the-end iterators are also invalidated.
  1034. @par Complexity
  1035. Constant plus linear in `std::distance(pos, end())`.
  1036. @par Exception Safety
  1037. Strong guarantee.
  1038. Calls to `memory_resource::allocate` may throw.
  1039. @param pos Iterator before which the element will
  1040. be inserted. This may be the @ref end() iterator.
  1041. @param arg The argument to forward to the @ref value
  1042. constructor.
  1043. @return An iterator to the inserted element
  1044. */
  1045. template<class Arg>
  1046. iterator
  1047. emplace(
  1048. const_iterator pos,
  1049. Arg&& arg);
  1050. /** Erase elements from the container.
  1051. The element at `pos` is removed.
  1052. @par Complexity
  1053. Constant plus linear in `std::distance(pos, end())`
  1054. @par Exception Safety
  1055. No-throw guarantee.
  1056. @param pos Iterator to the element to remove
  1057. @return Iterator following the last removed element.
  1058. If the iterator `pos` refers to the last element,
  1059. the @ref end() iterator is returned.
  1060. */
  1061. BOOST_JSON_DECL
  1062. iterator
  1063. erase(const_iterator pos) noexcept;
  1064. /** Erase elements from the container.
  1065. The elements in the range `{first, last)` are removed.
  1066. @par Complexity
  1067. Linear in `std::distance(first, end())`
  1068. @par Exception Safety
  1069. No-throw guarantee.
  1070. @param first An iterator pointing to the first
  1071. element to erase, or pointing to the end of the range.
  1072. @param last An iterator pointing to one past the
  1073. last element to erase, or pointing to the end of the
  1074. range.
  1075. @return Iterator following the last removed element.
  1076. If the iterator `last` refers to the last element,
  1077. the @ref end() iterator is returned.
  1078. */
  1079. BOOST_JSON_DECL
  1080. iterator
  1081. erase(
  1082. const_iterator first,
  1083. const_iterator last) noexcept;
  1084. /** Add an element to the end.
  1085. This appends a copy of `v` to the container's
  1086. elements.
  1087. If `capacity() < size() + 1`, a reallocation
  1088. occurs first, and all iterators and references
  1089. are invalidated. Any past-the-end iterators are
  1090. always invalidated.
  1091. @par Complexity
  1092. Amortized constant.
  1093. @par Exception Safety
  1094. Strong guarantee.
  1095. Calls to `memory_resource::allocate` may throw.
  1096. @param v The value to insert. A copy will be made using the container's
  1097. associated `boost::container::pmr::memory_resource`.
  1098. */
  1099. BOOST_JSON_DECL
  1100. void
  1101. push_back(value const& v);
  1102. /** Add an element to the end.
  1103. This appends `v` to the container's elements via
  1104. move-construction.
  1105. If `capacity() < size() + 1`, a reallocation
  1106. occurs first, and all iterators and references
  1107. are invalidated. Any past-the-end iterators are
  1108. always invalidated.
  1109. @par Complexity
  1110. Amortized constant.
  1111. @par Exception Safety
  1112. Strong guarantee.
  1113. Calls to `memory_resource::allocate` may throw.
  1114. @param v The value to insert. Ownership of the value will be
  1115. transferred via move construction, using the container's
  1116. associated `boost::container::pmr::memory_resource`.
  1117. */
  1118. BOOST_JSON_DECL
  1119. void
  1120. push_back(value&& v);
  1121. /** Append a constructed element in-place.
  1122. Appends a new element to the end of the container's
  1123. list of elements.
  1124. The element is constructed using placement-new
  1125. with the parameter `std::forward<Arg>(arg)`.
  1126. If `capacity() < size() + 1`,
  1127. a reallocation occurs first, and all iterators and
  1128. references are invalidated.
  1129. Otherwise, only the iterators and references from
  1130. the insertion point forward are invalidated. All
  1131. past-the-end iterators are also invalidated.
  1132. @par Complexity
  1133. Amortized constant.
  1134. @par Exception Safety
  1135. Strong guarantee.
  1136. Calls to `memory_resource::allocate` may throw.
  1137. @param arg The argument to forward to the @ref value
  1138. constructor.
  1139. @return A reference to the inserted element
  1140. */
  1141. template<class Arg>
  1142. value&
  1143. emplace_back(Arg&& arg);
  1144. /** Remove the last element
  1145. The last element of the container is erased.
  1146. @par Precondition
  1147. `not empty()`
  1148. @par Exception Safety
  1149. No-throw guarantee.
  1150. */
  1151. BOOST_JSON_DECL
  1152. void
  1153. pop_back() noexcept;
  1154. /** Change the number of elements stored.
  1155. Resizes the container to contain `count` elements.
  1156. If `capacity() < size() + count`, a reallocation
  1157. occurs first, and all iterators and references
  1158. are invalidated. Any past-the-end iterators are
  1159. always invalidated.
  1160. @li If `size() > count`, the container is reduced
  1161. to its first `count` elements.
  1162. @li If `size() < count`, additional null values
  1163. are appended.
  1164. @par Complexity
  1165. Linear in `abs(size() - count)`, plus the cost of
  1166. reallocation if @ref capacity() is less than `count`.
  1167. @par Exception Safety
  1168. Strong guarantee.
  1169. Calls to `memory_resource::allocate` may throw.
  1170. @param count The new size of the container.
  1171. */
  1172. BOOST_JSON_DECL
  1173. void
  1174. resize(std::size_t count);
  1175. /** Change the number of elements stored.
  1176. Resizes the container to contain `count` elements.
  1177. If `capacity() < size() + count`, a reallocation
  1178. occurs first, and all iterators and references
  1179. are invalidated. Any past-the-end iterators are
  1180. always invalidated.
  1181. @li If `size() > count`, the container is reduced
  1182. to its first `count` elements.
  1183. @li If `size() < count`, additional copies of `v`
  1184. are appended.
  1185. @par Complexity
  1186. Linear in `abs(size() - count)`, plus the cost of
  1187. reallocation if @ref capacity() is less than `count`.
  1188. @par Exception Safety
  1189. Strong guarantee.
  1190. Calls to `memory_resource::allocate` may throw.
  1191. @param count The new size of the container.
  1192. @param v The @ref value to copy into the new elements.
  1193. */
  1194. BOOST_JSON_DECL
  1195. void
  1196. resize(
  1197. std::size_t count,
  1198. value const& v);
  1199. /** Swap the contents.
  1200. Exchanges the contents of this array with another
  1201. array. Ownership of the respective
  1202. `boost::container::pmr::memory_resource` objects is not transferred.
  1203. @li If `*other.storage() == *this->storage()`,
  1204. ownership of the underlying memory is swapped in
  1205. constant time, with no possibility of exceptions.
  1206. All iterators and references remain valid.
  1207. @li If `*other.storage() != *this->storage()`,
  1208. the contents are logically swapped by making copies,
  1209. which can throw. In this case all iterators and
  1210. references are invalidated.
  1211. @par Complexity
  1212. Constant or linear in @ref size() plus `other.size()`.
  1213. @par Exception Safety
  1214. Strong guarantee.
  1215. Calls to `memory_resource::allocate` may throw.
  1216. @param other The value to swap with.
  1217. If `this == &other`, this function call has no effect.
  1218. */
  1219. BOOST_JSON_DECL
  1220. void
  1221. swap(array& other);
  1222. /** Exchange the given values.
  1223. Exchanges the contents of the array `lhs` with another array `rhs`.
  1224. Ownership of the respective `boost::container::pmr::memory_resource`
  1225. objects is not transferred.
  1226. @li If `*lhs.storage() == *rhs.storage()`,
  1227. ownership of the underlying memory is swapped in
  1228. constant time, with no possibility of exceptions.
  1229. All iterators and references remain valid.
  1230. @li If `*lhs.storage() != *rhs.storage()`,
  1231. the contents are logically swapped by making a copy,
  1232. which can throw. In this case all iterators and
  1233. references are invalidated.
  1234. @par Effects
  1235. @code
  1236. lhs.swap( rhs );
  1237. @endcode
  1238. @par Complexity
  1239. Constant or linear in `lhs.size() + rhs.size()`.
  1240. @par Exception Safety
  1241. Strong guarantee.
  1242. Calls to `memory_resource::allocate` may throw.
  1243. @param lhs The array to exchange.
  1244. @param rhs The array to exchange.
  1245. If `&lhs == &rhs`, this function call has no effect.
  1246. @see @ref array::swap
  1247. */
  1248. friend
  1249. void
  1250. swap(array& lhs, array& rhs)
  1251. {
  1252. lhs.swap(rhs);
  1253. }
  1254. /** Return `true` if two arrays are equal.
  1255. Arrays are equal when their sizes are
  1256. the same, and they are element-for-element
  1257. equal in order.
  1258. @par Effects
  1259. `return std::equal( lhs.begin(), lhs.end(), rhs.begin(), rhs.end() );`
  1260. @par Complexity
  1261. Constant or linear in `lhs.size()`.
  1262. @par Exception Safety
  1263. No-throw guarantee.
  1264. */
  1265. // inline friend speeds up overload resolution
  1266. friend
  1267. bool
  1268. operator==(
  1269. array const& lhs,
  1270. array const& rhs) noexcept
  1271. {
  1272. return lhs.equal(rhs);
  1273. }
  1274. /** Return `true` if two arrays are not equal.
  1275. Arrays are equal when their sizes are
  1276. the same, and they are element-for-element
  1277. equal in order.
  1278. @par Effects
  1279. `return ! std::equal( lhs.begin(), lhs.end(), rhs.begin(), rhs.end() );`
  1280. @par Complexity
  1281. Constant or linear in `lhs.size()`.
  1282. @par Exception Safety
  1283. No-throw guarantee.
  1284. */
  1285. // inline friend speeds up overload resolution
  1286. friend
  1287. bool
  1288. operator!=(
  1289. array const& lhs,
  1290. array const& rhs) noexcept
  1291. {
  1292. return ! (lhs == rhs);
  1293. }
  1294. /** Serialize @ref array to an output stream.
  1295. This function serializes an `array` as JSON into the output stream.
  1296. @return Reference to `os`.
  1297. @par Complexity
  1298. Constant or linear in the size of `arr`.
  1299. @par Exception Safety
  1300. Strong guarantee.
  1301. Calls to `memory_resource::allocate` may throw.
  1302. @param os The output stream to serialize to.
  1303. @param arr The value to serialize.
  1304. */
  1305. BOOST_JSON_DECL
  1306. friend
  1307. std::ostream&
  1308. operator<<(
  1309. std::ostream& os,
  1310. array const& arr);
  1311. private:
  1312. template<class It>
  1313. using iter_cat = typename
  1314. std::iterator_traits<It>::iterator_category;
  1315. template<class InputIt>
  1316. array(
  1317. InputIt first, InputIt last,
  1318. storage_ptr sp,
  1319. std::input_iterator_tag);
  1320. template<class InputIt>
  1321. array(
  1322. InputIt first, InputIt last,
  1323. storage_ptr sp,
  1324. std::forward_iterator_tag);
  1325. inline
  1326. std::size_t
  1327. growth(std::size_t new_size) const;
  1328. BOOST_JSON_DECL
  1329. void
  1330. reserve_impl(
  1331. std::size_t new_capacity);
  1332. BOOST_JSON_DECL
  1333. value&
  1334. push_back(
  1335. pilfered<value> pv);
  1336. BOOST_JSON_DECL
  1337. iterator
  1338. insert(
  1339. const_iterator pos,
  1340. pilfered<value> pv);
  1341. template<class InputIt>
  1342. iterator
  1343. insert(
  1344. const_iterator pos,
  1345. InputIt first, InputIt last,
  1346. std::input_iterator_tag);
  1347. template<class InputIt>
  1348. iterator
  1349. insert(
  1350. const_iterator pos,
  1351. InputIt first, InputIt last,
  1352. std::forward_iterator_tag);
  1353. BOOST_JSON_DECL
  1354. bool
  1355. equal(array const& other) const noexcept;
  1356. };
  1357. } // namespace json
  1358. } // namespace boost
  1359. // std::hash specialization
  1360. #ifndef BOOST_JSON_DOCS
  1361. namespace std {
  1362. template <>
  1363. struct hash< ::boost::json::array > {
  1364. BOOST_JSON_DECL
  1365. std::size_t
  1366. operator()(::boost::json::array const& ja) const noexcept;
  1367. };
  1368. } // std
  1369. #endif
  1370. // Must be included here for this file to stand alone
  1371. #include <boost/json/value.hpp>
  1372. // includes are at the bottom of <boost/json/value.hpp>
  1373. #endif