title: Transform an iterator on an unordered_map with pointer value type to an iterator on the same map with const reference value type
body: <p>I have the following class :</p>
  
  <pre><code>#include &lt;unordered_map&gt;
  #include &lt;memory&gt;
  
  
  class Node {
  public:
      typedef std::unique_ptr&lt;Node&gt; ptr_type;
      typedef std::unordered_map&lt;char, ptr_type&gt; map_type;
  
      typedef /**???**/ const_iterator;
  
      const_iterator begin() const;
      const_iterator end() const;
  
  private:
      map_type _children;
  };
  </code></pre>
  
  <p>As you can see, I want a way fo a user of this class to iterate over elements of <code>_children</code> without being able to modify them. That is why I want to create an iterator that point to elements of type <code>pair&lt;char, const Node&amp;&gt;</code> instead of <code>pair&lt;char, ptr_type&gt;</code>. </p>
  
  <p>Creating a base iterator class seems a little too complicated for the task at hand. I have taken a look at boost iterator, I think <code>transform_iterator</code> may be the way to go, but I have not yet found how to make it work. </p>
  
  <p>While I'm at it, does anyone know where I can find examples of the different examples of iterators defined in <code>boost-iterators</code> ? There is only one example in the doc for each type, and they do not always fit my needs (I'm new to this library, I may have missed something obvious).</p>
  
  <p><strong>UPDATE</strong>: Here is my attempt at using <code>boost::transform_iterator</code></p>
  
  <pre><code>class Node {
  public:
      typedef std::unique_ptr&lt;Node&gt; ptr_type;
      typedef std::unordered_map&lt;char, ptr_type&gt; map_type;
  
  
      struct Transformer {
          std::pair&lt;char, const Node&amp;&gt; operator()(const std::pair&lt;char, ptr_type&gt; &amp;p) const {
              return std::pair&lt;char, const Node&amp;&gt;(p.first, *p.second);
          }
      };
  
      typedef boost::transform_iterator&lt;Transformer, map_type::const_iterator, std::pair&lt;char, const Node&amp;&gt;&amp;, std::pair&lt;char, const Node&amp;&gt;&gt; const_iterator;
  
      const_iterator begin() const {
          return boost::make_transform_iterator&lt;Transformer, map_type::const_iterator&gt;(_children.begin(), Transformer());
      }
      const_iterator end() const {
          return boost::make_transform_iterator&lt;Transformer, map_type::const_iterator&gt;(_children.end(), Transformer());
      }
  
  private:
      map_type _children;
  };
  </code></pre>
  
  <p>It unfortunately does not compile, and gives the following error: </p>
  
  <pre><code>error: no type named ‘type’ in ‘boost::mpl::eval_if&lt;boost::is_same&lt;boost::iterators::use_default, boost::iterators::use_default&gt;, boost::result_of&lt;const Node::Transformer(const std::pair&lt;const char, std::unique_ptr&lt;Node&gt; &gt;&amp;)&gt;, boost::mpl::identity&lt;boost::iterators::use_default&gt; &gt;::f_ {aka struct boost::result_of&lt;const Node::Transformer(const std::pair&lt;const char, std::unique_ptr&lt;Node&gt; &gt;&amp;)&gt;}’
       typedef typename f_::type type;
  </code></pre>