#include <cassert>

#include <algorithm>
#include <string>
#include <utility>
#include <vector>

template <typename Key, typename Value>
typename std::vector<std::pair<const Key, Value>>::const_iterator
my_find(const std::vector<std::pair<const Key, Value>>& v, const Key& key)
{


    auto it = std::lower_bound(v.begin(), v.end(), key,
        [](const std::pair<const Key, Value>& lhs, const Key& rhs) {
            return lhs.first < rhs;
        }
    );
    if (it != v.end() && it->first == key) {
        return it;
    }
    return v.end();
}

int main()
{
    const std::vector<std::pair<const std::string, int>> v = {
        {"abc", 42},
        {"bar", 51},
        {"foo", 8}
    };

    assert(v.begin() + 1 == my_find(v, std::string("bar")));
    assert(v.end() == my_find(v, std::string("not present")));

    return 0;
}
