title: fake iterator operations for enumerating all the node values in a graph
body: <p>I'm trying to have a fake iterator for enumerating all the node values in a graph. The graph can be abstracted in any sequence, as long as the sequence consists of all and only the nodes in the graph. There should be a mutable qualifier, and the 4 operations' implementations are short and supposed to be only 1 line per function.</p>
  
  <p>The test case for the 4 fake iterator operations is as follow, it is supposed to print out a string of values of the graph nodes through the fake iterator operations:</p>
  
  <pre><code>gdwg::Graph&lt;std::string,int&gt;&gt; g
     for (g.begin(); !g.end(); g.next())
         std::cout &lt;&lt; g.value() &lt;&lt; std::end;
  </code></pre>
  
  <p>I declared the graph as the following:</p>
  
  <pre><code>template &lt;typename N, typename E&gt; class Graph {
  
  private:
      struct Node;
      struct Edge;
  
      struct Node {
          N val_;
          int numEdges_;
          int numIncomingEdges_;
          std::set&lt;std::shared_ptr&lt;Edge&gt;&gt; edges_;
          std::set&lt;std::shared_ptr&lt;Edge&gt;&gt; incomingEdges_;
          Node() {}
          Node(const N x) : val_{x} { numEdges_=0; numIncomingEdges_=0; }
          void printNode(N n);
          ~Node();
          void update();
      };
  
      struct Edge {
          std::weak_ptr&lt;Node&gt; orig;
          std::weak_ptr&lt;Node&gt; dest;
          E val_;
          Edge(std::shared_ptr&lt;Node&gt; o, std::shared_ptr&lt;Node&gt; d, E x);
          Edge() {};
          void printEdge();
          ~Edge();
      };
  
      // fake iterator operations
      void begin() const;
      bool end() const;
      void next() const;
      const N&amp; value() const;
  
  
  
  public:
  
      friend class Node_Iterator&lt;N, E&gt;;
      friend class Edge_Iterator&lt;N, E&gt;;
  
  
  private:
      std::map&lt; N, std::shared_ptr&lt;Node&gt; &gt; nodes_;
  
      // fake iterator to be used for the four operations begin(), end(), next() and value()
      mutable typename std::map&lt; N, std::shared_ptr&lt;Node&gt; &gt;::iterator fakeIter_;
  
  };
  </code></pre>
  
  <p>The implementation of the 4 operations are as follows:</p>
  
  <pre><code>// void begin() const: Sets an internal iterator, i.e., ``pointer'' to the first element of a sequence.
  template &lt;typename N, typename E&gt;
  void Graph&lt;N,E&gt;::begin() const {
      // gets iterator to the first key/value pair in map sequence
      fakeIter_ = nodes_.begin();
  }
  
  // bool end() const: Returns true if the iterator goes past the last element of the sequence and false otherwise.
  template &lt;typename N, typename E&gt;
  bool Graph&lt;N,E&gt;::end() const {
      // return true if iterator goes past last element, otherwise return false
      return ((fakeIter_ == nodes_.end()) ? true : false);
  }
  
  // void next() const: Moves the iterator to the next element of the sequence.
  template &lt;typename N, typename E&gt;
  void Graph&lt;N,E&gt;::next() const {
      fakeIter_ = std::next(fakeIter_, 1);
  }
  
  // const N&amp; value() const: Returns the value of the node pointed to by the iterator.
  template &lt;typename N, typename E&gt;
  const N&amp; Graph&lt;N,E&gt;::value() const {
      return fakeIter_-&gt;second-&gt;val_;
  }
  </code></pre>
  
  <p>When I try to compile, there is a bunch of errors popping up. I'm just wondering whether I'm implementing the fake iterator operations correctly and if there is any way to improve it if need be?</p>
  
  <pre><code>tests/Graph.tem: In instantiation of ‘void gdwg::Graph&lt;N, E&gt;::begin() const [with N = unsigned int; E = int]’:
  tests/test13.cpp:23:15:   required from here
  tests/Graph.tem:713:12: error: no match for ‘operator=’ (operand types are ‘std::map&lt;unsigned int, std::shared_ptr&lt;gdwg::Graph&lt;unsigned int, int&gt;::Node&gt;, std::less&lt;unsigned int&gt;, std::allocator&lt;std::pair&lt;const unsigned int, std::shared_ptr&lt;gdwg::Graph&lt;unsigned int, int&gt;::Node&gt; &gt; &gt; &gt;::iterator {aka std::_Rb_tree_iterator&lt;std::pair&lt;const unsigned int, std::shared_ptr&lt;gdwg::Graph&lt;unsigned int, int&gt;::Node&gt; &gt; &gt;}’ and ‘std::map&lt;unsigned int, std::shared_ptr&lt;gdwg::Graph&lt;unsigned int, int&gt;::Node&gt;, std::less&lt;unsigned int&gt;, std::allocator&lt;std::pair&lt;const unsigned int, std::shared_ptr&lt;gdwg::Graph&lt;unsigned int, int&gt;::Node&gt; &gt; &gt; &gt;::const_iterator {aka std::_Rb_tree_const_iterator&lt;std::pair&lt;const unsigned int, std::shared_ptr&lt;gdwg::Graph&lt;unsigned int, int&gt;::Node&gt; &gt; &gt;}’)
    fakeIter_ = nodes_.begin();
  
  In file included from /usr/local/include/c++/6.1.0/map:60:0,
                   from tests/Graph.h:19,
                   from tests/test13.cpp:3:
  /usr/local/include/c++/6.1.0/bits/stl_tree.h:174:12: note: candidate: constexpr std::_Rb_tree_iterator&lt;std::pair&lt;const unsigned int, std::shared_ptr&lt;gdwg::Graph&lt;unsigned int, int&gt;::Node&gt; &gt; &gt;&amp; std::_Rb_tree_iterator&lt;std::pair&lt;const unsigned int, std::shared_ptr&lt;gdwg::Graph&lt;unsigned int, int&gt;::Node&gt; &gt; &gt;::operator=(const std::_Rb_tree_iterator&lt;std::pair&lt;const unsigned int, std::shared_ptr&lt;gdwg::Graph&lt;unsigned int, int&gt;::Node&gt; &gt; &gt;&amp;)
       struct _Rb_tree_iterator
              ^~~~~~~~~~~~~~~~~
  /usr/local/include/c++/6.1.0/bits/stl_tree.h:174:12: note:   no known conversion for argument 1 from ‘std::map&lt;unsigned int, std::shared_ptr&lt;gdwg::Graph&lt;unsigned int, int&gt;::Node&gt;, std::less&lt;unsigned int&gt;, std::allocator&lt;std::pair&lt;const unsigned int, std::shared_ptr&lt;gdwg::Graph&lt;unsigned int, int&gt;::Node&gt; &gt; &gt; &gt;::const_iterator {aka std::_Rb_tree_const_iterator&lt;std::pair&lt;const unsigned int, std::shared_ptr&lt;gdwg::Graph&lt;unsigned int, int&gt;::Node&gt; &gt; &gt;}’ to ‘const std::_Rb_tree_iterator&lt;std::pair&lt;const unsigned int, std::shared_ptr&lt;gdwg::Graph&lt;unsigned int, int&gt;::Node&gt; &gt; &gt;&amp;’
  /usr/local/include/c++/6.1.0/bits/stl_tree.h:174:12: note: candidate: constexpr std::_Rb_tree_iterator&lt;std::pair&lt;const unsigned int, std::shared_ptr&lt;gdwg::Graph&lt;unsigned int, int&gt;::Node&gt; &gt; &gt;&amp; std::_Rb_tree_iterator&lt;std::pair&lt;const unsigned int, std::shared_ptr&lt;gdwg::Graph&lt;unsigned int, int&gt;::Node&gt; &gt; &gt;::operator=(std::_Rb_tree_iterator&lt;std::pair&lt;const unsigned int, std::shared_ptr&lt;gdwg::Graph&lt;unsigned int, int&gt;::Node&gt; &gt; &gt;&amp;&amp;)
  /usr/local/include/c++/6.1.0/bits/stl_tree.h:174:12: note:   no known conversion for argument 1 from ‘std::map&lt;unsigned int, std::shared_ptr&lt;gdwg::Graph&lt;unsigned int, int&gt;::Node&gt;, std::less&lt;unsigned int&gt;, std::allocator&lt;std::pair&lt;const unsigned int, std::shared_ptr&lt;gdwg::Graph&lt;unsigned int, int&gt;::Node&gt; &gt; &gt; &gt;::const_iterator {aka std::_Rb_tree_const_iterator&lt;std::pair&lt;const unsigned int, std::shared_ptr&lt;gdwg::Graph&lt;unsigned int, int&gt;::Node&gt; &gt; &gt;}’ to ‘std::_Rb_tree_iterator&lt;std::pair&lt;const unsigned int, std::shared_ptr&lt;gdwg::Graph&lt;unsigned int, int&gt;::Node&gt; &gt; &gt;&amp;&amp;’
  </code></pre>