Listing 2: Function objects that use character traits

template <class traits>
struct traits_eq 
 : public std::binary_function<
     typename traits::char_type,
     typename traits::char_type,
     bool>
{
  typedef typename traits::char_type char_type;
  bool operator()(const char_type& x,
                  const char_type& y) const
    { return traits::eq(x, y); }
};

template <class traits>
struct traits_int_eq 
  : public std::binary_function<
      typename traits::char_type,
      typename traits::char_type,
      bool>
{
  typedef typename traits::int_type int_type;

  bool operator()(const int_type& x,
                  int_type& y) const
    { return traits::eq_int_type(x, y); }
};

template <class traits>
struct is_eof 
  : public std::unary_function<
      typename traits::int_type,
      bool>
{
public:
  is_eof() : eof(traits::eof()) { }

  typedef typename traits::int_type int_type;
  bool operator()(const int_type& c) const
    { return traits::eq_int_type(c, eof); }

private:
  int_type eof;
};
— End of Listing —