// Example 13-39: Making pairs of objects.
#include <algorithm>
#include <iostream>
#include <limits>
#include <map>
#include <ostream>
#include <string>
#include <utility>
#include <vector>

// Functor, suitable for passing to for_each to find
// minimum and maximum values in a range.
template<typename T>
class minmax
{
public:
  minmax() : min_(std::numeric_limits<T>::max()),
             max_(std::numeric_limits<T>::min())
             {}
  void operator()(const T& x) {
    if (x < min_) min_ = x;
    if (max_ < x) max_ = x;
  }
  operator std::pair<T,T>() const {
    return std::make_pair(min_, max_);
  }
private:
  T min_;
  T max_;
};

int main()
{
  std::map<std::string, int> wordcounts;
  wordcounts.insert(std::make_pair("hello", 1));

  std::vector<int> v;
  // fill v with data
  std::pair<int,int> mm =
    std::for_each(v.begin(), v.end(), minmax<int>());
  // do something with mm
}
