I have an std::set of std::pairs, and the second pair is a string. I want to check if a pair exists in the set.
std::set< std::pair<size_t, std::string> > set_; bool exists(size_t x, const std::string& s) { std::set< std::pair<size_t, std::string> >::iterator i = set_.find(std::make_pair(x, s)); // copy of s is constructed by make_pair! return i != set_.end(); }
I call this function often (yes, very often), so I want to perform this check without making a temporary copy of the string. Is there a way to do this which is as simple and terse as what I have here, but which does not make a temporary copy of the string? Any solution with STL or Boost containers would be nice.