
#include <iostream>
#include <vector>
#include <string>
#include <unordered_map>

template<typename T>
class lookup {
  std::unordered_map<T, int> position;
public:
  lookup(const std::vector<T>& a) {
    for(int i = 0; i < a.size(); ++i) position.emplace(a[i], i);
  }
  int operator()(const T& key) const {
    auto pos = position.find(key);
    return pos == position.end() ? -1 : pos->second;
  }
};
 
template<typename T>
static lookup<T> make_lookup(const std::vector<T>& a) {
  return lookup<T>(a);
}

int main() {
  std::vector<std::string> foo{"a", "b", "d", "e", "g", "k", "m", "n", "r", "x"};
  auto find = make_lookup(foo);
  for(std::string key : {"g", "m", "p"}) {
    std::cout << find(key) << std::endl;
  }
  return 0;
}

