title: get the rank of an element of a boost::multi_index container
body: <p>The code below shows a multi_index container which is indexed by sequence and order.</p>
  
  <p>In my use case elements will be mainly searched by index, and if existing, the next element (by order) is obtained.</p>
  
  <p>My question is, how to get the rank (by order) of obtained next element?</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;boost/multi_index_container.hpp&gt;
  #include &lt;boost/multi_index/sequenced_index.hpp&gt;
  #include &lt;boost/multi_index/ordered_index.hpp&gt;
  #include &lt;boost/multi_index/ranked_index.hpp&gt;
  #include &lt;boost/multi_index/identity.hpp&gt;
  
  using namespace boost::multi_index;
  
  typedef multi_index_container &lt;
      int
    , indexed_by&lt;
          sequenced&lt;&gt;
        , ordered_non_unique&lt;identity&lt;int&gt;&gt;
        , ranked_non_unique&lt;identity&lt;int&gt;&gt;
      &gt;
  &gt; Ints;
  
  int main() {
      Ints ints;
  
      auto &amp; sequence=ints.get&lt;0&gt;();
      auto &amp; order=ints.get&lt;1&gt;();
  
      sequence.push_back(2);
      sequence.push_back(-1);
      sequence.push_back(5);
      sequence.push_back(6);
  
      auto it = order.find(2);
      if (it!=order.end()) {
          std::cout
              &lt;&lt; "next to "
              &lt;&lt; *it
              &lt;&lt; " by sequence is "
              &lt;&lt; *(++(ints.project&lt;0&gt;(it)))
              &lt;&lt; std::endl
          ;
          std::cout
              &lt;&lt; "next to "
              &lt;&lt; *it
              &lt;&lt; " by order is "
              &lt;&lt; *(++(ints.project&lt;1&gt;(it))) //++it is good too
              &lt;&lt; std::endl
          ;
          std::cout
              &lt;&lt; "rank of next by sequence is "
              // &lt;&lt; ??? ints.rank&lt;???&gt;(???)
              &lt;&lt; std::endl
          ;
          std::cout
              &lt;&lt; "rank of next by order is "
              // &lt;&lt; ??? ints.rank&lt;???&gt;(???)
              &lt;&lt; std::endl
          ;
      }
  }
  </code></pre>