Advertisement
Guest User

QWEazrXTCYGVHBJN

a guest
Oct 10th, 2017
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.63 KB | None | 0 0
  1. #include <vector>
  2. #include <string>
  3. #include <utility>
  4. #include <algorithm>
  5.  
  6. class StaticMap {
  7. public:
  8.  
  9.     std::vector<std::pair<std::string, std::string>> all_items;
  10.  
  11.     explicit StaticMap(const std::vector<std::pair<std::string, std::string>>& items) {
  12.         all_items = items;
  13.         sort(all_items.begin(), all_items.end());
  14.     }
  15.  
  16.     bool Find(const std::string& key, std::string* value) const {
  17.         auto it = std::lower_bound(all_items.begin(), all_items.end(), key);
  18.         if (it != all_items.end()){
  19.             *value = (*it).second;
  20.             return true;
  21.         }
  22.         return false;
  23.     }
  24. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement