+
+ template <typename Self>
+ using self_iterator_t = _t<
+ std::conditional<std::is_const<Self>::value, const_iterator, iterator>>;
+
+ template <typename Self, typename K>
+ static self_iterator_t<Self> find(Self& self, K const& key) {
+ auto end = self.end();
+ auto it = self.lower_bound(key);
+ if (it == end || !self.key_comp()(key, it->first)) {
+ return it;
+ }
+ return end;
+ }
+
+ template <typename Self, typename K>
+ static self_iterator_t<Self> lower_bound(Self& self, K const& key) {
+ auto f = [c = self.key_comp()](value_type const& a, K const& b) {
+ return c(a.first, b);
+ };
+ return std::lower_bound(self.begin(), self.end(), key, f);
+ }
+
+ template <typename Self, typename K>
+ static self_iterator_t<Self> upper_bound(Self& self, K const& key) {
+ auto f = [c = self.key_comp()](K const& a, value_type const& b) {
+ return c(a, b.first);
+ };
+ return std::upper_bound(self.begin(), self.end(), key, f);
+ }
+
+ template <typename Self, typename K>
+ static std::pair<self_iterator_t<Self>, self_iterator_t<Self>> equal_range(
+ Self& self,
+ K const& key) {
+ // Note: std::equal_range can't be passed a functor that takes
+ // argument types different from the iterator value_type, so we
+ // have to do this.
+ return {lower_bound(self, key), upper_bound(self, key)};
+ }