title: Using my custom iterator with STL algorithms
body: <p>I'm trying to create my own iterator, and I've got it working as expected with the std::generate algorithm. However, when I try std::max_element of std::find, I get some cryptic errors.</p>
  <p>Here is the interface for my iterator:</p>
  <pre><code>template &lt;typename GridT,
            typename GridPtr,
            typename GridRef,
            template &lt;typename&gt; class ShapeT&gt;
  class GridIterator
  {
  public:
      typedef GridIterator&lt;GridT, GridPtr, GridRef, ShapeT&gt; Iterator;
  
      // Iterator traits - typedefs and types required to be STL compliant
      typedef std::ptrdiff_t           difference_type;
      typedef typename GridT::Element  value_type;
      typedef typename GridT::Element* pointer;
      typedef typename GridT::Element&amp; reference;
      typedef size_t                      size_type;
      std::forward_iterator_tag          iterator_category;
  
  
      GridIterator(GridT&amp; grid,
                   ShapeT&lt;typename GridT::Resolution&gt; shape,
                   Index iterStartIndex);
  
      ~GridIterator();
  
      Iterator&amp; operator++();
      Iterator  operator++(int);
  
      typename GridT::Element&amp; operator*();
      typename GridT::Element* operator-&gt;();
  
      bool operator!=(const GridIterator&amp; rhs) const;
      bool operator==(const GridIterator&amp; rhs) const;
      ....
  </code></pre>
  <p>}</p>
  <p>Using std::find, I get this error:</p>
  <blockquote>
  <p>In file included from /usr/include/c++/4.6/algorithm:63:0,
  from ./grid/Map_Grid.h:11,
  from main.cpp:4: /usr/include/c++/4.6/bits/stl_algo.h: In function ‘_IIter
  std::find(_IIter, _IIter, const _Tp&amp;) [with _IIter =
  Map::GridIterator&lt;Map::Grid&lt;double, int&gt;, Map::Grid&lt;double, int&gt;<em>,
  Map::Grid&lt;double, int&gt;&amp;, Map::Rectangle&gt;, _Tp = int]’:
  main.cpp:103:50:   instantiated from here
  /usr/include/c++/4.6/bits/stl_algo.h:4404:45: error: no matching
  function for call to
  ‘__iterator_category(Map::GridIterator&lt;Map::Grid&lt;double, int&gt;,
  Map::Grid&lt;double, int&gt;</em>, Map::Grid&lt;double, int&gt;&amp;, Map::Rectangle&gt;&amp;)’
  /usr/include/c++/4.6/bits/stl_algo.h:4404:45: note: candidate is:
  /usr/include/c++/4.6/bits/stl_iterator_base_types.h:202:5: note:
  template typename std::iterator_traits::iterator_category
  std::__iterator_category(const _Iter&amp;)</p>
  </blockquote>
  <p>With std::max_element :</p>
  <blockquote>
  <p>In file included from /usr/include/c++/4.6/bits/char_traits.h:41:0,
  from /usr/include/c++/4.6/ios:41,
  from /usr/include/c++/4.6/ostream:40,
  from /usr/include/c++/4.6/iostream:40,
  from ./grid/Map_GridIterator.h:7,
  from ./grid/Map_Grid.h:8,
  from main.cpp:4: /usr/include/c++/4.6/bits/stl_algobase.h: In function ‘const _Tp&amp;
  std::max(const _Tp&amp;, const _Tp&amp;) [with _Tp =
  Map::GridIterator&lt;Map::Grid&lt;double, int&gt;, Map::Grid&lt;double, int&gt;<em>,
  Map::Grid&lt;double, int&gt;&amp;, Map::Rectangle&gt;]’: main.cpp:102:60:
  instantiated from here /usr/include/c++/4.6/bits/stl_algobase.h:215:7:
  error: no match for ‘operator&lt;’ in ‘__a &lt; __b’
  /usr/include/c++/4.6/bits/stl_algobase.h:215:7: note: candidates are:
  /usr/include/c++/4.6/bits/stl_pair.h:207:5: note: template&lt;class _T1,
  class _T2&gt; constexpr bool std::operator&lt;(const std::pair&lt;_T1, _T2&gt;&amp;,
  const std::pair&lt;_T1, _T2&gt;&amp;)
  /usr/include/c++/4.6/bits/stl_iterator.h:291:5: note: template bool std::operator&lt;(const std::reverse_iterator&lt;_Iterator&gt;&amp;, const
  std::reverse_iterator&lt;_Iterator&gt;&amp;)
  /usr/include/c++/4.6/bits/stl_iterator.h:341:5: note: template&lt;class
  _IteratorL, class _IteratorR&gt; bool std::operator&lt;(const std::reverse_iterator&lt;_IteratorL&gt;&amp;, const
  std::reverse_iterator&lt;_IteratorR&gt;&amp;)
  /usr/include/c++/4.6/bits/stl_iterator.h:1049:5: note: template&lt;class
  _IteratorL, class _IteratorR&gt; bool std::operator&lt;(const std::move_iterator&lt;_IteratorL&gt;&amp;, const
  std::move_iterator&lt;_IteratorR&gt;&amp;)
  /usr/include/c++/4.6/bits/stl_iterator.h:1055:5: note: template bool std::operator&lt;(const std::move_iterator&lt;_Iterator&gt;&amp;, const std::move_iterator&lt;_Iterator&gt;&amp;)
  /usr/include/c++/4.6/bits/basic_string.h:2510:5: note: template&lt;class
  _CharT, class _Traits, class _Alloc&gt; bool std::operator&lt;(const std::basic_string&lt;_CharT, _Traits, _Alloc&gt;&amp;, const
  std::basic_string&lt;_CharT, _Traits, _Alloc&gt;&amp;)
  /usr/include/c++/4.6/bits/basic_string.h:2522:5: note: template&lt;class
  _CharT, class _Traits, class _Alloc&gt; bool std::operator&lt;(const std::basic_string&lt;_CharT, _Traits, _Alloc&gt;&amp;, const _CharT</em>)
  /usr/include/c++/4.6/bits/basic_string.h:2534:5: note: template&lt;class
  _CharT, class _Traits, class _Alloc&gt; bool std::operator&lt;(const _CharT*, const std::basic_string&lt;_CharT, _Traits, _Alloc&gt;&amp;) /usr/include/c++/4.6/bits/stl_vector.h:1290:5: note: template&lt;class
  _Tp, class _Alloc&gt; bool std::operator&lt;(const std::vector&lt;_Tp, _Alloc&gt;&amp;, const std::vector&lt;_Tp, _Alloc&gt;&amp;) /usr/include/c++/4.6/tuple:586:5: note: template&lt;class ... _TElements,
  class ... _UElements&gt; bool std::operator&lt;(const std::tuple&lt;_TElements
  ...&gt;&amp;, const std::tuple&lt;_Elements ...&gt;&amp;)</p>
  </blockquote>