sandbox
Loading...
Searching...
No Matches
multimap_key_range.hpp
1// SPDX-License-Identifier: MIT
2#ifndef LIBSBX_UTILITY_MULTIMAP_KEY_RANGE_HPP_
3#define LIBSBX_UTILITY_MULTIMAP_KEY_RANGE_HPP_
4
5#include <utility>
6#include <tuple>
7#include <concepts>
8#include <type_traits>
9
10namespace sbx::utility {
11
12template<typename Map>
13concept multimap = requires {
14 typename Map::key_type;
15 typename Map::iterator;
16 typename Map::const_iterator;
17} && requires(Map& map, const Map::key_type& key) {
18 { map.equal_range(key) };
19};
20
21template<multimap Map>
23
24public:
25
26 using key_type = typename Map::key_type;
27 using iterator = std::conditional_t<std::is_const_v<Map>, typename Map::const_iterator, typename Map::iterator>;
28
29 multimap_key_range(Map& range, const key_type& key) {
30 std::tie(_begin, _end) = range.equal_range(key);
31 }
32
33 auto begin() -> iterator {
34 return _begin;
35 }
36
37 auto end() -> iterator {
38 return _end;
39 }
40
41private:
42
43 iterator _begin;
44 iterator _end;
45
46};
47
48} // namespace sbx::utility
49
50#endif // LIBSBX_UTILITY_MULTIMAP_KEY_RANGE_HPP_
Definition: multimap_key_range.hpp:22