diff options
Diffstat (limited to 'libs/kstd/kstd/flat_map.hpp')
| -rw-r--r-- | libs/kstd/kstd/flat_map.hpp | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/libs/kstd/kstd/flat_map.hpp b/libs/kstd/kstd/flat_map.hpp index f00956a5..dcf73392 100644 --- a/libs/kstd/kstd/flat_map.hpp +++ b/libs/kstd/kstd/flat_map.hpp @@ -872,6 +872,59 @@ namespace kstd return iterator{m_containers, offset}; } + //! Get a range of elements whose keys compare equal to the given key. + //! + //! @param key The key to look for. + //! @return A pair of iterators describing the, possibly empty, range of elements. + [[nodiscard]] constexpr auto equal_range(key_type const & key) noexcept -> std::pair<iterator, iterator> + { + auto found = std::ranges::equal_range(m_containers.keys, key, m_comparator); + auto start_offset = static_cast<std::size_t>(std::ranges::distance(m_containers.keys.begin(), found.begin())); + auto end_offset = static_cast<std::size_t>(std::ranges::distance(m_containers.keys.begin(), found.end())); + return std::make_pair(iterator{m_containers, start_offset}, iterator{m_containers, end_offset}); + } + + //! Get a range of elements whose keys compare equal to the given key. + //! + //! @param key The key to look for. + //! @return A pair of iterators describing the, possibly empty, range of elements. + [[nodiscard]] constexpr auto equal_range(key_type const & key) const noexcept + -> std::pair<const_iterator, const_iterator> + { + auto found = std::ranges::equal_range(m_containers.keys, key, m_comparator); + auto start_offset = static_cast<std::size_t>(std::ranges::distance(m_containers.keys.begin(), found.begin())); + auto end_offset = static_cast<std::size_t>(std::ranges::distance(m_containers.keys.begin(), found.end())); + return std::make_pair(iterator{m_containers, start_offset}, iterator{m_containers, end_offset}); + } + + //! Get a range of elements whose keys compare equal to the given key. + //! + //! @param key The key to look for. + //! @return A pair of iterators describing the, possibly empty, range of elements. + template<typename K> + requires requires { typename key_compare::is_transparent; } + [[nodiscard]] constexpr auto equal_range(K const & key) noexcept -> std::pair<iterator, iterator> + { + auto found = std::ranges::equal_range(m_containers.keys, key, m_comparator); + auto start_offset = static_cast<std::size_t>(std::ranges::distance(m_containers.keys.begin(), found.begin())); + auto end_offset = static_cast<std::size_t>(std::ranges::distance(m_containers.keys.begin(), found.end())); + return std::make_pair(iterator{m_containers, start_offset}, iterator{m_containers, end_offset}); + } + + //! Get a range of elements whose keys compare equal to the given key. + //! + //! @param key The key to look for. + //! @return A pair of iterators describing the, possibly empty, range of elements. + template<typename K> + requires requires { typename key_compare::is_transparent; } + [[nodiscard]] constexpr auto equal_range(K const & key) const noexcept -> std::pair<const_iterator, const_iterator> + { + auto found = std::ranges::equal_range(m_containers.keys, key, m_comparator); + auto start_offset = static_cast<std::size_t>(std::ranges::distance(m_containers.keys.begin(), found.begin())); + auto end_offset = static_cast<std::size_t>(std::ranges::distance(m_containers.keys.begin(), found.end())); + return std::make_pair(iterator{m_containers, start_offset}, iterator{m_containers, end_offset}); + } + //! Get the key comparator of this flat map. //! //! @return The key comparator of this flat map. |
