unordered_flat_map.hpp 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812
  1. // Copyright (C) 2022-2023 Christian Mazakas
  2. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  3. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  4. #ifndef BOOST_UNORDERED_UNORDERED_FLAT_MAP_HPP_INCLUDED
  5. #define BOOST_UNORDERED_UNORDERED_FLAT_MAP_HPP_INCLUDED
  6. #include <boost/config.hpp>
  7. #if defined(BOOST_HAS_PRAGMA_ONCE)
  8. #pragma once
  9. #endif
  10. #include <boost/unordered/concurrent_flat_map_fwd.hpp>
  11. #include <boost/unordered/detail/foa/flat_map_types.hpp>
  12. #include <boost/unordered/detail/foa/table.hpp>
  13. #include <boost/unordered/detail/serialize_container.hpp>
  14. #include <boost/unordered/detail/throw_exception.hpp>
  15. #include <boost/unordered/detail/type_traits.hpp>
  16. #include <boost/unordered/unordered_flat_map_fwd.hpp>
  17. #include <boost/core/allocator_access.hpp>
  18. #include <boost/container_hash/hash.hpp>
  19. #include <initializer_list>
  20. #include <iterator>
  21. #include <stdexcept>
  22. #include <type_traits>
  23. #include <utility>
  24. namespace boost {
  25. namespace unordered {
  26. #if defined(BOOST_MSVC)
  27. #pragma warning(push)
  28. #pragma warning(disable : 4714) /* marked as __forceinline not inlined */
  29. #endif
  30. template <class Key, class T, class Hash, class KeyEqual, class Allocator>
  31. class unordered_flat_map
  32. {
  33. template <class Key2, class T2, class Hash2, class Pred2,
  34. class Allocator2>
  35. friend class concurrent_flat_map;
  36. using map_types = detail::foa::flat_map_types<Key, T>;
  37. using table_type = detail::foa::table<map_types, Hash, KeyEqual,
  38. typename boost::allocator_rebind<Allocator,
  39. typename map_types::value_type>::type>;
  40. table_type table_;
  41. template <class K, class V, class H, class KE, class A>
  42. bool friend operator==(unordered_flat_map<K, V, H, KE, A> const& lhs,
  43. unordered_flat_map<K, V, H, KE, A> const& rhs);
  44. template <class K, class V, class H, class KE, class A, class Pred>
  45. typename unordered_flat_map<K, V, H, KE, A>::size_type friend erase_if(
  46. unordered_flat_map<K, V, H, KE, A>& set, Pred pred);
  47. public:
  48. using key_type = Key;
  49. using mapped_type = T;
  50. using value_type = typename map_types::value_type;
  51. using init_type = typename map_types::init_type;
  52. using size_type = std::size_t;
  53. using difference_type = std::ptrdiff_t;
  54. using hasher = typename boost::unordered::detail::type_identity<Hash>::type;
  55. using key_equal = typename boost::unordered::detail::type_identity<KeyEqual>::type;
  56. using allocator_type = typename boost::unordered::detail::type_identity<Allocator>::type;
  57. using reference = value_type&;
  58. using const_reference = value_type const&;
  59. using pointer = typename boost::allocator_pointer<allocator_type>::type;
  60. using const_pointer =
  61. typename boost::allocator_const_pointer<allocator_type>::type;
  62. using iterator = typename table_type::iterator;
  63. using const_iterator = typename table_type::const_iterator;
  64. #if defined(BOOST_UNORDERED_ENABLE_STATS)
  65. using stats = typename table_type::stats;
  66. #endif
  67. unordered_flat_map() : unordered_flat_map(0) {}
  68. explicit unordered_flat_map(size_type n, hasher const& h = hasher(),
  69. key_equal const& pred = key_equal(),
  70. allocator_type const& a = allocator_type())
  71. : table_(n, h, pred, a)
  72. {
  73. }
  74. unordered_flat_map(size_type n, allocator_type const& a)
  75. : unordered_flat_map(n, hasher(), key_equal(), a)
  76. {
  77. }
  78. unordered_flat_map(size_type n, hasher const& h, allocator_type const& a)
  79. : unordered_flat_map(n, h, key_equal(), a)
  80. {
  81. }
  82. template <class InputIterator>
  83. unordered_flat_map(
  84. InputIterator f, InputIterator l, allocator_type const& a)
  85. : unordered_flat_map(f, l, size_type(0), hasher(), key_equal(), a)
  86. {
  87. }
  88. explicit unordered_flat_map(allocator_type const& a)
  89. : unordered_flat_map(0, a)
  90. {
  91. }
  92. template <class Iterator>
  93. unordered_flat_map(Iterator first, Iterator last, size_type n = 0,
  94. hasher const& h = hasher(), key_equal const& pred = key_equal(),
  95. allocator_type const& a = allocator_type())
  96. : unordered_flat_map(n, h, pred, a)
  97. {
  98. this->insert(first, last);
  99. }
  100. template <class Iterator>
  101. unordered_flat_map(
  102. Iterator first, Iterator last, size_type n, allocator_type const& a)
  103. : unordered_flat_map(first, last, n, hasher(), key_equal(), a)
  104. {
  105. }
  106. template <class Iterator>
  107. unordered_flat_map(Iterator first, Iterator last, size_type n,
  108. hasher const& h, allocator_type const& a)
  109. : unordered_flat_map(first, last, n, h, key_equal(), a)
  110. {
  111. }
  112. unordered_flat_map(unordered_flat_map const& other) : table_(other.table_)
  113. {
  114. }
  115. unordered_flat_map(
  116. unordered_flat_map const& other, allocator_type const& a)
  117. : table_(other.table_, a)
  118. {
  119. }
  120. unordered_flat_map(unordered_flat_map&& other)
  121. noexcept(std::is_nothrow_move_constructible<table_type>::value)
  122. : table_(std::move(other.table_))
  123. {
  124. }
  125. unordered_flat_map(unordered_flat_map&& other, allocator_type const& al)
  126. : table_(std::move(other.table_), al)
  127. {
  128. }
  129. unordered_flat_map(std::initializer_list<value_type> ilist,
  130. size_type n = 0, hasher const& h = hasher(),
  131. key_equal const& pred = key_equal(),
  132. allocator_type const& a = allocator_type())
  133. : unordered_flat_map(ilist.begin(), ilist.end(), n, h, pred, a)
  134. {
  135. }
  136. unordered_flat_map(
  137. std::initializer_list<value_type> il, allocator_type const& a)
  138. : unordered_flat_map(il, size_type(0), hasher(), key_equal(), a)
  139. {
  140. }
  141. unordered_flat_map(std::initializer_list<value_type> init, size_type n,
  142. allocator_type const& a)
  143. : unordered_flat_map(init, n, hasher(), key_equal(), a)
  144. {
  145. }
  146. unordered_flat_map(std::initializer_list<value_type> init, size_type n,
  147. hasher const& h, allocator_type const& a)
  148. : unordered_flat_map(init, n, h, key_equal(), a)
  149. {
  150. }
  151. unordered_flat_map(
  152. concurrent_flat_map<Key, T, Hash, KeyEqual, Allocator>&& other)
  153. : table_(std::move(other.table_))
  154. {
  155. }
  156. ~unordered_flat_map() = default;
  157. unordered_flat_map& operator=(unordered_flat_map const& other)
  158. {
  159. table_ = other.table_;
  160. return *this;
  161. }
  162. unordered_flat_map& operator=(unordered_flat_map&& other) noexcept(
  163. noexcept(std::declval<table_type&>() = std::declval<table_type&&>()))
  164. {
  165. table_ = std::move(other.table_);
  166. return *this;
  167. }
  168. allocator_type get_allocator() const noexcept
  169. {
  170. return table_.get_allocator();
  171. }
  172. /// Iterators
  173. ///
  174. iterator begin() noexcept { return table_.begin(); }
  175. const_iterator begin() const noexcept { return table_.begin(); }
  176. const_iterator cbegin() const noexcept { return table_.cbegin(); }
  177. iterator end() noexcept { return table_.end(); }
  178. const_iterator end() const noexcept { return table_.end(); }
  179. const_iterator cend() const noexcept { return table_.cend(); }
  180. /// Capacity
  181. ///
  182. BOOST_ATTRIBUTE_NODISCARD bool empty() const noexcept
  183. {
  184. return table_.empty();
  185. }
  186. size_type size() const noexcept { return table_.size(); }
  187. size_type max_size() const noexcept { return table_.max_size(); }
  188. /// Modifiers
  189. ///
  190. void clear() noexcept { table_.clear(); }
  191. template <class Ty>
  192. BOOST_FORCEINLINE auto insert(Ty&& value)
  193. -> decltype(table_.insert(std::forward<Ty>(value)))
  194. {
  195. return table_.insert(std::forward<Ty>(value));
  196. }
  197. BOOST_FORCEINLINE std::pair<iterator, bool> insert(init_type&& value)
  198. {
  199. return table_.insert(std::move(value));
  200. }
  201. template <class Ty>
  202. BOOST_FORCEINLINE auto insert(const_iterator, Ty&& value)
  203. -> decltype(table_.insert(std::forward<Ty>(value)).first)
  204. {
  205. return table_.insert(std::forward<Ty>(value)).first;
  206. }
  207. BOOST_FORCEINLINE iterator insert(const_iterator, init_type&& value)
  208. {
  209. return table_.insert(std::move(value)).first;
  210. }
  211. template <class InputIterator>
  212. BOOST_FORCEINLINE void insert(InputIterator first, InputIterator last)
  213. {
  214. for (auto pos = first; pos != last; ++pos) {
  215. table_.emplace(*pos);
  216. }
  217. }
  218. void insert(std::initializer_list<value_type> ilist)
  219. {
  220. this->insert(ilist.begin(), ilist.end());
  221. }
  222. template <class M>
  223. std::pair<iterator, bool> insert_or_assign(key_type const& key, M&& obj)
  224. {
  225. auto ibp = table_.try_emplace(key, std::forward<M>(obj));
  226. if (ibp.second) {
  227. return ibp;
  228. }
  229. ibp.first->second = std::forward<M>(obj);
  230. return ibp;
  231. }
  232. template <class M>
  233. std::pair<iterator, bool> insert_or_assign(key_type&& key, M&& obj)
  234. {
  235. auto ibp = table_.try_emplace(std::move(key), std::forward<M>(obj));
  236. if (ibp.second) {
  237. return ibp;
  238. }
  239. ibp.first->second = std::forward<M>(obj);
  240. return ibp;
  241. }
  242. template <class K, class M>
  243. typename std::enable_if<
  244. boost::unordered::detail::are_transparent<K, hasher, key_equal>::value,
  245. std::pair<iterator, bool> >::type
  246. insert_or_assign(K&& k, M&& obj)
  247. {
  248. auto ibp = table_.try_emplace(std::forward<K>(k), std::forward<M>(obj));
  249. if (ibp.second) {
  250. return ibp;
  251. }
  252. ibp.first->second = std::forward<M>(obj);
  253. return ibp;
  254. }
  255. template <class M>
  256. iterator insert_or_assign(const_iterator, key_type const& key, M&& obj)
  257. {
  258. return this->insert_or_assign(key, std::forward<M>(obj)).first;
  259. }
  260. template <class M>
  261. iterator insert_or_assign(const_iterator, key_type&& key, M&& obj)
  262. {
  263. return this->insert_or_assign(std::move(key), std::forward<M>(obj))
  264. .first;
  265. }
  266. template <class K, class M>
  267. typename std::enable_if<
  268. boost::unordered::detail::are_transparent<K, hasher, key_equal>::value,
  269. iterator>::type
  270. insert_or_assign(const_iterator, K&& k, M&& obj)
  271. {
  272. return this->insert_or_assign(std::forward<K>(k), std::forward<M>(obj))
  273. .first;
  274. }
  275. template <class... Args>
  276. BOOST_FORCEINLINE std::pair<iterator, bool> emplace(Args&&... args)
  277. {
  278. return table_.emplace(std::forward<Args>(args)...);
  279. }
  280. template <class... Args>
  281. BOOST_FORCEINLINE iterator emplace_hint(const_iterator, Args&&... args)
  282. {
  283. return table_.emplace(std::forward<Args>(args)...).first;
  284. }
  285. template <class... Args>
  286. BOOST_FORCEINLINE std::pair<iterator, bool> try_emplace(
  287. key_type const& key, Args&&... args)
  288. {
  289. return table_.try_emplace(key, std::forward<Args>(args)...);
  290. }
  291. template <class... Args>
  292. BOOST_FORCEINLINE std::pair<iterator, bool> try_emplace(
  293. key_type&& key, Args&&... args)
  294. {
  295. return table_.try_emplace(std::move(key), std::forward<Args>(args)...);
  296. }
  297. template <class K, class... Args>
  298. BOOST_FORCEINLINE typename std::enable_if<
  299. boost::unordered::detail::transparent_non_iterable<K,
  300. unordered_flat_map>::value,
  301. std::pair<iterator, bool> >::type
  302. try_emplace(K&& key, Args&&... args)
  303. {
  304. return table_.try_emplace(
  305. std::forward<K>(key), std::forward<Args>(args)...);
  306. }
  307. template <class... Args>
  308. BOOST_FORCEINLINE iterator try_emplace(
  309. const_iterator, key_type const& key, Args&&... args)
  310. {
  311. return table_.try_emplace(key, std::forward<Args>(args)...).first;
  312. }
  313. template <class... Args>
  314. BOOST_FORCEINLINE iterator try_emplace(
  315. const_iterator, key_type&& key, Args&&... args)
  316. {
  317. return table_.try_emplace(std::move(key), std::forward<Args>(args)...)
  318. .first;
  319. }
  320. template <class K, class... Args>
  321. BOOST_FORCEINLINE typename std::enable_if<
  322. boost::unordered::detail::transparent_non_iterable<K,
  323. unordered_flat_map>::value,
  324. iterator>::type
  325. try_emplace(const_iterator, K&& key, Args&&... args)
  326. {
  327. return table_
  328. .try_emplace(std::forward<K>(key), std::forward<Args>(args)...)
  329. .first;
  330. }
  331. BOOST_FORCEINLINE typename table_type::erase_return_type erase(
  332. iterator pos)
  333. {
  334. return table_.erase(pos);
  335. }
  336. BOOST_FORCEINLINE typename table_type::erase_return_type erase(
  337. const_iterator pos)
  338. {
  339. return table_.erase(pos);
  340. }
  341. iterator erase(const_iterator first, const_iterator last)
  342. {
  343. while (first != last) {
  344. this->erase(first++);
  345. }
  346. return iterator{detail::foa::const_iterator_cast_tag{}, last};
  347. }
  348. BOOST_FORCEINLINE size_type erase(key_type const& key)
  349. {
  350. return table_.erase(key);
  351. }
  352. template <class K>
  353. BOOST_FORCEINLINE typename std::enable_if<
  354. detail::transparent_non_iterable<K, unordered_flat_map>::value,
  355. size_type>::type
  356. erase(K const& key)
  357. {
  358. return table_.erase(key);
  359. }
  360. void swap(unordered_flat_map& rhs) noexcept(
  361. noexcept(std::declval<table_type&>().swap(std::declval<table_type&>())))
  362. {
  363. table_.swap(rhs.table_);
  364. }
  365. template <class H2, class P2>
  366. void merge(
  367. unordered_flat_map<key_type, mapped_type, H2, P2, allocator_type>&
  368. source)
  369. {
  370. table_.merge(source.table_);
  371. }
  372. template <class H2, class P2>
  373. void merge(
  374. unordered_flat_map<key_type, mapped_type, H2, P2, allocator_type>&&
  375. source)
  376. {
  377. table_.merge(std::move(source.table_));
  378. }
  379. /// Lookup
  380. ///
  381. mapped_type& at(key_type const& key)
  382. {
  383. auto pos = table_.find(key);
  384. if (pos != table_.end()) {
  385. return pos->second;
  386. }
  387. // TODO: someday refactor this to conditionally serialize the key and
  388. // include it in the error message
  389. //
  390. boost::unordered::detail::throw_out_of_range(
  391. "key was not found in unordered_flat_map");
  392. }
  393. mapped_type const& at(key_type const& key) const
  394. {
  395. auto pos = table_.find(key);
  396. if (pos != table_.end()) {
  397. return pos->second;
  398. }
  399. boost::unordered::detail::throw_out_of_range(
  400. "key was not found in unordered_flat_map");
  401. }
  402. template <class K>
  403. typename std::enable_if<
  404. boost::unordered::detail::are_transparent<K, hasher, key_equal>::value,
  405. mapped_type&>::type
  406. at(K&& key)
  407. {
  408. auto pos = table_.find(std::forward<K>(key));
  409. if (pos != table_.end()) {
  410. return pos->second;
  411. }
  412. boost::unordered::detail::throw_out_of_range(
  413. "key was not found in unordered_flat_map");
  414. }
  415. template <class K>
  416. typename std::enable_if<
  417. boost::unordered::detail::are_transparent<K, hasher, key_equal>::value,
  418. mapped_type const&>::type
  419. at(K&& key) const
  420. {
  421. auto pos = table_.find(std::forward<K>(key));
  422. if (pos != table_.end()) {
  423. return pos->second;
  424. }
  425. boost::unordered::detail::throw_out_of_range(
  426. "key was not found in unordered_flat_map");
  427. }
  428. BOOST_FORCEINLINE mapped_type& operator[](key_type const& key)
  429. {
  430. return table_.try_emplace(key).first->second;
  431. }
  432. BOOST_FORCEINLINE mapped_type& operator[](key_type&& key)
  433. {
  434. return table_.try_emplace(std::move(key)).first->second;
  435. }
  436. template <class K>
  437. typename std::enable_if<
  438. boost::unordered::detail::are_transparent<K, hasher, key_equal>::value,
  439. mapped_type&>::type
  440. operator[](K&& key)
  441. {
  442. return table_.try_emplace(std::forward<K>(key)).first->second;
  443. }
  444. BOOST_FORCEINLINE size_type count(key_type const& key) const
  445. {
  446. auto pos = table_.find(key);
  447. return pos != table_.end() ? 1 : 0;
  448. }
  449. template <class K>
  450. BOOST_FORCEINLINE typename std::enable_if<
  451. detail::are_transparent<K, hasher, key_equal>::value, size_type>::type
  452. count(K const& key) const
  453. {
  454. auto pos = table_.find(key);
  455. return pos != table_.end() ? 1 : 0;
  456. }
  457. BOOST_FORCEINLINE iterator find(key_type const& key)
  458. {
  459. return table_.find(key);
  460. }
  461. BOOST_FORCEINLINE const_iterator find(key_type const& key) const
  462. {
  463. return table_.find(key);
  464. }
  465. template <class K>
  466. BOOST_FORCEINLINE typename std::enable_if<
  467. boost::unordered::detail::are_transparent<K, hasher, key_equal>::value,
  468. iterator>::type
  469. find(K const& key)
  470. {
  471. return table_.find(key);
  472. }
  473. template <class K>
  474. BOOST_FORCEINLINE typename std::enable_if<
  475. boost::unordered::detail::are_transparent<K, hasher, key_equal>::value,
  476. const_iterator>::type
  477. find(K const& key) const
  478. {
  479. return table_.find(key);
  480. }
  481. BOOST_FORCEINLINE bool contains(key_type const& key) const
  482. {
  483. return this->find(key) != this->end();
  484. }
  485. template <class K>
  486. BOOST_FORCEINLINE typename std::enable_if<
  487. boost::unordered::detail::are_transparent<K, hasher, key_equal>::value,
  488. bool>::type
  489. contains(K const& key) const
  490. {
  491. return this->find(key) != this->end();
  492. }
  493. std::pair<iterator, iterator> equal_range(key_type const& key)
  494. {
  495. auto pos = table_.find(key);
  496. if (pos == table_.end()) {
  497. return {pos, pos};
  498. }
  499. auto next = pos;
  500. ++next;
  501. return {pos, next};
  502. }
  503. std::pair<const_iterator, const_iterator> equal_range(
  504. key_type const& key) const
  505. {
  506. auto pos = table_.find(key);
  507. if (pos == table_.end()) {
  508. return {pos, pos};
  509. }
  510. auto next = pos;
  511. ++next;
  512. return {pos, next};
  513. }
  514. template <class K>
  515. typename std::enable_if<
  516. detail::are_transparent<K, hasher, key_equal>::value,
  517. std::pair<iterator, iterator> >::type
  518. equal_range(K const& key)
  519. {
  520. auto pos = table_.find(key);
  521. if (pos == table_.end()) {
  522. return {pos, pos};
  523. }
  524. auto next = pos;
  525. ++next;
  526. return {pos, next};
  527. }
  528. template <class K>
  529. typename std::enable_if<
  530. detail::are_transparent<K, hasher, key_equal>::value,
  531. std::pair<const_iterator, const_iterator> >::type
  532. equal_range(K const& key) const
  533. {
  534. auto pos = table_.find(key);
  535. if (pos == table_.end()) {
  536. return {pos, pos};
  537. }
  538. auto next = pos;
  539. ++next;
  540. return {pos, next};
  541. }
  542. /// Hash Policy
  543. ///
  544. size_type bucket_count() const noexcept { return table_.capacity(); }
  545. float load_factor() const noexcept { return table_.load_factor(); }
  546. float max_load_factor() const noexcept
  547. {
  548. return table_.max_load_factor();
  549. }
  550. void max_load_factor(float) {}
  551. size_type max_load() const noexcept { return table_.max_load(); }
  552. void rehash(size_type n) { table_.rehash(n); }
  553. void reserve(size_type n) { table_.reserve(n); }
  554. #if defined(BOOST_UNORDERED_ENABLE_STATS)
  555. /// Stats
  556. ///
  557. stats get_stats() const { return table_.get_stats(); }
  558. void reset_stats() noexcept { table_.reset_stats(); }
  559. #endif
  560. /// Observers
  561. ///
  562. hasher hash_function() const { return table_.hash_function(); }
  563. key_equal key_eq() const { return table_.key_eq(); }
  564. };
  565. template <class Key, class T, class Hash, class KeyEqual, class Allocator>
  566. bool operator==(
  567. unordered_flat_map<Key, T, Hash, KeyEqual, Allocator> const& lhs,
  568. unordered_flat_map<Key, T, Hash, KeyEqual, Allocator> const& rhs)
  569. {
  570. return lhs.table_ == rhs.table_;
  571. }
  572. template <class Key, class T, class Hash, class KeyEqual, class Allocator>
  573. bool operator!=(
  574. unordered_flat_map<Key, T, Hash, KeyEqual, Allocator> const& lhs,
  575. unordered_flat_map<Key, T, Hash, KeyEqual, Allocator> const& rhs)
  576. {
  577. return !(lhs == rhs);
  578. }
  579. template <class Key, class T, class Hash, class KeyEqual, class Allocator>
  580. void swap(unordered_flat_map<Key, T, Hash, KeyEqual, Allocator>& lhs,
  581. unordered_flat_map<Key, T, Hash, KeyEqual, Allocator>& rhs)
  582. noexcept(noexcept(lhs.swap(rhs)))
  583. {
  584. lhs.swap(rhs);
  585. }
  586. template <class Key, class T, class Hash, class KeyEqual, class Allocator,
  587. class Pred>
  588. typename unordered_flat_map<Key, T, Hash, KeyEqual, Allocator>::size_type
  589. erase_if(
  590. unordered_flat_map<Key, T, Hash, KeyEqual, Allocator>& map, Pred pred)
  591. {
  592. return erase_if(map.table_, pred);
  593. }
  594. template <class Archive, class Key, class T, class Hash, class KeyEqual,
  595. class Allocator>
  596. void serialize(Archive& ar,
  597. unordered_flat_map<Key, T, Hash, KeyEqual, Allocator>& map,
  598. unsigned int version)
  599. {
  600. detail::serialize_container(ar, map, version);
  601. }
  602. #if defined(BOOST_MSVC)
  603. #pragma warning(pop) /* C4714 */
  604. #endif
  605. #if BOOST_UNORDERED_TEMPLATE_DEDUCTION_GUIDES
  606. template <class InputIterator,
  607. class Hash =
  608. boost::hash<boost::unordered::detail::iter_key_t<InputIterator> >,
  609. class Pred =
  610. std::equal_to<boost::unordered::detail::iter_key_t<InputIterator> >,
  611. class Allocator = std::allocator<
  612. boost::unordered::detail::iter_to_alloc_t<InputIterator> >,
  613. class = std::enable_if_t<detail::is_input_iterator_v<InputIterator> >,
  614. class = std::enable_if_t<detail::is_hash_v<Hash> >,
  615. class = std::enable_if_t<detail::is_pred_v<Pred> >,
  616. class = std::enable_if_t<detail::is_allocator_v<Allocator> > >
  617. unordered_flat_map(InputIterator, InputIterator,
  618. std::size_t = boost::unordered::detail::foa::default_bucket_count,
  619. Hash = Hash(), Pred = Pred(), Allocator = Allocator())
  620. -> unordered_flat_map<boost::unordered::detail::iter_key_t<InputIterator>,
  621. boost::unordered::detail::iter_val_t<InputIterator>, Hash, Pred,
  622. Allocator>;
  623. template <class Key, class T,
  624. class Hash = boost::hash<std::remove_const_t<Key> >,
  625. class Pred = std::equal_to<std::remove_const_t<Key> >,
  626. class Allocator = std::allocator<std::pair<const Key, T> >,
  627. class = std::enable_if_t<detail::is_hash_v<Hash> >,
  628. class = std::enable_if_t<detail::is_pred_v<Pred> >,
  629. class = std::enable_if_t<detail::is_allocator_v<Allocator> > >
  630. unordered_flat_map(std::initializer_list<std::pair<Key, T> >,
  631. std::size_t = boost::unordered::detail::foa::default_bucket_count,
  632. Hash = Hash(), Pred = Pred(), Allocator = Allocator())
  633. -> unordered_flat_map<std::remove_const_t<Key>, T, Hash, Pred,
  634. Allocator>;
  635. template <class InputIterator, class Allocator,
  636. class = std::enable_if_t<detail::is_input_iterator_v<InputIterator> >,
  637. class = std::enable_if_t<detail::is_allocator_v<Allocator> > >
  638. unordered_flat_map(InputIterator, InputIterator, std::size_t, Allocator)
  639. -> unordered_flat_map<boost::unordered::detail::iter_key_t<InputIterator>,
  640. boost::unordered::detail::iter_val_t<InputIterator>,
  641. boost::hash<boost::unordered::detail::iter_key_t<InputIterator> >,
  642. std::equal_to<boost::unordered::detail::iter_key_t<InputIterator> >,
  643. Allocator>;
  644. template <class InputIterator, class Allocator,
  645. class = std::enable_if_t<detail::is_input_iterator_v<InputIterator> >,
  646. class = std::enable_if_t<detail::is_allocator_v<Allocator> > >
  647. unordered_flat_map(InputIterator, InputIterator, Allocator)
  648. -> unordered_flat_map<boost::unordered::detail::iter_key_t<InputIterator>,
  649. boost::unordered::detail::iter_val_t<InputIterator>,
  650. boost::hash<boost::unordered::detail::iter_key_t<InputIterator> >,
  651. std::equal_to<boost::unordered::detail::iter_key_t<InputIterator> >,
  652. Allocator>;
  653. template <class InputIterator, class Hash, class Allocator,
  654. class = std::enable_if_t<detail::is_hash_v<Hash> >,
  655. class = std::enable_if_t<detail::is_input_iterator_v<InputIterator> >,
  656. class = std::enable_if_t<detail::is_allocator_v<Allocator> > >
  657. unordered_flat_map(
  658. InputIterator, InputIterator, std::size_t, Hash, Allocator)
  659. -> unordered_flat_map<boost::unordered::detail::iter_key_t<InputIterator>,
  660. boost::unordered::detail::iter_val_t<InputIterator>, Hash,
  661. std::equal_to<boost::unordered::detail::iter_key_t<InputIterator> >,
  662. Allocator>;
  663. template <class Key, class T, class Allocator,
  664. class = std::enable_if_t<detail::is_allocator_v<Allocator> > >
  665. unordered_flat_map(std::initializer_list<std::pair<Key, T> >, std::size_t,
  666. Allocator) -> unordered_flat_map<std::remove_const_t<Key>, T,
  667. boost::hash<std::remove_const_t<Key> >,
  668. std::equal_to<std::remove_const_t<Key> >, Allocator>;
  669. template <class Key, class T, class Allocator,
  670. class = std::enable_if_t<detail::is_allocator_v<Allocator> > >
  671. unordered_flat_map(std::initializer_list<std::pair<Key, T> >, Allocator)
  672. -> unordered_flat_map<std::remove_const_t<Key>, T,
  673. boost::hash<std::remove_const_t<Key> >,
  674. std::equal_to<std::remove_const_t<Key> >, Allocator>;
  675. template <class Key, class T, class Hash, class Allocator,
  676. class = std::enable_if_t<detail::is_hash_v<Hash> >,
  677. class = std::enable_if_t<detail::is_allocator_v<Allocator> > >
  678. unordered_flat_map(std::initializer_list<std::pair<Key, T> >, std::size_t,
  679. Hash, Allocator) -> unordered_flat_map<std::remove_const_t<Key>, T,
  680. Hash, std::equal_to<std::remove_const_t<Key> >, Allocator>;
  681. #endif
  682. } // namespace unordered
  683. } // namespace boost
  684. #endif