array.hpp 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766
  1. //
  2. // Copyright (c) 2019 Vinnie Falco ([email protected])
  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. /** Associated [Allocator](https://en.cppreference.com/w/cpp/named_req/Allocator)
  101. This type is `boost::container::pmr::polymorphic_allocator<value>`.
  102. */
  103. #ifdef BOOST_JSON_DOCS
  104. using allocator_type = __see_below__;
  105. #else
  106. // VFALCO doc toolchain renders this incorrectly
  107. using allocator_type = container::pmr::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 `boost::container::pmr::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 `boost::container::pmr::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 `boost::container::pmr::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 `boost::container::pmr::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 `boost::container::pmr::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 `boost::container::pmr::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 `boost::container::pmr::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 `boost::container::pmr::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 memory resource.
  422. This function returns the `boost::container::pmr::memory_resource` used
  423. by 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 allocator.
  435. This function returns an instance of @ref allocator_type constructed
  436. from the associated `boost::container::pmr::memory_resource`.
  437. @par Complexity
  438. Constant.
  439. @par Exception Safety
  440. No-throw guarantee.
  441. */
  442. allocator_type
  443. get_allocator() const noexcept
  444. {
  445. return sp_.get();
  446. }
  447. //------------------------------------------------------
  448. //
  449. // Element access
  450. //
  451. //------------------------------------------------------
  452. /** Access an element, with bounds checking.
  453. Returns a reference to the element specified at
  454. location `pos`, with bounds checking. If `pos` is
  455. not within the range of the container, an exception
  456. of type `boost::system::system_error` is thrown.
  457. @par Complexity
  458. Constant.
  459. @param pos A zero-based index.
  460. @throw `boost::system::system_error` `pos >= size()`.
  461. */
  462. /* @{ */
  463. inline
  464. value&
  465. at(std::size_t pos) &;
  466. inline
  467. value&&
  468. at(std::size_t pos) &&;
  469. inline
  470. value const&
  471. at(std::size_t pos) const&;
  472. /* @} */
  473. /** Access an element.
  474. Returns a reference to the element specified at
  475. location `pos`. No bounds checking is performed.
  476. @par Precondition
  477. `pos < size()`
  478. @par Complexity
  479. Constant.
  480. @param pos A zero-based index
  481. */
  482. /* @{ */
  483. inline
  484. value&
  485. operator[](std::size_t pos) & noexcept;
  486. inline
  487. value&&
  488. operator[](std::size_t pos) && noexcept;
  489. inline
  490. value const&
  491. operator[](std::size_t pos) const& noexcept;
  492. /* @} */
  493. /** Access the first element.
  494. Returns a reference to the first element.
  495. @par Precondition
  496. `not empty()`
  497. @par Complexity
  498. Constant.
  499. */
  500. /* @{ */
  501. inline
  502. value&
  503. front() & noexcept;
  504. inline
  505. value&&
  506. front() && noexcept;
  507. inline
  508. value const&
  509. front() const& noexcept;
  510. /* @} */
  511. /** Access the last element.
  512. Returns a reference to the last element.
  513. @par Precondition
  514. `not empty()`
  515. @par Complexity
  516. Constant.
  517. */
  518. /* @{ */
  519. inline
  520. value&
  521. back() & noexcept;
  522. inline
  523. value&&
  524. back() && noexcept;
  525. inline
  526. value const&
  527. back() const& noexcept;
  528. /* @} */
  529. /** Access the underlying array directly.
  530. Returns a pointer to the underlying array serving
  531. as element storage. The value returned is such that
  532. the range `{data(), data() + size())` is always a
  533. valid range, even if the container is empty.
  534. @par Complexity
  535. Constant.
  536. @par Exception Safety
  537. No-throw guarantee.
  538. @note
  539. If `size() == 0`, the function may or may not return
  540. a null pointer.
  541. */
  542. inline
  543. value*
  544. data() noexcept;
  545. /** Access the underlying array directly.
  546. Returns a pointer to the underlying array serving
  547. as element storage. The value returned is such that
  548. the range `{data(), data() + size())` is always a
  549. valid range, even if the container is empty.
  550. @par Complexity
  551. Constant.
  552. @par Exception Safety
  553. No-throw guarantee.
  554. @note
  555. If `size() == 0`, the function may or may not return
  556. a null pointer.
  557. */
  558. inline
  559. value const*
  560. data() const noexcept;
  561. /** Return a pointer to an element, or nullptr if the index is invalid
  562. This function returns a pointer to the element
  563. at index `pos` when the index is less then the size
  564. of the container. Otherwise it returns null.
  565. @par Example
  566. @code
  567. if( auto p = arr.if_contains( 1 ) )
  568. std::cout << *p;
  569. @endcode
  570. @par Complexity
  571. Constant.
  572. @par Exception Safety
  573. No-throw guarantee.
  574. @param pos The index of the element to return.
  575. */
  576. inline
  577. value const*
  578. if_contains(std::size_t pos) const noexcept;
  579. /** Return a pointer to an element, or nullptr if the index is invalid
  580. This function returns a pointer to the element
  581. at index `pos` when the index is less then the size
  582. of the container. Otherwise it returns null.
  583. @par Example
  584. @code
  585. if( auto p = arr.if_contains( 1 ) )
  586. std::cout << *p;
  587. @endcode
  588. @par Complexity
  589. Constant.
  590. @par Exception Safety
  591. No-throw guarantee.
  592. @param pos The index of the element to return.
  593. */
  594. inline
  595. value*
  596. if_contains(std::size_t pos) noexcept;
  597. //------------------------------------------------------
  598. //
  599. // Iterators
  600. //
  601. //------------------------------------------------------
  602. /** Return an iterator to the first element.
  603. If the container is empty, @ref end() is returned.
  604. @par Complexity
  605. Constant.
  606. @par Exception Safety
  607. No-throw guarantee.
  608. */
  609. inline
  610. iterator
  611. begin() noexcept;
  612. /** Return a const iterator to the first element.
  613. If the container is empty, @ref end() is returned.
  614. @par Complexity
  615. Constant.
  616. @par Exception Safety
  617. No-throw guarantee.
  618. */
  619. inline
  620. const_iterator
  621. begin() const noexcept;
  622. /** Return a const iterator to the first element.
  623. If the container is empty, @ref cend() is returned.
  624. @par Complexity
  625. Constant.
  626. @par Exception Safety
  627. No-throw guarantee.
  628. */
  629. inline
  630. const_iterator
  631. cbegin() const noexcept;
  632. /** Return an iterator to the element following the last element.
  633. The element acts as a placeholder; attempting
  634. to access it results in undefined behavior.
  635. @par Complexity
  636. Constant.
  637. @par Exception Safety
  638. No-throw guarantee.
  639. */
  640. inline
  641. iterator
  642. end() noexcept;
  643. /** Return a const iterator to the element following the last element.
  644. The element acts as a placeholder; attempting
  645. to access it results in undefined behavior.
  646. @par Complexity
  647. Constant.
  648. @par Exception Safety
  649. No-throw guarantee.
  650. */
  651. inline
  652. const_iterator
  653. end() const noexcept;
  654. /** Return a const iterator to the element following the last element.
  655. The element acts as a placeholder; attempting
  656. to access it results in undefined behavior.
  657. @par Complexity
  658. Constant.
  659. @par Exception Safety
  660. No-throw guarantee.
  661. */
  662. inline
  663. const_iterator
  664. cend() const noexcept;
  665. /** Return a reverse iterator to the first element of the reversed container.
  666. The pointed-to element corresponds to the
  667. last element of the non-reversed container.
  668. If the container is empty, @ref rend() is returned.
  669. @par Complexity
  670. Constant.
  671. @par Exception Safety
  672. No-throw guarantee.
  673. */
  674. inline
  675. reverse_iterator
  676. rbegin() noexcept;
  677. /** Return a const reverse iterator to the first element of the reversed container.
  678. The pointed-to element corresponds to the
  679. last element of the non-reversed container.
  680. If the container is empty, @ref rend() is returned.
  681. @par Complexity
  682. Constant.
  683. @par Exception Safety
  684. No-throw guarantee.
  685. */
  686. inline
  687. const_reverse_iterator
  688. rbegin() const noexcept;
  689. /** Return a const reverse iterator to the first element of the reversed container.
  690. The pointed-to element corresponds to the
  691. last element of the non-reversed container.
  692. If the container is empty, @ref crend() is returned.
  693. @par Complexity
  694. Constant.
  695. @par Exception Safety
  696. No-throw guarantee.
  697. */
  698. inline
  699. const_reverse_iterator
  700. crbegin() const noexcept;
  701. /** Return a reverse iterator to the element following the last element of the reversed container.
  702. The pointed-to element corresponds to the element
  703. preceding the first element of the non-reversed container.
  704. The element acts as a placeholder; attempting
  705. to access it results in undefined behavior.
  706. @par Complexity
  707. Constant.
  708. @par Exception Safety
  709. No-throw guarantee.
  710. */
  711. inline
  712. reverse_iterator
  713. rend() noexcept;
  714. /** Return a const reverse iterator to the element following the last element of the reversed container.
  715. The pointed-to element corresponds to the element
  716. preceding the first element of the non-reversed container.
  717. The element acts as a placeholder; attempting
  718. to access it results in undefined behavior.
  719. @par Complexity
  720. Constant.
  721. @par Exception Safety
  722. No-throw guarantee.
  723. */
  724. inline
  725. const_reverse_iterator
  726. rend() const noexcept;
  727. /** Return a const reverse iterator to the element following the last element of the reversed container.
  728. The pointed-to element corresponds to the element
  729. preceding the first element of the non-reversed container.
  730. The element acts as a placeholder; attempting
  731. to access it results in undefined behavior.
  732. @par Complexity
  733. Constant.
  734. @par Exception Safety
  735. No-throw guarantee.
  736. */
  737. inline
  738. const_reverse_iterator
  739. crend() const noexcept;
  740. //------------------------------------------------------
  741. //
  742. // Capacity
  743. //
  744. //------------------------------------------------------
  745. /** Return the number of elements in the array.
  746. This returns the number of elements in the array.
  747. The value returned may be different from the number
  748. returned from @ref capacity.
  749. @par Complexity
  750. Constant.
  751. @par Exception Safety
  752. No-throw guarantee.
  753. */
  754. inline
  755. std::size_t
  756. size() const noexcept;
  757. /** Return the maximum number of elements any array can hold.
  758. The maximum is an implementation-defined number.
  759. This value is a theoretical limit; at runtime,
  760. the actual maximum size may be less due to
  761. resource limits.
  762. @par Complexity
  763. Constant.
  764. @par Exception Safety
  765. No-throw guarantee.
  766. */
  767. static
  768. inline
  769. constexpr
  770. std::size_t
  771. max_size() noexcept;
  772. /** Return the number of elements that can be held in currently allocated memory.
  773. This number may be larger than the value returned
  774. by @ref size().
  775. @par Complexity
  776. Constant.
  777. @par Exception Safety
  778. No-throw guarantee.
  779. */
  780. inline
  781. std::size_t
  782. capacity() const noexcept;
  783. /** Check if the array has no elements.
  784. Returns `true` if there are no elements in the
  785. array, i.e. @ref size() returns 0.
  786. @par Complexity
  787. Constant.
  788. @par Exception Safety
  789. No-throw guarantee.
  790. */
  791. inline
  792. bool
  793. empty() const noexcept;
  794. /** Increase the capacity to at least a certain amount.
  795. This increases the @ref capacity() to a value
  796. that is greater than or equal to `new_capacity`.
  797. If `new_capacity > capacity()`, new memory is
  798. allocated. Otherwise, the call has no effect.
  799. The number of elements and therefore the
  800. @ref size() of the container is not changed.
  801. \n
  802. If new memory is allocated, all iterators
  803. including any past-the-end iterators, and all
  804. references to the elements are invalidated.
  805. Otherwise, no iterators or references are
  806. invalidated.
  807. @par Complexity
  808. At most, linear in @ref size().
  809. @par Exception Safety
  810. Strong guarantee.
  811. Calls to `memory_resource::allocate` may throw.
  812. @param new_capacity The new capacity of the array.
  813. @throw `boost::system::system_error` `new_capacity > max_size()`.
  814. */
  815. inline
  816. void
  817. reserve(std::size_t new_capacity);
  818. /** Request the removal of unused capacity.
  819. This performs a non-binding request to reduce the
  820. capacity to the current size. The request may or
  821. may not be fulfilled. If reallocation occurs, all
  822. iterators including any past-the-end iterators,
  823. and all references to the elements are invalidated.
  824. Otherwise, no iterators or references are
  825. invalidated.
  826. @par Complexity
  827. At most, linear in @ref size().
  828. @par Exception Safety
  829. No-throw guarantee.
  830. */
  831. BOOST_JSON_DECL
  832. void
  833. shrink_to_fit() noexcept;
  834. //------------------------------------------------------
  835. //
  836. // Modifiers
  837. //
  838. //------------------------------------------------------
  839. /** Clear the contents.
  840. Erases all elements from the container. After this
  841. call, @ref size() returns zero but @ref capacity()
  842. is unchanged. All references, pointers, or iterators
  843. referring to contained elements are invalidated. Any
  844. past-the-end iterators are also invalidated.
  845. @par Complexity
  846. Linear in @ref size().
  847. @par Exception Safety
  848. No-throw guarantee.
  849. */
  850. BOOST_JSON_DECL
  851. void
  852. clear() noexcept;
  853. /** Insert elements before the specified location.
  854. This inserts a copy of `v` before `pos`.
  855. If `capacity() < size() + 1`, a reallocation
  856. occurs first, and all iterators and references
  857. are invalidated.
  858. Otherwise, only the iterators and references from
  859. the insertion point forward are invalidated. All
  860. past-the-end iterators are also invalidated.
  861. @par Complexity
  862. Constant plus linear in `std::distance(pos, end())`.
  863. @par Exception Safety
  864. Strong guarantee.
  865. Calls to `memory_resource::allocate` may throw.
  866. @param pos Iterator before which the content will
  867. be inserted. This may be the @ref end() iterator.
  868. @param v The value to insert. A copy will be made
  869. using container's associated `boost::container::pmr::memory_resource`.
  870. @return An iterator to the inserted value
  871. */
  872. BOOST_JSON_DECL
  873. iterator
  874. insert(
  875. const_iterator pos,
  876. value const& v);
  877. /** Insert elements before the specified location.
  878. This inserts `v` before `pos` via move-construction.
  879. If `capacity() < size() + 1`, a reallocation occurs
  880. first, and all iterators and references are
  881. invalidated.
  882. Otherwise, only the iterators and references from
  883. the insertion point forward are invalidated. All
  884. past-the-end iterators are also invalidated.
  885. @par Complexity
  886. Constant plus linear in `std::distance(pos, end())`.
  887. @par Exception Safety
  888. Strong guarantee.
  889. Calls to `memory_resource::allocate` may throw.
  890. @param pos Iterator before which the content will
  891. be inserted. This may be the @ref end() iterator.
  892. @param v The value to insert. Ownership of the
  893. value will be transferred via move construction,
  894. using the container's
  895. associated `boost::container::pmr::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 the container's
  921. associated `boost::container::pmr::memory_resource`.
  922. @return An iterator to the first inserted value,
  923. or `pos` if `count == 0`.
  924. */
  925. BOOST_JSON_DECL
  926. iterator
  927. insert(
  928. const_iterator pos,
  929. std::size_t count,
  930. value const& v);
  931. /** Insert elements before the specified location.
  932. The elements in the range `{first, last)` are
  933. inserted in order.
  934. If `capacity() < size() + std::distance(first, last)`,
  935. a reallocation occurs first, and all iterators and
  936. references are invalidated.
  937. Otherwise, only the iterators and references from
  938. the insertion point forward are invalidated. All
  939. past-the-end iterators are also invalidated.
  940. @par Precondition
  941. `first` and `last` are not iterators into `*this`.
  942. @par Constraints
  943. @code
  944. not std::is_convertible_v<InputIt, value>
  945. @endcode
  946. @par Mandates
  947. @code
  948. std::is_constructible_v<value, std::iterator_traits<InputIt>::reference>
  949. @endcode
  950. @par Complexity
  951. Linear in `std::distance(first, last) + std::distance(pos, end())`.
  952. @par Exception Safety
  953. Strong guarantee.
  954. Calls to `memory_resource::allocate` may throw.
  955. @return An iterator to the first inserted value, or
  956. `pos` if `first == last`.
  957. @param pos Iterator before which the content will
  958. be inserted. This may be the @ref end() iterator.
  959. @param first An input iterator pointing to the first
  960. element to insert, or pointing to the end of the range.
  961. @param last An input iterator pointing to the end
  962. of the range.
  963. @tparam InputIt a type satisfying the requirements
  964. of __InputIterator__.
  965. */
  966. template<
  967. class InputIt
  968. #ifndef BOOST_JSON_DOCS
  969. ,class = typename std::enable_if<
  970. std::is_constructible<value,
  971. typename std::iterator_traits<
  972. InputIt>::reference>::value>::type
  973. #endif
  974. >
  975. iterator
  976. insert(
  977. const_iterator pos,
  978. InputIt first, InputIt last);
  979. /** Insert elements before the specified location.
  980. The elements in the initializer list `init` are
  981. inserted in order.
  982. If `capacity() < size() + init.size()`,
  983. a reallocation occurs first, and all iterators and
  984. references are invalidated.
  985. Otherwise, only the iterators and references from
  986. the insertion point forward are invalidated. All
  987. past-the-end iterators are also invalidated.
  988. @par Complexity
  989. Linear in `init.size() + std::distance(pos, end())`.
  990. @par Exception Safety
  991. Strong guarantee.
  992. Calls to `memory_resource::allocate` may throw.
  993. @param pos Iterator before which the content will
  994. be inserted. This may be the @ref end() iterator.
  995. @param init The initializer list to insert
  996. @return An iterator to the first inserted value, or
  997. `pos` if `init.size() == 0`.
  998. */
  999. BOOST_JSON_DECL
  1000. iterator
  1001. insert(
  1002. const_iterator pos,
  1003. std::initializer_list<value_ref> init);
  1004. /** Insert a constructed element in-place.
  1005. Inserts a new element into the container directly before
  1006. `pos`. The element is constructed using placement-new
  1007. with the parameter `std::forward<Arg>(arg)`.
  1008. If `capacity() < size() + 1`,
  1009. a reallocation occurs first, and all iterators and
  1010. references are invalidated.
  1011. Otherwise, only the iterators and references from
  1012. the insertion point forward are invalidated. All
  1013. past-the-end iterators are also invalidated.
  1014. @par Complexity
  1015. Constant plus linear in `std::distance(pos, end())`.
  1016. @par Exception Safety
  1017. Strong guarantee.
  1018. Calls to `memory_resource::allocate` may throw.
  1019. @param pos Iterator before which the element will
  1020. be inserted. This may be the @ref end() iterator.
  1021. @param arg The argument to forward to the @ref value
  1022. constructor.
  1023. @return An iterator to the inserted element
  1024. */
  1025. template<class Arg>
  1026. iterator
  1027. emplace(
  1028. const_iterator pos,
  1029. Arg&& arg);
  1030. /** Erase elements from the container.
  1031. The element at `pos` is removed.
  1032. @par Complexity
  1033. Constant plus linear in `std::distance(pos, end())`
  1034. @par Exception Safety
  1035. No-throw guarantee.
  1036. @param pos Iterator to the element to remove
  1037. @return Iterator following the last removed element.
  1038. If the iterator `pos` refers to the last element,
  1039. the @ref end() iterator is returned.
  1040. */
  1041. BOOST_JSON_DECL
  1042. iterator
  1043. erase(const_iterator pos) noexcept;
  1044. /** Erase elements from the container.
  1045. The elements in the range `{first, last)` are removed.
  1046. @par Complexity
  1047. Linear in `std::distance(first, end())`
  1048. @par Exception Safety
  1049. No-throw guarantee.
  1050. @param first An iterator pointing to the first
  1051. element to erase, or pointing to the end of the range.
  1052. @param last An iterator pointing to one past the
  1053. last element to erase, or pointing to the end of the
  1054. range.
  1055. @return Iterator following the last removed element.
  1056. If the iterator `last` refers to the last element,
  1057. the @ref end() iterator is returned.
  1058. */
  1059. BOOST_JSON_DECL
  1060. iterator
  1061. erase(
  1062. const_iterator first,
  1063. const_iterator last) noexcept;
  1064. /** Add an element to the end.
  1065. This appends a copy of `v` to the container's
  1066. elements.
  1067. If `capacity() < size() + 1`, a reallocation
  1068. occurs first, and all iterators and references
  1069. are invalidated. Any past-the-end iterators are
  1070. always invalidated.
  1071. @par Complexity
  1072. Amortized constant.
  1073. @par Exception Safety
  1074. Strong guarantee.
  1075. Calls to `memory_resource::allocate` may throw.
  1076. @param v The value to insert. A copy will be made using the container's
  1077. associated `boost::container::pmr::memory_resource`.
  1078. */
  1079. BOOST_JSON_DECL
  1080. void
  1081. push_back(value const& v);
  1082. /** Add an element to the end.
  1083. This appends `v` to the container's elements via
  1084. move-construction.
  1085. If `capacity() < size() + 1`, a reallocation
  1086. occurs first, and all iterators and references
  1087. are invalidated. Any past-the-end iterators are
  1088. always invalidated.
  1089. @par Complexity
  1090. Amortized constant.
  1091. @par Exception Safety
  1092. Strong guarantee.
  1093. Calls to `memory_resource::allocate` may throw.
  1094. @param v The value to insert. Ownership of the value will be
  1095. transferred via move construction, using the container's
  1096. associated `boost::container::pmr::memory_resource`.
  1097. */
  1098. BOOST_JSON_DECL
  1099. void
  1100. push_back(value&& v);
  1101. /** Append a constructed element in-place.
  1102. Appends a new element to the end of the container's
  1103. list of elements.
  1104. The element is constructed using placement-new
  1105. with the parameter `std::forward<Arg>(arg)`.
  1106. If `capacity() < size() + 1`,
  1107. a reallocation occurs first, and all iterators and
  1108. references are invalidated.
  1109. Otherwise, only the iterators and references from
  1110. the insertion point forward are invalidated. All
  1111. past-the-end iterators are also invalidated.
  1112. @par Complexity
  1113. Amortized constant.
  1114. @par Exception Safety
  1115. Strong guarantee.
  1116. Calls to `memory_resource::allocate` may throw.
  1117. @param arg The argument to forward to the @ref value
  1118. constructor.
  1119. @return A reference to the inserted element
  1120. */
  1121. template<class Arg>
  1122. value&
  1123. emplace_back(Arg&& arg);
  1124. /** Remove the last element
  1125. The last element of the container is erased.
  1126. @par Precondition
  1127. `not empty()`
  1128. @par Exception Safety
  1129. No-throw guarantee.
  1130. */
  1131. BOOST_JSON_DECL
  1132. void
  1133. pop_back() noexcept;
  1134. /** Change the number of elements stored.
  1135. Resizes the container to contain `count` elements.
  1136. If `capacity() < size() + count`, a reallocation
  1137. occurs first, and all iterators and references
  1138. are invalidated. Any past-the-end iterators are
  1139. always invalidated.
  1140. @li If `size() > count`, the container is reduced
  1141. to its first `count` elements.
  1142. @li If `size() < count`, additional null values
  1143. are appended.
  1144. @par Complexity
  1145. Linear in `abs(size() - count)`, plus the cost of
  1146. reallocation if @ref capacity() is less than `count`.
  1147. @par Exception Safety
  1148. Strong guarantee.
  1149. Calls to `memory_resource::allocate` may throw.
  1150. @param count The new size of the container.
  1151. */
  1152. BOOST_JSON_DECL
  1153. void
  1154. resize(std::size_t count);
  1155. /** Change the number of elements stored.
  1156. Resizes the container to contain `count` elements.
  1157. If `capacity() < size() + count`, a reallocation
  1158. occurs first, and all iterators and references
  1159. are invalidated. Any past-the-end iterators are
  1160. always invalidated.
  1161. @li If `size() > count`, the container is reduced
  1162. to its first `count` elements.
  1163. @li If `size() < count`, additional copies of `v`
  1164. are appended.
  1165. @par Complexity
  1166. Linear in `abs(size() - count)`, plus the cost of
  1167. reallocation if @ref capacity() is less than `count`.
  1168. @par Exception Safety
  1169. Strong guarantee.
  1170. Calls to `memory_resource::allocate` may throw.
  1171. @param count The new size of the container.
  1172. @param v The @ref value to copy into the new elements.
  1173. */
  1174. BOOST_JSON_DECL
  1175. void
  1176. resize(
  1177. std::size_t count,
  1178. value const& v);
  1179. /** Swap the contents.
  1180. Exchanges the contents of this array with another
  1181. array. Ownership of the respective
  1182. `boost::container::pmr::memory_resource` objects is not transferred.
  1183. @li If `*other.storage() == *this->storage()`,
  1184. ownership of the underlying memory is swapped in
  1185. constant time, with no possibility of exceptions.
  1186. All iterators and references remain valid.
  1187. @li If `*other.storage() != *this->storage()`,
  1188. the contents are logically swapped by making copies,
  1189. which can throw. In this case all iterators and
  1190. references are invalidated.
  1191. @par Complexity
  1192. Constant or linear in @ref size() plus `other.size()`.
  1193. @par Exception Safety
  1194. Strong guarantee.
  1195. Calls to `memory_resource::allocate` may throw.
  1196. @param other The value to swap with.
  1197. If `this == &other`, this function call has no effect.
  1198. */
  1199. BOOST_JSON_DECL
  1200. void
  1201. swap(array& other);
  1202. /** Exchange the given values.
  1203. Exchanges the contents of the array `lhs` with another array `rhs`.
  1204. Ownership of the respective `boost::container::pmr::memory_resource`
  1205. objects is not transferred.
  1206. @li If `*lhs.storage() == *rhs.storage()`,
  1207. ownership of the underlying memory is swapped in
  1208. constant time, with no possibility of exceptions.
  1209. All iterators and references remain valid.
  1210. @li If `*lhs.storage() != *rhs.storage()`,
  1211. the contents are logically swapped by making a copy,
  1212. which can throw. In this case all iterators and
  1213. references are invalidated.
  1214. @par Effects
  1215. @code
  1216. lhs.swap( rhs );
  1217. @endcode
  1218. @par Complexity
  1219. Constant or linear in `lhs.size() + rhs.size()`.
  1220. @par Exception Safety
  1221. Strong guarantee.
  1222. Calls to `memory_resource::allocate` may throw.
  1223. @param lhs The array to exchange.
  1224. @param rhs The array to exchange.
  1225. If `&lhs == &rhs`, this function call has no effect.
  1226. @see @ref array::swap
  1227. */
  1228. friend
  1229. void
  1230. swap(array& lhs, array& rhs)
  1231. {
  1232. lhs.swap(rhs);
  1233. }
  1234. /** Return `true` if two arrays are equal.
  1235. Arrays are equal when their sizes are
  1236. the same, and they are element-for-element
  1237. equal in order.
  1238. @par Effects
  1239. `return std::equal( lhs.begin(), lhs.end(), rhs.begin(), rhs.end() );`
  1240. @par Complexity
  1241. Constant or linear in `lhs.size()`.
  1242. @par Exception Safety
  1243. No-throw guarantee.
  1244. */
  1245. // inline friend speeds up overload resolution
  1246. friend
  1247. bool
  1248. operator==(
  1249. array const& lhs,
  1250. array const& rhs) noexcept
  1251. {
  1252. return lhs.equal(rhs);
  1253. }
  1254. /** Return `true` if two arrays are not 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 == rhs);
  1273. }
  1274. /** Serialize @ref array to an output stream.
  1275. This function serializes an `array` as JSON into the output stream.
  1276. @return Reference to `os`.
  1277. @par Complexity
  1278. Constant or linear in the size of `arr`.
  1279. @par Exception Safety
  1280. Strong guarantee.
  1281. Calls to `memory_resource::allocate` may throw.
  1282. @param os The output stream to serialize to.
  1283. @param arr The value to serialize.
  1284. */
  1285. BOOST_JSON_DECL
  1286. friend
  1287. std::ostream&
  1288. operator<<(
  1289. std::ostream& os,
  1290. array const& arr);
  1291. private:
  1292. template<class It>
  1293. using iter_cat = typename
  1294. std::iterator_traits<It>::iterator_category;
  1295. template<class InputIt>
  1296. array(
  1297. InputIt first, InputIt last,
  1298. storage_ptr sp,
  1299. std::input_iterator_tag);
  1300. template<class InputIt>
  1301. array(
  1302. InputIt first, InputIt last,
  1303. storage_ptr sp,
  1304. std::forward_iterator_tag);
  1305. inline
  1306. std::size_t
  1307. growth(std::size_t new_size) const;
  1308. BOOST_JSON_DECL
  1309. void
  1310. reserve_impl(
  1311. std::size_t new_capacity);
  1312. BOOST_JSON_DECL
  1313. value&
  1314. push_back(
  1315. pilfered<value> pv);
  1316. BOOST_JSON_DECL
  1317. iterator
  1318. insert(
  1319. const_iterator pos,
  1320. pilfered<value> pv);
  1321. template<class InputIt>
  1322. iterator
  1323. insert(
  1324. const_iterator pos,
  1325. InputIt first, InputIt last,
  1326. std::input_iterator_tag);
  1327. template<class InputIt>
  1328. iterator
  1329. insert(
  1330. const_iterator pos,
  1331. InputIt first, InputIt last,
  1332. std::forward_iterator_tag);
  1333. BOOST_JSON_DECL
  1334. bool
  1335. equal(array const& other) const noexcept;
  1336. };
  1337. } // namespace json
  1338. } // namespace boost
  1339. // std::hash specialization
  1340. #ifndef BOOST_JSON_DOCS
  1341. namespace std {
  1342. template <>
  1343. struct hash< ::boost::json::array > {
  1344. BOOST_JSON_DECL
  1345. std::size_t
  1346. operator()(::boost::json::array const& ja) const noexcept;
  1347. };
  1348. } // std
  1349. #endif
  1350. // Must be included here for this file to stand alone
  1351. #include <boost/json/value.hpp>
  1352. // includes are at the bottom of <boost/json/value.hpp>
  1353. #endif