Boost logo

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&lt;item, K, &amp;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