I need to overload the [] operator for boost::multi_index_container. It would look like something like this :
template<typename T>
using my_set = boost::multi_index_container<
T,
boost::multi_index::indexed_by<
boost::multi_index::sequenced<>,
boost::multi_index::ordered_unique<boost::multi_index::identity<T>>
>
>;
template<typename T>
T operator[](const my_set &s, const size_t &t){
auto it=s.get<0>.begin();
advance(it, t);
return *it;
}
I tried but I get this error :
error: ‘T operator[](boost::multi_index::multi_index_container<T, boost::multi_index::indexed_by<boost::multi_index::sequenced<>, boost::multi_index::ordered_unique<boost::multi_index::identity<Value> > > >&, int&)’ must be a nonstatic member function
\> &s, int &t){
Is there any way I can do this ?
I want to do this because I had a vector and I need to insert unique elements in it. I used find to know if the element was already in my vector then inserted it if it wasn't. But the linear complexity of find on a vector bothered me, I thought of using a set but I want to keep the elements in the insertion order.
Using a multi_index_container allows me to keep the insertion index with s.get<0> but will also allow me to have unique elements in it
I hope everything's clear.