Domanda

I've got a boost multi_index_container storing a bunch of locations with the following index

boost::multi_index::indexed_by<
    boost::multi_index::ordered_unique<
            boost::multi_index::tag<Slot>,
            boost::multi_index::identity<SlotData>
        >,  //ordered_unique
    boost::multi_index::ordered_non_unique<
            boost::multi_index::tag<Level>,
            SlotData::ExtractZ
        >,  // ordered_non_unique
...//index by
.//typedef as SlotLocations

In this definition, I believe the default index will be by ordered_unique based on Slot. Later on I have an iterator SlotLocations::iterator that I want to use to store the result from a search based on Level which is ordered_non_unique:

typedef SlotLocations::index<Level>::iterator MIterator;

std::pair<MIterator, MIterator> range = map.get<Level>().range(..some conds..);

SlotLocations::iterator itr = range.first;    //error

The ranged search works and return the desired result stored in range, however this code won't compile with the lined marked giving the following error:

error: no match for 'operator='

Why can't I assign/store the iterators like this? And what's the possible ways to store the search result iterator?

È stato utile?

Soluzione

You have to project the iterators across indices

It should be like

 SlotLocations::iterator itr = project<Slot>(map, range.first);

Altri suggerimenti

As for your second question on why projection is not done automatically through implicit conversions: in fact the reason is not the one suggested by @sehe (all indices are different even if untagged, and their iterators are guaranteedly different types), but this: projection is done through an expression like

it1 =  c.project<X>(it0); // X is either a tag or an index number

which needs the user to provide the container both iterators belong to: that is, you cannot (in general) convert from it0 to it1 with the information held by it0 alone.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top