View difference between Paste ID: ffEgrpf3 and NiPcHAXj
SHOW: | | - or go back to the newest paste.
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
};