0

Here is a container of ints with a sequence index and a hashed index:

#include <iostream>
#include <boost/multi_index_container.hpp>
#include <boost/multi_index/hashed_index.hpp>
#include <boost/multi_index/identity.hpp>
#include <boost/multi_index/sequenced_index.hpp>

int main()
{
    namespace bmi = boost::multi_index;
    boost::multi_index_container<
        int,
        bmi::indexed_by<
            bmi::sequenced<>,
            bmi::hashed_unique<bmi::identity<int>>
        >
    > c;
    for (int i=0; i<100; ++i) c.push_back(i);
    for (int j : c) std::cout << " " << j;
    std::cout << std::endl;
    return 0;
}

Note I did not use get in the second loop. Is the behavior defined in this case? (E.g., "This is the same as using .get<0>()".)

John H.
  • 1,551
  • 1
  • 12
  • 18
  • Cannot reproduce, I do see different output on boost 1.70, please add which version of boost you are using – Slava Feb 25 '20 at 19:40
  • Here is wanbox live example for boost 1.72 https://wandbox.org/permlink/96OSdRxraauwNiKw – Slava Feb 25 '20 at 19:49
  • I believe I'm using 1.68.0. – John H. Feb 25 '20 at 21:17
  • 1
    I used link above from wandbox and changed to use gcc 7.3.0 and boost 1.68, still cannot reproduce your result. Looks like something is wrong on your side. – Slava Feb 25 '20 at 21:23
  • Your demonstration shows the result I was hoping for, so I consider this answered. Thanks very much! – John H. Feb 28 '20 at 02:13
  • @slava resolved the confusion I revealed in my original question, and there were no answers posted. So I have repurposed this to my real question, about "default indices". – John H. Mar 02 '20 at 22:04

1 Answers1

2

Yes, index #0 is the default in the sense explained here:

The functionality of index #0 can be accessed directly from a multi_index_container object without using get<0>(): for instance, es.begin() is equivalent to es.get<0>().begin().

Joaquín M López Muñoz
  • 5,243
  • 1
  • 15
  • 20