Ok, this is my code:
#include
#include
#include
#include
using namespace boost::multi_index;
template //K = Key, V = Value
class Ordered_Map
{
private:
struct mutable_pair
{
typedef K first_type;
typedef V second_type;
mutable_pair():first(K()),second(V()){}
mutable_pair(const K& f,const V&s):first(f),second(s){}
mutable_pair(const std::pair& p):first(p.first),second(p.second){}
K first;
mutable V second;
};
typedef multi_index_container<
mutable_pair,
indexed_by< random_access<>,
ordered_unique >
>
> container1;
container1 c;
mutable_pair *r;
public:
V& operator[]( const K& key )
{
r = new mutable_pair(key,V());
c.insert(c.end(),*r);
return (*r).second;
}
typename container1::const_iterator cbegin() const
{
return c.cbegin();
}
typename container1::const_iterator cend() const
{
return c.cend();
}
};
int main()
{
Ordered_Mapstd::string,int myMap;
myMap["Joe"] = 3;
myMap["Lillo"] = 9;
myMap["Mary"] = -3;
for (auto i = myMap.cbegin(); i != myMap.cend(); ++i)
std::cout << i->first << " - " << i->second << std::endl;
std::cin.get();
return 0;
}
I now correctly get two iterators, but in this class don't work the
assignment: my output is:
Joe - 0
Lillo - 0
Mary - 0
--
View this message in context: http://boost.2283326.n4.nabble.com/Container-with-insertion-order-tp4097717p...
Sent from the Boost - Users mailing list archive at Nabble.com.