I write this code:
std::vector<std::pair<std::string, std::string>> map_ = {{"b", "1"}, {"a", "2"}};
auto iter = std::lower_bound(map_.begin(), map_.end(), key,
[](auto p1, std::string& rhs) { return p1.first < rhs; });
and get such compile error:
error: no matching function for call to object of type '(lambda at /Users/bestasoff/.../static_map.h:17:38)'
if (__comp(*__m, __value_))
But if I drop &, std::lower_bound works properly.
Why?
If you look at the requirements for the predicate in
std::lower_boundyou will see that it should look likeSo you can't use reference. Only with
constqualifier(or pass key by value).