| 1 | // Copyright (C) 2023 Christian Mazakas |
| 2 | // Copyright (C) 2024 Braden Ganetsky |
| 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 | |
| 6 | #ifndef BOOST_UNORDERED_DETAIL_FOA_FLAT_MAP_TYPES_HPP |
| 7 | #define BOOST_UNORDERED_DETAIL_FOA_FLAT_MAP_TYPES_HPP |
| 8 | |
| 9 | #include <boost/core/allocator_access.hpp> |
| 10 | |
| 11 | namespace boost { |
| 12 | namespace unordered { |
| 13 | namespace detail { |
| 14 | namespace foa { |
| 15 | template <class Key, class T> struct flat_map_types |
| 16 | { |
| 17 | using key_type = Key; |
| 18 | using mapped_type = T; |
| 19 | using raw_key_type = typename std::remove_const<Key>::type; |
| 20 | using raw_mapped_type = typename std::remove_const<T>::type; |
| 21 | |
| 22 | using init_type = std::pair<raw_key_type, raw_mapped_type>; |
| 23 | using moved_type = std::pair<raw_key_type&&, raw_mapped_type&&>; |
| 24 | using value_type = std::pair<Key const, T>; |
| 25 | |
| 26 | using element_type = value_type; |
| 27 | |
| 28 | static value_type& value_from(element_type& x) { return x; } |
| 29 | |
| 30 | template <class K, class V> |
| 31 | static raw_key_type const& (std::pair<K, V> const& kv) |
| 32 | { |
| 33 | return kv.first; |
| 34 | } |
| 35 | |
| 36 | static moved_type move(init_type& x) |
| 37 | { |
| 38 | return {std::move(x.first), std::move(x.second)}; |
| 39 | } |
| 40 | |
| 41 | static moved_type move(element_type& x) |
| 42 | { |
| 43 | // TODO: we probably need to launder here |
| 44 | return {std::move(const_cast<raw_key_type&>(x.first)), |
| 45 | std::move(const_cast<raw_mapped_type&>(x.second))}; |
| 46 | } |
| 47 | |
| 48 | template <class A, class... Args> |
| 49 | static void construct(A& al, init_type* p, Args&&... args) |
| 50 | { |
| 51 | boost::allocator_construct(al, p, std::forward<Args>(args)...); |
| 52 | } |
| 53 | |
| 54 | template <class A, class... Args> |
| 55 | static void construct(A& al, value_type* p, Args&&... args) |
| 56 | { |
| 57 | boost::allocator_construct(al, p, std::forward<Args>(args)...); |
| 58 | } |
| 59 | |
| 60 | template <class A, class... Args> |
| 61 | static void construct(A& al, key_type* p, Args&&... args) |
| 62 | { |
| 63 | boost::allocator_construct(al, p, std::forward<Args>(args)...); |
| 64 | } |
| 65 | |
| 66 | template <class A> static void destroy(A& al, init_type* p) noexcept |
| 67 | { |
| 68 | boost::allocator_destroy(al, p); |
| 69 | } |
| 70 | |
| 71 | template <class A> static void destroy(A& al, value_type* p) noexcept |
| 72 | { |
| 73 | boost::allocator_destroy(al, p); |
| 74 | } |
| 75 | |
| 76 | template <class A> static void destroy(A& al, key_type* p) noexcept |
| 77 | { |
| 78 | boost::allocator_destroy(al, p); |
| 79 | } |
| 80 | }; |
| 81 | } // namespace foa |
| 82 | } // namespace detail |
| 83 | } // namespace unordered |
| 84 | } // namespace boost |
| 85 | |
| 86 | #endif // BOOST_UNORDERED_DETAIL_FOA_FLAT_MAP_TYPES_HPP |
| 87 | |