   Templates and classes
  Hi,I am having some confusion over some code I saw.   template <class F, class S>class value_equals {    private :   S second;   public :   value_equals(const S& s): second(s) { }   bool operator() (pair<const F, S> elem)   {   return elem.second == second;    }};How does this code exactly work ? How does "S" get resolved here ?  
  This looks like a function object designed to work with std::map (or similar container types). Probably in conjunction with algorithms from the algorithm header. Basically you specialize it for the key and value types you want for your container and initialize it with a value type. Then you can use the class as a function to see if the value of an item in the map is equal to the value you initialized it with. It would probably be more helpful to show an example than just explain it with words. int main(int, char **) {  std::map<std::string, int> my_map;  my_map["cow"] = 1;  my_map["pig"] = 7;  my_map["chicken"] = 5;  int count = std::count_if(my_map.begin(),   my_map.end(),   value_equals<std::string, int>(5));  std::cout << count << std::endl;    return 0;}See how I create a copy of a value_equals<> object and pass it to the std::count_if() function? In this case the type parameters I''m using are determined by what type parameters I use for the std::map. Because it returns true when the second part of the pair (the value half) is equal to the stored value in the function object, this code will report how many items in the map have the value 5. ;  It''s a template functor, which test for equivalence based on the second elements of a pair.When value_pair is instanced, you need to tell it the types F & S (first and second). 