STL algorithm cannot access private member
<p>Apologize in advance for the amount of codes, but I can't find where the built error coming from.  This example built correctly on VC++ 6.0, but failed on the more recent compilers, including g++ and VC++ 2010.  The error message says error C2248: 'std::basic_ios&lt;_Elem,_Traits>::basic_ios' : cannot access private member declared in class 'std::basic_ios&lt;_Elem,_Traits>'  Help please.</p>

<pre><code>  #pragma warning( disable : 4786 )  
  #pragma warning( disable : 4996 )  

  #include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;algorithm&gt;
  #include &lt;vector&gt;
  #include &lt;list&gt;
  #include &lt;numeric&gt;
  #include &lt;iterator&gt;

  template&lt;class T&gt;
  class Criteria {
  public:
    Criteria(T match) : m_match(match) {

    }

    bool operator()(T match) {
        return (m_match == match);
    }
  private:
    T m_match;
  };

  template&lt;class T&gt;
  class BinaryCriteria {
  public:
    bool operator()(T item1, T item2) {
        return (item1*item1 &gt; item2+item2);
    }
  };

  std::ostream&amp; operator&lt;&lt;(std::ostream&amp; o, std::string rhs) {
    return (o &lt;&lt; rhs.c_str());
  }

  void print( int x ) {
    std::cout &lt;&lt; x &lt;&lt; " ";
  }

  template&lt;class T&gt;
  class Print {
  public:
    Print(const char* sep) : m_sep(sep) {
    }
    void operator()(T item) {
        std::cout &lt;&lt; item &lt;&lt; m_sep.c_str();
    }
  private:
    std::string m_sep;
  };

  template&lt;class T&gt;
  class Equal {
  public:

    bool operator()(T item1, T item2) {
        return (item1 * 2 == item2);
    }
  };

  template&lt;class T&gt;
  class File {
  public:
    File(const char* file) {
        m_in.open(file);
    }
    ~File() {
        if (m_in)
            m_in.close();
    }
    T operator()() {
        m_in.getline(m_buf, sizeof(m_buf));
        T line = m_buf;
        return line;
    }
  private:
    std::ifstream m_in;
    char m_buf[80];
  };

  template&lt;class T&gt;
  class Odd {
  public:
    bool operator()(T item) {
        if (item % 2 != 0)
            return false;
        else
            return true;
    }
  };

  template&lt;class T&gt;
  class Upper {
  public:
    T operator()(T item) {
        std::transform(item.begin(),item.end(),item.begin(),::toupper);
        return item;
    }
  };

  template&lt;class T&gt;
  class Concat {
  public:
    Concat(const char* sep) : m_sep(sep) {

    }
    T operator()(T item1, T item2) {
        T out;
        out = item1;
        out += m_sep;
        out += item2;
        return out;
    }
  private:
    std::string m_sep;
  };

  template&lt;class T&gt;
  class TheSame {
  public:
    bool operator()(T item1, T item2) {
        if (item1 * 10 == item2)
            return true;
        else
            return false;
    }
  };

  template&lt;class T&gt;
  class Rand {
  public:
    T operator()() {
        return static_cast&lt;T&gt;(::rand());
    }
  };

  struct Employee {
    Employee(std::string name, std::string dept, std::string id) :
          m_name(name), m_dept(dept), m_id(id) {
    }
    std::string m_name;
    std::string m_dept;
    std::string m_id;
  };

  class SortByName {
  public:
    bool operator()(const Employee* lhs, const Employee* rhs) {
        int res = ::strcmp(lhs-&gt;m_name.c_str(),rhs-&gt;m_name.c_str());
        if (res == -1)
            return true;
        else
            return false;
    }
  };

  class SortByDept {
  public:
    bool operator()(const Employee* lhs, const Employee* rhs) {
        int res = ::strcmp(lhs-&gt;m_dept.c_str(),rhs-&gt;m_dept.c_str());
        if (res == -1)
            return true;
        else
            return false;
    }
  };

  class SortById {
  public:
    bool operator()(const Employee* lhs, const Employee* rhs) {
        int res = ::strcmp(lhs-&gt;m_id.c_str(),rhs-&gt;m_id.c_str());
        if (res == -1)
            return true;
        else
            return false;
    }
  };

  std::ostream&amp; operator&lt;&lt;(std::ostream&amp; o, const Employee* rhs) {
    o &lt;&lt; rhs-&gt;m_name &lt;&lt; "," &lt;&lt; rhs-&gt;m_dept &lt;&lt; "," &lt;&lt; rhs-&gt;m_id;
    return o;
  }

  int main(int argc, char* argv[]) {

  if (false)    {

            std::vector&lt;int&gt; v;
            for (int i=0; i&lt;10; i++)
                v.push_back(i);

            std::vector&lt;int&gt;::iterator ifind = std::find(v.begin(), v.end(), -4);
            if (ifind != v.end())
                std::cout &lt;&lt; "Item found " &lt;&lt; *ifind &lt;&lt; std::endl;
            else 
                std::cout &lt;&lt; "Item was not found" &lt;&lt; std::endl;

            ifind = std::find_if(v.begin(), v.end(), Criteria&lt;int&gt;(4));
            if (ifind != v.end())
                std::cout &lt;&lt; "Item found " &lt;&lt; *ifind &lt;&lt; std::endl;
            else 
                std::cout &lt;&lt; "Item was not found" &lt;&lt; std::endl;
    }

  if (false)    {

            std::vector&lt;int&gt; v;
            for (int i=0; i&lt;10; i++)
                v.push_back(i);
            v[4] = 5; // create an adjacent pair

            std::vector&lt;int&gt;::iterator ifind = std::adjacent_find(v.begin(), v.end());
            if (ifind != v.end())
                std::cout &lt;&lt; "Items found " &lt;&lt; *ifind &lt;&lt; " " &lt;&lt; *(ifind+1) &lt;&lt; std::endl;
            else 
                std::cout &lt;&lt; "Items were not found" &lt;&lt; std::endl;

            v[4] = 4; // create an adjacent pair
            ifind = std::adjacent_find(v.begin(), v.end(), BinaryCriteria&lt;int&gt;());
            if (ifind != v.end())
                std::cout &lt;&lt; "Items found " &lt;&lt; *ifind &lt;&lt; " " &lt;&lt; *(ifind+1) &lt;&lt; std::endl;
            else 
                std::cout &lt;&lt; "Items were not found" &lt;&lt; std::endl;
    }

  if (false)    {

            std::vector&lt;int&gt; v;
            for (int i=0; i&lt;10; i++)
                v.push_back(i);
            v[3] = 3;
            v[7] = 3; // some duplicates

            std::cout &lt;&lt; "The item " &lt;&lt; 2 &lt;&lt; " appears " 
                      &lt;&lt; std::count( v.begin(), v.end(), 2) 
                      &lt;&lt; " times" &lt;&lt; std::endl;

            std::cout &lt;&lt; "The item " &lt;&lt; 3 &lt;&lt; " appears " 
                      &lt;&lt; std::count_if( v.begin(), v.end(), Criteria&lt;int&gt;(3)) 
                      &lt;&lt; " times" &lt;&lt; std::endl;

    }

  if (false)    {

            std::vector&lt;int&gt; v;
            for (int i=0; i&lt;10; i++)
                v.push_back(i);

            std::for_each(v.begin(), v.end(), Print&lt;int&gt;(" "));
            std::cout &lt;&lt; std::endl;
            std::for_each(v.begin(), v.end(), print);
            std::cout &lt;&lt; std::endl;
    }   

  if (false)    {

            std::vector&lt;int&gt; v;
            for (int i=0; i&lt;10; i++)
                v.push_back(i);
            int tab[3] = { 0, 1, 2 };

            bool res = std::equal(tab, tab+3, v.begin());
            if (res)
                std::cout &lt;&lt; "Ranges are equal" &lt;&lt; std::endl;
            else
                std::cout &lt;&lt; "Ranges are not equal" &lt;&lt; std::endl;


            v[0] = 2 * tab[0];
            v[1] = 2 * tab[1];
            v[2] = 2 * tab[2];
            res = std::equal(tab, tab+3, v.begin(), Equal&lt;int&gt;());
            if (res)
                std::cout &lt;&lt; "Ranges are equal" &lt;&lt; std::endl;
            else
                std::cout &lt;&lt; "Ranges are not equal" &lt;&lt; std::endl;

            res = std::equal(tab, tab+3, v.begin());
            if (res)
                std::cout &lt;&lt; "Ranges are equal" &lt;&lt; std::endl;
            else
                std::cout &lt;&lt; "Ranges are not equal" &lt;&lt; std::endl;

            res = std::equal(tab, tab+3, &amp;v[5], Equal&lt;int&gt;());
            if (res)
                std::cout &lt;&lt; "Ranges are equal" &lt;&lt; std::endl;
            else
                std::cout &lt;&lt; "Ranges are not equal" &lt;&lt; std::endl;

    }   

  if (false)    {

            std::vector&lt;int&gt; v;
            for (int i=0; i&lt;10; i++)
                v.push_back(i);
            int tab[6] = { 0, 1, 2, 4, 5, 6 };

            std::pair&lt;int*, std::vector&lt;int&gt;::iterator&gt; res =
                std::mismatch(tab, tab+6, v.begin() );
            if (res.first != (tab+6)) {
                std::cout &lt;&lt; "mismatch located " 
                    &lt;&lt; "item in first range " &lt;&lt; *res.first &lt;&lt;
                       " item in second range " &lt;&lt; *res.second &lt;&lt; std::endl;
            } else
                std::cout &lt;&lt; "No mismatch found within the range" &lt;&lt; std::endl;

            v[0] = 2 * tab[0];
            v[1] = 2 * tab[1];
            v[2] = 2 * tab[2];
            tab[3] = -99;
            res = std::mismatch(tab, tab+6, v.begin(), Equal&lt;int&gt;() );
            if (res.first != (tab+6)) {
                std::cout &lt;&lt; "mismatch located " 
                    &lt;&lt; "item in first range " &lt;&lt; *res.first &lt;&lt;
                       " item in second range " &lt;&lt; *res.second &lt;&lt; std::endl;
            } else
                std::cout &lt;&lt; "No mismatch found within the range" &lt;&lt; std::endl;

    }   

  if (false)    {

            std::vector&lt;int&gt; v;
            for (int i=0; i&lt;10; i++)
                v.push_back(i);
            int tab[3] = { 4, 5, 6 };

            std::vector&lt;int&gt;::iterator res = std::search(v.begin(), v.end(), tab, tab+3);
            if (res != v.end())
                std::cout &lt;&lt; "Subsequence located - first item = " &lt;&lt; *res &lt;&lt; std::endl;
            else
                std::cout &lt;&lt; "Subsequence not located" &lt;&lt; std::endl;

            tab[0] = 2 * v[5];
            tab[1] = 2 * v[6];
            tab[2] = 2 * v[7];
            // predicate function version
            res = std::search(v.begin(), v.end(), tab, tab+3, Equal&lt;int&gt;());
            if (res != v.end())
                std::cout &lt;&lt; "Subsequence located - first item = " &lt;&lt; *res &lt;&lt; std::endl;
            else
                std::cout &lt;&lt; "Subsequence not located" &lt;&lt; std::endl;

    }

  if (false)    {

            std::vector&lt;int&gt; v(10);
            int tab[10] = { 10, 20, 30, 40, 50, 60, 70, 80, 90, 100 };
            std::copy(tab,tab+10,v.begin());
            std::for_each(v.begin(),v.end(),Print&lt;int&gt;(" "));
            std::cout &lt;&lt; std::endl;

            std::copy_backward(tab,tab+10,v.end());
            std::for_each(v.begin(),v.end(),Print&lt;int&gt;(" "));
            std::cout &lt;&lt; std::endl;

            std::vector&lt;char&gt; v2;
            const char* str = "ABCDEFGHIJ";
            std::copy(str,str+10,std::back_inserter(v2));

            std::cout &lt;&lt; "Before shift left" &lt;&lt; std::endl;
            std::for_each(v2.begin(),v2.end(),Print&lt;char&gt;(""));
            std::cout &lt;&lt; std::endl;

            std::copy(v2.begin()+1, v2.end(), v2.begin());

            std::cout &lt;&lt; "After shift left" &lt;&lt; std::endl;
            std::for_each(v2.begin(),v2.end(),Print&lt;char&gt;(""));
            std::cout &lt;&lt; std::endl;

            std::copy(str,str+10,v2.begin());

            std::cout &lt;&lt; "Before shift right" &lt;&lt; std::endl;
            std::for_each(v2.begin(),v2.end(),Print&lt;char&gt;(""));
            std::cout &lt;&lt; std::endl;

            std::copy_backward(v2.begin(), v2.end()-1, v2.end());

            std::cout &lt;&lt; "After shift right" &lt;&lt; std::endl;
            std::for_each(v2.begin(),v2.end(),Print&lt;char&gt;(""));
            std::cout &lt;&lt; std::endl;

    }

  if (false)    {

            std::vector&lt;int&gt; v(10);
            std::fill(v.begin(),v.end(),-5);
            std::for_each(v.begin(),v.end(),Print&lt;int&gt;(" "));
            std::cout &lt;&lt; std::endl;

            std::fill_n(v.begin(),10,-5);
            std::for_each(v.begin(),v.end(),Print&lt;int&gt;(" "));
            std::cout &lt;&lt; std::endl;

    }

  if (false)    {

            std::vector&lt;std::string&gt; v(10);

            std::generate(v.begin(),v.end(),File&lt;std::string&gt;("c:/temp/items.txt"));
            std::for_each(v.begin(),v.end(),Print&lt;std::string&gt;("\n"));
            std::cout &lt;&lt; std::endl;

    }

  if (false)    {
            std::vector&lt;int&gt; v;
            for(int i=0; i&lt;10; i++)
                v.push_back(i);
            std::vector&lt;int&gt;::iterator res =
                std::partition(v.begin(),v.end(),Odd&lt;int&gt;());

            // display each range
            std::cout &lt;&lt; "first range ";
            std::for_each(v.begin(),res,Print&lt;int&gt;(" "));
            std::cout &lt;&lt; std::endl;

            std::cout &lt;&lt; "second range ";
            std::for_each(res,v.end(),Print&lt;int&gt;(" "));
            std::cout &lt;&lt; std::endl;

            // repeat for stable_partition
            for(int i=0; i&lt;10; i++)
                v[i]=i;
            res = std::stable_partition(v.begin(),v.end(),Odd&lt;int&gt;());

            // display each range
            std::cout &lt;&lt; "first range ";
            std::for_each(v.begin(),res,Print&lt;int&gt;(" "));
            std::cout &lt;&lt; std::endl;

            std::cout &lt;&lt; "second range ";
            std::for_each(res,v.end(),Print&lt;int&gt;(" "));
            std::cout &lt;&lt; std::endl;

            // repeat using STL components
            for(int i=0; i&lt;10; i++)
                v[i]=i;
            res = std::partition(v.begin(),v.end(),
                std::bind2nd(  std::greater&lt;int&gt;(),  2));

            // display each range
            std::cout &lt;&lt; "first range ";
            std::for_each(v.begin(),res,Print&lt;int&gt;(" "));
            std::cout &lt;&lt; std::endl;

            std::cout &lt;&lt; "second range ";
            std::for_each(res,v.end(),Print&lt;int&gt;(" "));
            std::cout &lt;&lt; std::endl;

            // repeat using STL components
            for(int i=0; i&lt;10; i++)
                v[i]=i;
            res = std::partition(v.begin(),v.end(),
                std::bind1st(  std::greater&lt;int&gt;(),  2));

            // display each range
            std::cout &lt;&lt; "first range ";
            std::for_each(v.begin(),res,Print&lt;int&gt;(" "));
            std::cout &lt;&lt; std::endl;

            std::cout &lt;&lt; "second range ";
            std::for_each(res,v.end(),Print&lt;int&gt;(" "));
            std::cout &lt;&lt; std::endl;

    }

  if (false)    {
            // random_shuffle randomly rearranges the items in a range.
            std::vector&lt;int&gt; v;
            for(int i=0; i&lt;100; i++)
                v.push_back(i);
            std::random_shuffle(v.begin(),v.end());
            std::copy(v.begin(),v.end(),
                std::ostream_iterator&lt;int&gt;(std::cout," "));
            std::cout &lt;&lt; std::endl;

    }

  if (false)    {
            int buf[10] = { 2, 5, 3, 5, 4, 5, 6, 6, 5, 5 };

            int* res = std::remove(buf, buf+10, 5);

            std::cout &lt;&lt; "items to keep ";
            std::copy(buf, res, std::ostream_iterator&lt;int&gt;(std::cout," "));
            std::cout &lt;&lt; std::endl;

            std::cout &lt;&lt; "items to remove ";
            std::copy(res, buf+10, std::ostream_iterator&lt;int&gt;(std::cout," "));
            std::cout &lt;&lt; std::endl;

            // test with vector
            std::vector&lt;int&gt; v;
            for(int i=0; i&lt;10; i++)
                v.push_back(i);

            std::cout &lt;&lt; "size of v before call to remove " &lt;&lt; v.size() &lt;&lt; std::endl;
            std::vector&lt;int&gt;::iterator p = std::remove(v.begin(), v.end(), 5);
            std::cout &lt;&lt; "size of v after call to remove " &lt;&lt; v.size() &lt;&lt; std::endl;

            v.erase(p);
            std::cout &lt;&lt; "size of v after erase " &lt;&lt; v.size() &lt;&lt; std::endl;
            std::copy(v.begin(), v.end(), std::ostream_iterator&lt;int&gt;(std::cout," "));
            std::cout &lt;&lt; std::endl;

    }

  if (false)    {
            int buf[10] = { 2, 5, 3, 5, 4, 5, 6, 6, 5, 5 };
            std::copy(buf, buf+10, std::ostream_iterator&lt;int&gt;(std::cout," "));
            std::cout &lt;&lt; std::endl;
            std::replace(buf, buf+10, 5, 0);
            std::copy(buf, buf+10, std::ostream_iterator&lt;int&gt;(std::cout," "));
            std::cout &lt;&lt; std::endl;

    }

  if (false)    {
            // The reverse algorithm reverses the order of the items in a given range.
            int buf[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };

            std::cout &lt;&lt; "Before reverse ";
            std::copy(buf, buf+10, std::ostream_iterator&lt;int&gt;(std::cout," "));
            std::cout &lt;&lt; std::endl;

            std::reverse(buf, buf+10);

            std::cout &lt;&lt; "After reverse ";
            std::copy(buf, buf+10, std::ostream_iterator&lt;int&gt;(std::cout," "));
            std::cout &lt;&lt; std::endl;

    }

  if (false)    {
            int buf[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };

            std::cout &lt;&lt; "Before rotate ";
            std::copy(buf, buf+10, std::ostream_iterator&lt;int&gt;(std::cout," "));
            std::cout &lt;&lt; std::endl;

            std::rotate(buf, buf+4, buf+10);

            std::cout &lt;&lt; "After rotate ";
            std::copy(buf, buf+10, std::ostream_iterator&lt;int&gt;(std::cout," "));
            std::cout &lt;&lt; std::endl;

    }

  if (false)    {
            // The swap function swaps to values
            std::string first="Hello";
            std::string second="World";
            std::cout &lt;&lt; first &lt;&lt; " " &lt;&lt; second &lt;&lt; std::endl;
            std::swap(first,second);
            std::cout &lt;&lt; first &lt;&lt; " " &lt;&lt; second &lt;&lt; std::endl;

            // The swap_ranges function swaps ranges.
            std::list&lt;std::string&gt; ll;
            ll.push_front("Homer");
            ll.push_front("Marge");
            ll.push_front("Bart");

            std::vector&lt;std::string&gt; vec;
            vec.push_back("Moe");
            vec.push_back("Wiggum");
            vec.push_back("Burns");

            std::swap_ranges(ll.begin(),ll.end(),vec.begin());

            std::cout &lt;&lt; "List values ";
            std::for_each(ll.begin(),ll.end(),Print&lt;std::string&gt;(" "));
            std::cout &lt;&lt; std::endl;

            std::cout &lt;&lt; "Vector values ";
            std::for_each(vec.begin(),vec.end(),Print&lt;std::string&gt;(" "));
            std::cout &lt;&lt; std::endl;

    }

  if (false)    {
            std::vector&lt;std::string&gt; v(3);
            std::list&lt;std::string&gt; ll;
            ll.push_front("Homer");
            ll.push_front("Marge");
            ll.push_front("Bart");
            std::transform(ll.begin(),ll.end(),v.begin(),Upper&lt;std::string&gt;());
            std::cout &lt;&lt; "Uppercase names ";
            std::for_each(v.begin(),v.end(),Print&lt;std::string&gt;(" "));
            std::cout &lt;&lt; std::endl;

            std::list&lt;std::string&gt; ll2;
            ll2.push_front("Simpson");
            ll2.push_front("Simpson");
            ll2.push_front("Simpson");
            std::transform(ll.begin(),ll.end(),ll2.begin(),v.begin(),Concat&lt;std::string&gt;(" "));
            std::cout &lt;&lt; "Concat'ed names ";
            std::for_each(v.begin(),v.end(),Print&lt;std::string&gt;("\n"));
            std::cout &lt;&lt; std::endl;

            int a[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
            int b[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
            int c[10];
            std::transform(a,a+10,b,c,std::plus&lt;int&gt;());
            std::for_each(c,c+10,Print&lt;int&gt;(" "));
            std::cout &lt;&lt; std::endl;

            std::transform(a,a+10,c,std::bind2nd(std::plus&lt;int&gt;(),10));
            std::for_each(c,c+10,Print&lt;int&gt;(" "));
            std::cout &lt;&lt; std::endl;


    }

  if (false)    {
            int tab[10] = { 1, 2, 2, 3, 4, 4, 5, 6, 6, 7 };
            int* res = std::unique(tab, tab+10);

            std::cout &lt;&lt; "Unique items ";
            std::for_each(tab,res,Print&lt;int&gt;(" "));
            std::cout &lt;&lt; std::endl;

            // Binary predicate function version.
            int tab2[10] = { 1, 2, 20, 3, 4, 40, 5, 6, 60, 7 };
            res = std::unique(tab2, tab2+10, TheSame&lt;int&gt;());

            std::cout &lt;&lt; "Unique items ";
            std::for_each(tab2,res,Print&lt;int&gt;(" "));
            std::cout &lt;&lt; std::endl;

            int tab3[10] = { 1, 2, 20, 3, 4, 40, 5, 6, 60, 7 };
            res = std::unique(tab3, tab3+10);

            std::cout &lt;&lt; "Unique items ";
            std::for_each(tab3,res,Print&lt;int&gt;(" "));
            std::cout &lt;&lt; std::endl;

    }

  if (false)    {

            int tab[10];

            // initialize
            std::generate(tab,tab+10,Rand&lt;int&gt;());

            std::cout &lt;&lt; "Unsorted sequence ";
            std::for_each(tab,tab+10,Print&lt;int&gt;(" "));
            std::cout &lt;&lt; std::endl;

            std::sort(tab,tab+10,std::less&lt;int&gt;());

            std::cout &lt;&lt; "Sorted ascending order sequence ";
            std::for_each(tab,tab+10,Print&lt;int&gt;(" "));
            std::cout &lt;&lt; std::endl;

            // initialize
            std::generate(tab,tab+10,Rand&lt;int&gt;());

            std::cout &lt;&lt; "Unsorted sequence ";
            std::for_each(tab,tab+10,Print&lt;int&gt;(" "));
            std::cout &lt;&lt; std::endl;

            std::sort(tab,tab+10,std::greater&lt;int&gt;());

            std::cout &lt;&lt; "Sorted descending order sequence ";
            std::for_each(tab,tab+10,Print&lt;int&gt;(" "));
            std::cout &lt;&lt; std::endl;

            // customize the sort criteria
            std::vector&lt;Employee*&gt; v;
            v.push_back( new Employee("EEE", "Dept AAA", "Id100") );
            v.push_back( new Employee("CCC", "Dept BBB", "Id500") );
            v.push_back( new Employee("BBB", "Dept DDD", "Id300") );
            v.push_back( new Employee("FFF", "Dept CCC", "Id600") );
            v.push_back( new Employee("AAA", "Dept CCC", "Id200") );
            v.push_back( new Employee("DDD", "Dept AAA", "Id000") );

            std::cout &lt;&lt; "Unsorted employees " &lt;&lt; std::endl;
            std::for_each(v.begin(),v.end(),Print&lt;Employee*&gt;("\n"));
            std::cout &lt;&lt; std::endl;

            // sort by name
            std::sort(v.begin(),v.end(),SortByName());

            std::cout &lt;&lt; "Sorted employees by name " &lt;&lt; std::endl;
            std::for_each(v.begin(),v.end(),Print&lt;Employee*&gt;("\n"));
            std::cout &lt;&lt; std::endl;

            // sort by id
            std::sort(v.begin(),v.end(),SortById());

            std::cout &lt;&lt; "Sorted employees by id " &lt;&lt; std::endl;
            std::for_each(v.begin(),v.end(),Print&lt;Employee*&gt;("\n"));
            std::cout &lt;&lt; std::endl;

            // sort by dept
            std::sort(v.begin(),v.end(),SortByDept());

            std::cout &lt;&lt; "Sorted employees by dept " &lt;&lt; std::endl;
            std::for_each(v.begin(),v.end(),Print&lt;Employee*&gt;("\n"));
            std::cout &lt;&lt; std::endl;


            // sort by name, the by dept
            std::sort(v.begin(),v.end(),SortByName());
            std::stable_sort(v.begin(),v.end(),SortByDept());
            std::cout &lt;&lt; "Sorted employees by name then stable sorted by dept " &lt;&lt; std::endl;
            std::for_each(v.begin(),v.end(),Print&lt;Employee*&gt;("\n"));
            std::cout &lt;&lt; std::endl;


            // initialize
            std::generate(tab,tab+10,Rand&lt;int&gt;());

            std::cout &lt;&lt; "Unsorted sequence " &lt;&lt; std::endl;
            std::for_each(tab,tab+10,Print&lt;int&gt;(" "));
            std::cout &lt;&lt; std::endl;

            std::partial_sort(tab,tab+3,tab+10,std::greater&lt;int&gt;());

            std::cout &lt;&lt; "Partially sorted (top 3) in descending order sequence " &lt;&lt; std::endl;
            std::for_each(tab,tab+10,Print&lt;int&gt;(" "));
            std::cout &lt;&lt; std::endl;

            double salaries[10] = { 22000.0, 28500.00, 17500.00, 22000.0, 54000.00,
                77500.00, 18400.00, 100000.00, 23000.0, 50000.0 };
            std::nth_element(salaries, salaries+2, salaries+10, std::less&lt;double&gt;());
            std::cout &lt;&lt; "The 3rd top salary is " &lt;&lt; salaries[2] &lt;&lt; std::endl;
            std::cout &lt;&lt; std::endl;

            }

  if (false)    {

            std::vector&lt;int&gt; keys;
            for (int i=0; i&lt;100; i++)
                keys.push_back(i);
            std::sort(keys.begin(), keys.end(), std::less&lt;int&gt;());

            // is item 55 in the sequence?
            bool isThere = std::binary_search(keys.begin(), keys.end(), int(55));
            if (isThere)
                std::cout &lt;&lt; "The key 55 is in the sequence" &lt;&lt; std::endl;
            else
                std::cout &lt;&lt; "The key 55 is not in the sequence" &lt;&lt; std::endl;

            // is item 555 in the sequence?
            isThere = std::binary_search(keys.begin(), keys.end(), int(555));
            if (isThere)
                std::cout &lt;&lt; "The key 555 is in the sequence" &lt;&lt; std::endl;
            else
                std::cout &lt;&lt; "The key 555 is not in the sequence" &lt;&lt; std::endl;

            }

  if (false)    {

            std::list&lt;float&gt; ll;
            ll.push_front(70.0f);
            ll.push_front(60.0f);
            ll.push_front(50.0f);
            ll.push_front(30.0f);
            ll.push_front(20.0f);
            ll.push_front(10.0f);
            std::list&lt;float&gt;::iterator iter = 
                std::lower_bound(ll.begin(), ll.end(), 40.0f);
            ll.insert(iter, 40.0f);
            std::for_each(ll.begin(), ll.end(), Print&lt;float&gt;(" "));
            std::cout &lt;&lt; std::endl;

            std::list&lt;float&gt; ll2;
            ll2.push_front(70.0f);
            ll2.push_front(60.0f);
            ll2.push_front(50.0f);
            ll2.push_front(30.0f);
            ll2.push_front(20.0f);
            ll2.push_front(10.0f);
            std::list&lt;float&gt;::iterator iter2 = 
                std::upper_bound(ll2.begin(), ll2.end(), 40.0f);
            ll2.insert(iter2, 40.0f);
            std::for_each(ll2.begin(), ll2.end(), Print&lt;float&gt;(" "));
            std::cout &lt;&lt; std::endl;

            std::list&lt;float&gt; ll3;
            ll3.push_front(70.0f);
            ll3.push_front(60.0f);
            ll3.push_front(50.0f);
            ll3.push_front(30.0f);
            ll3.push_front(20.0f);
            ll3.push_front(10.0f);
            std::pair&lt; std::list&lt;float&gt;::iterator, std::list&lt;float&gt;::iterator &gt; res =
                std::equal_range(ll3.begin(), ll3.end(), 40.0f);
            std::cout &lt;&lt; *res.first &lt;&lt; " " &lt;&lt; *res.second &lt;&lt; std::endl;
            std::cout &lt;&lt; std::endl;

            }


  if (false)    {
        int tab1[5] = { 10, 20, 30, 40, 50 };
        int tab2[5] = { 5, 15, 25, 35, 45 };
        int tab3[10];
        std::merge(tab1,tab1+5,tab2,tab2+5,tab3);
        std::cout &lt;&lt; "The merged list ";
        std::for_each(tab3,tab3+10,Print&lt;int&gt;(" "));
        std::cout &lt;&lt; std::endl;

        int tab4[10] = { 10, 20, 30, 40, 50, 5, 15, 25, 35, 45 };
        std::inplace_merge(tab4,tab4+5,tab4+10);
        std::cout &lt;&lt; "The in-place merged list ";
        std::for_each(tab4,tab4+10,Print&lt;int&gt;(" "));
        std::cout &lt;&lt; std::endl;

    }

  if (false)    {
        // The set algorithms allows set operations on sorted sequences.
        int tab1[5] = { 10, 20, 30, 40, 50 };
        int tab2[5] = { 10, 25, 30, 45, 50 };
        int tab3[10];

        // union
        int* p = std::set_union(tab1,tab1+5,tab2,tab2+5,tab3);
        std::cout &lt;&lt; "Union ";
        std::for_each(tab3,p,Print&lt;int&gt;(" "));
        std::cout &lt;&lt; std::endl;

        // intersection
        p = std::set_intersection(tab1,tab1+5,tab2,tab2+5,tab3);
        std::cout &lt;&lt; "Intersection ";
        std::for_each(tab3,p,Print&lt;int&gt;(" "));
        std::cout &lt;&lt; std::endl;

        // difference
        p = std::set_difference(tab1,tab1+5,tab2,tab2+5,tab3);
        std::cout &lt;&lt; "Difference ";
        std::for_each(tab3,p,Print&lt;int&gt;(" "));
        std::cout &lt;&lt; std::endl;

        // symmetric difference
        p = std::set_symmetric_difference(tab1,tab1+5,tab2,tab2+5,tab3);
        std::cout &lt;&lt; "Symmetric difference ";
        std::for_each(tab3,p,Print&lt;int&gt;(" "));
        std::cout &lt;&lt; std::endl;

        int tab4[3] = { 20, 30, 40 };
        bool res = std::includes(tab1,tab1+5,tab4,tab4+3);
        if (res)
            std::cout &lt;&lt; "Located the sequence in tab4 within tab1" &lt;&lt; std::endl;
        else
            std::cout &lt;&lt; "The sequence in tab4 is not located within tab1" &lt;&lt; std::endl;

    }

  if (true) {

        int tab[10] = { 2, 4, 6, 1, 3, 5, 8, 7, 9, 100 };
        int* p = std::min_element(tab,tab+10);
        std::cout &lt;&lt; "Min value = " &lt;&lt; *p &lt;&lt; std::endl;

        p = std::max_element(tab,tab+10);
        std::cout &lt;&lt; "Max value = " &lt;&lt; *p &lt;&lt; std::endl;

    }



    return 0;
  }
</code></pre>
