#include <map>
#include <iostream>
#include <algorithm>
#include <stdexcept>

//functor
template<class key, class value>
struct finder {
    finder(const value& value_to_find) : v(&value_to_find){}
    bool operator()(const std::pair<const key&, value>& node) 
    {return node.second == *v;}
protected:
    const value* v;
};

template<class key, class value>
const key& find_key(const std::map<key, value>& container, const value& value_to_find) {
    typename std::map<key, value>::const_iterator it;
    it = std::find_if(container.begin(), container.end(), finder<key, value>(value_to_find));
    if (it == container.end())
        throw std::runtime_error("value is not in container!");
    return it->first;
}

int main() {
    std::map<int, int> container;
    container[3] = 7;
    std::cout << find_key(container, 7);
}