|
Boost Users : |
Subject: Re: [Boost-users] Container with insertion order
From: Igor R (boost.lists_at_[hidden])
Date: 2011-11-28 05:31:43
> template<typename K,typename V>
> class Ordered_Map
> {
> private:
> Â Â Â Â struct item
> Â Â Â Â {
> Â Â Â Â item(K k,V v) : first(k),second(v)
> Â Â Â Â {}
> Â Â Â Â Â Â Â Â K first;
> Â Â Â Â Â Â Â Â V second;
> Â Â Â Â };
>
> Â Â Â Â typedef multi_index_container<
> Â Â Â Â item,
> Â Â Â Â indexed_by< random_access<>,
> Â Â Â Â Â Â Â Â Â Â ordered_unique<member<item, K, &item::first> >
> Â Â Â Â >
> Â Â > container;
>
> Â Â Â Â container c;
>
> public:
>
> Â Â Â V operator[](const K& key)
> Â Â Â Â {
>
> Â Â Â Â Â Â Â Â c.insert(c.end(), item(key,2));
>
> Â Â Â Â Â Â Â Â return (??);
> Â Â Â Â }
> Â Â Â Â void begin()
> Â Â Â Â {
>
> Â Â Â Â Â Â Â Â //for (container::const_iterator i = c.begin(); i != c.end(); ++i)
> Â Â Â Â Â Â Â Â //std::cout << i->first << " - " << i->second << std::endl;
> Â Â Â Â }
> };
>
> I have some problems; The operator[] is not yet complete.
Have you red the link I posted:
http://www.boost.org/doc/libs/1_48_0/libs/multi_index/doc/tutorial/techniques.html#emulate_assoc_containers
> But the real problem is the begin() method, it should return a
> container::const_iterator, but if I use the signature: *container::const_iterator begin()*
> {
> Â return c.begin();
> }
>
> I get an error :-(
Maybe you try to return the iterator of the second index? Note that
container::const_iterator is the iterator of the 1st index.
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net