19 static constexpr bool no_mapped_container = std::is_same_v<MappedContainer, ::brstd::no_mapped_container_t>;
20 template <
bool NoMappedContainer>
24 using mapped_type = Key;
25 using value_type = Key;
29 using mapped_type = T;
30 using value_type = std::pair<Key, T>;
35 using mapped_type = std::conditional_t<no_mapped_container, Key, T>;
36 using key_compare = Compare;
37 using key_container_type = KeyContainer;
38 using mapped_container_type = MappedContainer;
39 using size_type =
typename key_container_type::size_type;
40 using difference_type =
typename std::iterator_traits<typename key_container_type::iterator>::difference_type;
43 template <
typename KeysIterator,
typename ValuesIterator,
typename Reference>
44 class zip_iterator_impl {
46 using difference_type =
typename std::iterator_traits<KeysIterator>::difference_type;
47 using reference = Reference;
48 using iterator_category =
typename std::iterator_traits<KeysIterator>::iterator_category;
51 zip_iterator_impl() =
default;
52 zip_iterator_impl(KeysIterator keysIt, ValuesIterator valuesIt) : mKeysIt(keysIt), mValuesIt(valuesIt) {}
54 reference operator*()
const {
55 if constexpr (no_mapped_container) {
58 return reference(*mKeysIt, *mValuesIt);
62 zip_iterator_impl& operator++() {
68 zip_iterator_impl operator++(
int) {
74 zip_iterator_impl& operator--() {
80 zip_iterator_impl operator--(
int) {
86 zip_iterator_impl& operator+=(difference_type offset) {
92 zip_iterator_impl& operator-=(difference_type offset) {
98 zip_iterator_impl operator+(difference_type offset)
const {
99 return zip_iterator_impl(mKeysIt + offset, mValuesIt + offset);
102 zip_iterator_impl operator-(difference_type offset)
const {
103 return zip_iterator_impl(mKeysIt - offset, mValuesIt - offset);
106 difference_type operator-(zip_iterator_impl
const& other)
const {
return mKeysIt - other.mKeysIt; }
107 bool operator==(zip_iterator_impl
const& other)
const {
return mKeysIt == other.mKeysIt; }
108 std::strong_ordering operator<=>(zip_iterator_impl
const& other)
const {
return mKeysIt <=> other.mKeysIt; }
111 KeysIterator mKeysIt{};
112 ValuesIterator mValuesIt{};
116 using zip_iterator = zip_iterator_impl<
117 typename key_container_type::iterator,
118 typename mapped_container_type::iterator,
119 std::conditional_t<no_mapped_container, key_type const&, std::pair<key_type const&, T&>>>;
120 using const_zip_iterator = zip_iterator_impl<
121 typename key_container_type::const_iterator,
122 typename mapped_container_type::const_iterator,
123 std::conditional_t<no_mapped_container, key_type const&, std::pair<key_type const&, T const&>>>;
125 using iterator = zip_iterator;
126 using const_iterator = const_zip_iterator;
129 key_container_type keys;
130 LL_NO_UNIQUE_ADDRESS mapped_container_type values;
134 iterator begin() noexcept {
return iterator(mContainers.keys.begin(), mContainers.values.begin()); }
135 const_iterator begin() const noexcept {
136 return const_iterator(mContainers.keys.begin(), mContainers.values.begin());
138 iterator end() noexcept {
return iterator(mContainers.keys.end(), mContainers.values.end()); }
139 const_iterator end() const noexcept {
return const_iterator(mContainers.keys.end(), mContainers.values.end()); }
140 const_iterator cbegin() const noexcept {
return begin(); }
141 const_iterator cend() const noexcept {
return end(); }
143 iterator find(key_type
const& key) {
144 auto first = mContainers.keys.begin();
145 auto last = mContainers.keys.end();
146 auto it = std::lower_bound(first, last, key, mCompare);
147 if (it != last && !mCompare(*it, key) && !mCompare(key, *it)) {
148 auto offset =
static_cast<difference_type
>(it - first);
149 return iterator(it, mContainers.values.begin() + offset);
154 const_iterator find(key_type
const& key)
const {
155 auto first = mContainers.keys.begin();
156 auto last = mContainers.keys.end();
157 auto it = std::lower_bound(first, last, key, mCompare);
158 if (it != last && !mCompare(*it, key) && !mCompare(key, *it)) {
159 auto offset =
static_cast<difference_type
>(it - first);
160 return const_iterator(it, mContainers.values.begin() + offset);
167 LL_NO_UNIQUE_ADDRESS key_compare mCompare{};