unordered_flat_map.hpp 26 KB

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