array.hpp 48 KB

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