unordered_flat_map.hpp 26 KB

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