title: The C++ STL function find() doesn't accept the iterator arguments of a user-defined class
body: <p>When I pass user-defined iterator arguments in std::find(), the GCC 5.2.1. compiler (on Ubuntu 15.10) gives two error messages:</p>
  
  <p>(1) </p>
  
  <blockquote>
    <p>/usr/include/c++/5/bits/stl_algo.h:162:34: error: no matching 
    function for call to ‘__iterator_category(Text_iterator&amp;)’<br>
    std::__iterator_category(__first));</p>
  </blockquote>
  
  <p>(2) </p>
  
  <blockquote>
    <p>/usr/include/c++/5/bits/stl_iterator_base_types.h:204:5: error:  no
    type named ‘iterator_category’ in ‘struct std::iterator_traits’</p>
  </blockquote>
  
  <p>The error is caused by the line <code>auto p = find(first, last, first_char);</code>, which is inside the find_txt() function. When the line is commented out, the code compiles seamlessly. Here's the code excerpt that causes the errors:</p>
  
  <pre><code>#include "std_lib_facilities.h"//from B. Stroustrup's site
  
  using Line = vector&lt;char&gt;;
  
  class Text_iterator {
  
      list&lt;Line&gt;::iterator ln; //points to lines
      Line::iterator pos; //points to characters
  
      public: 
      Text_iterator(list&lt;Line&gt;::iterator ll, Line::iterator pp)
          :ln{ll}, pos{pp} { }
      char&amp; operator*() { return *pos; }
      Text_iterator&amp; operator++();
      bool operator==(const Text_iterator&amp; other) const
          { return ln==other.ln &amp;&amp; pos==other.pos; }
      bool operator!=(const Text_iterator&amp; other) const
          { return !(*this==other); }
  };
  
  Text_iterator&amp; Text_iterator::operator++()
  {
      ++pos;
      if (pos==(*ln).end()) {
      ++ln;
      pos = (*ln).begin();
  }
      return *this;
  }
  
  Text_iterator find_txt(Text_iterator first, Text_iterator last, const string&amp; s)
  {
      if (s.size()==0) return last;// can’t find an empty stringchar first_char = s[0];
      char first_char = s[0];
      while (true) {
          auto p = find(first, last, first_char); //&lt;------------the PROBLEM!!!!!!
          //if (p==last || match(p,last,s)) return p;
          //first = ++p;// look at the next character
      }
  }
  
  void ex6()
  {
      ;
  }
  
  
  int main()
  {
      ex6();
  }
  </code></pre>
  
  <p>I referred to the files mentioned in the error messages: </p>
  
  <pre><code>template&lt;typename _Iterator, typename _Predicate&gt;
      inline _Iterator
      __find_if(_Iterator __first, _Iterator __last, _Predicate __pred)
      {
          return __find_if(__first, __last, __pred,
          std::__iterator_category(__first)); //this is line #162 in stl_algo.h
      }
  </code></pre>
  
  <p>and</p>
  
  <pre><code>template&lt;typename _Iter&gt;
      inline typename iterator_traits&lt;_Iter&gt;::iterator_category
      __iterator_category(const _Iter&amp;)//this is line #204 in stl_iterator_base_types.h
      { return typename iterator_traits&lt;_Iter&gt;::iterator_category(); }
  </code></pre>
  
  <p>Does the problem lie in <code>auto p = find(first, last, first_char);</code> or in those two GCC library files—that is, stl_algo.h and stl_iterator_base_types.h? What could be the possible ways to handle it?</p>
  
  <p>I was preparing code for doing exercise 6, Chapter 20 of Stroustrup's <em>Programming: Principles and Practice Using C++</em>, 2nd Ed. and got stuck here. The search on the Internet for std::find() problems has been to no avail. None of the questions referred to the iterator arguments to this funtion.</p>