aboutsummaryrefslogtreecommitdiff
path: root/libs/kstd/kstd/flat_map.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'libs/kstd/kstd/flat_map.hpp')
-rw-r--r--libs/kstd/kstd/flat_map.hpp52
1 files changed, 52 insertions, 0 deletions
diff --git a/libs/kstd/kstd/flat_map.hpp b/libs/kstd/kstd/flat_map.hpp
index 3eda42d8..f00956a5 100644
--- a/libs/kstd/kstd/flat_map.hpp
+++ b/libs/kstd/kstd/flat_map.hpp
@@ -820,6 +820,58 @@ namespace kstd
return const_iterator{m_containers, offset};
}
+ //! Get an iterator to the first element greater than the given key.
+ //!
+ //! @param key The key to look for.
+ //! @return An iterator to the first element greater than the given iff. such an element exists, the end iterator
+ //! otherwise.
+ [[nodiscard]] constexpr auto upper_bound(key_type const & key) noexcept -> iterator
+ {
+ auto found = std::ranges::upper_bound(m_containers.keys, key, m_comparator);
+ auto offset = static_cast<std::size_t>(std::ranges::distance(m_containers.keys.begin(), found));
+ return iterator{m_containers, offset};
+ }
+
+ //! Get an iterator to the first element greater than the given key.
+ //!
+ //! @param key The key to look for.
+ //! @return An iterator to the first element greater than the given iff. such an element exists, the end iterator
+ //! otherwise.
+ [[nodiscard]] constexpr auto upper_bound(key_type const & key) const noexcept -> const_iterator
+ {
+ auto found = std::ranges::upper_bound(m_containers.keys, key, m_comparator);
+ auto offset = static_cast<std::size_t>(std::ranges::distance(m_containers.keys.begin(), found));
+ return const_iterator{m_containers, offset};
+ }
+
+ //! Get an iterator to the first element greater than the given key.
+ //!
+ //! @param key The key to look for.
+ //! @return An iterator to the first element greater than the given iff. such an element exists, the end iterator
+ //! otherwise.
+ template<typename K>
+ requires requires { typename key_compare::is_transparent; }
+ [[nodiscard]] constexpr auto upper_bound(K const & key) noexcept -> iterator
+ {
+ auto found = std::ranges::upper_bound(m_containers.keys, key, m_comparator);
+ auto offset = static_cast<std::size_t>(std::ranges::distance(m_containers.keys.begin(), found));
+ return iterator{m_containers, offset};
+ }
+
+ //! Get an iterator to the first element greater than the given key.
+ //!
+ //! @param key The key to look for.
+ //! @return An iterator to the first element greater than the given iff. such an element exists, the end iterator
+ //! otherwise.
+ template<typename K>
+ requires requires { typename key_compare::is_transparent; }
+ [[nodiscard]] constexpr auto upper_bound(K const & key) const noexcept -> const_iterator
+ {
+ auto found = std::ranges::upper_bound(m_containers.keys, key, m_comparator);
+ auto offset = static_cast<std::size_t>(std::ranges::distance(m_containers.keys.begin(), found));
+ return iterator{m_containers, offset};
+ }
+
//! Get the key comparator of this flat map.
//!
//! @return The key comparator of this flat map.