title: boost multi index access to hashed unique index
body: <p>This code is adopted from the boost multi-index "mru" example:</p>
  
  <p><a href="http://www.boost.org/doc/libs/1_46_1/libs/multi_index/example/serialization.cpp" rel="nofollow">http://www.boost.org/doc/libs/1_46_1/libs/multi_index/example/serialization.cpp</a></p>
  
  <p>I have code that is doing something similiar as a boost::unordered_map, but I would really like to add the mru functionality from this example.</p>
  
  <p>I would like to make this code work as close to having a boost::unordered_map as possible. The key feature for me is the [] operator of the unordered_map.</p>
  
  <p>The final lines of main() are broken and above each line as a comment is my question.</p>
  
  <p>Thanks in advance to all answers comments.</p>
  
  <pre><code>#include &lt;algorithm&gt;
  #include &lt;boost/multi_index_container.hpp&gt;
  #include &lt;boost/multi_index/hashed_index.hpp&gt;
  #include &lt;boost/multi_index/identity.hpp&gt;
  #include &lt;boost/multi_index/sequenced_index.hpp&gt;
  #include &lt;iostream&gt;
  
  using namespace boost::multi_index;
  
  class my_struct {
  public:
      my_struct(int in_a, std::string in_b) : a(in_a), b(in_b) {}
  
      int a;
      std::string b;
  
      bool operator==(const my_struct &amp;rhs) const
      {
          return (a == rhs.a);
      }
      bool operator!=(const my_struct &amp;rhs) const
      {
              return !(*this == rhs);
      }
  
      friend std::ostream&amp; operator&lt;&lt;(std::ostream &amp;out, const my_struct&amp;ms);
  };
  
  std::ostream&amp; operator&lt;&lt;(std::ostream &amp;out, my_struct &amp;ms)
  {
      out &lt;&lt; ms.a &lt;&lt; " " &lt;&lt; ms.b &lt;&lt; std::endl;
      return out;
  }
  
  inline std::size_t
  hash_value(const my_struct &amp;val)
  {
      return boost::hash_value(val.a);
  }
  
  // tags for multi_index
  struct umap {};
  template &lt;typename Item&gt;
  class mru_list
  {
    typedef multi_index_container&lt;
      Item,
      indexed_by&lt;
        sequenced&lt;&gt;,
        hashed_unique&lt;boost::multi_index::tag&lt;umap&gt;, identity&lt;Item&gt; &gt;
      &gt;
    &gt; item_list;
  
  public:
  
    typedef Item                         item_type;
    typedef typename item_list::iterator iterator;
  
    mru_list(std::size_t max_num_items_):max_num_items(max_num_items_){}
  
    void insert(const item_type&amp; item)
    {
      std::pair&lt;iterator,bool&gt; p=il.push_front(item);
  
      if(!p.second){                     /* duplicate item */
        il.relocate(il.begin(),p.first); /* put in front */
      }
      else if(il.size()&gt;max_num_items){  /* keep the length &lt;= max_num_items */
        il.pop_back();
      }
    }
  
    iterator begin(){return il.begin();}
    iterator end(){return il.end();}
  
  //private:
    item_list   il;
    std::size_t max_num_items;
  };
  
  int main()
  {
      mru_list&lt;my_struct&gt; mru(10);
      my_struct one(1, "One");
  
      mru.insert(one);
      mru.insert(my_struct(2, "Two"));
      mru.insert(my_struct(3, "Three"));
      mru.insert(one);
  
      std::cout&lt;&lt;"most recently entered terms:"&lt;&lt;std::endl;
      for (mru_list&lt;my_struct&gt;::iterator itr = mru.begin(); itr != mru.end(); ++itr) {
          std::cout &lt;&lt; itr-&gt;a &lt;&lt; std::endl;
      }
  
      // what is my return type?
      mru.il.get&lt;umap&gt;();
  
      // Why doesn't this work?
      mru_list&lt;my_struct&gt;::iterator itr = mru.il.get&lt;umap&gt;().find(one);
  
      // Why doesn't this have a [] operator like boost:unordered_map
      mru.il.get&lt;umap&gt;()[1] = "foobar";
  
      return 0;
  }
  </code></pre>