// FunctorDemo.cpp
#include <iostream>
#include <map>
#include <string>
#include <algorithm>
#include <functional>
using namespace std;
template<class C>
struct value_eq : public binary_function<typename C::value_type, typename C::value_type::second_type, bool>
{
typedef typename binary_function<typename C::value_type, typename C::value_type::second_type, bool>::result_type
result_type;
typedef typename binary_function<typename C::value_type, typename C::value_type::second_type, bool>::first_argument_type
first_argument_type;
typedef typename binary_function<typename C::value_type, typename C::value_type::second_type, bool>::second_argument_type
second_argument_type;
result_type operator()( first_argument_type value, second_argument_type s ) const {
return value.second == s;
}
};
int main()
{
map<string, string> v;
v["A"] = "ABC";
v["B"] = "BCD";
v["C"] = "CDE";
v["D"] = "DEF";
map<string, string>::iterator it;
it = find_if(v.begin(), v.end(), bind2nd(value_eq< map<string, string> >(), "CDE"));
if (it != v.end()) {
cout << "Key found: " << (*it).
first << endl;
}
}