Boost logo

Boost Users :

From: Ramesh (rramesh1_at_[hidden])
Date: 2008-08-12 01:40:12


Hi.

I am using boost multi-index container for storing objects of type class A,
in the class key1 & Key 3 are unique and key2 is non-unique. I try to insert
objects of type A and it works fine. No issues.

At some point after the insertion, I wish to modify the key2 to 20 in the
container. Can I do this with modify? If yes How do I define the iterator
(since I need to do a find based on key1 but modify key2 in the container)

Here is the code snippet:

-----------

class A {
    private:
        std::string key1;
        long key2;
        long key3;

< Other class members >
};

struct DataMap {
    std::string key1;
    long key2;
    long key3;
      A *pObj;
};

typedef multi_index_container<
  DataMap,
    indexed_by<
        ordered_unique<
            tag <Key1>, BOOST_MULTI_INDEX_MEMBER(DataMap,std::string,Key1)>,
        ordered_non_unique<
                  tag<Key2>,BOOST_MULTI_INDEX_MEMBER(DataMap,long,Key2)>,

              ordered_unique<
                  tag<Key3>,BOOST_MULTI_INDEX_MEMBER(DataMap,long,Key3)>
>
> tDMap;

class myclass {

    private:

        tDMap Map;

    public:

        insert(std::string, long , long, A *);
};

myclass::insert(std::string key1, long key2, long key3, A *pObj) {

}

main() {
std::string key1 = "Test String";

A abc;

abc.key1 = key1;
abc.key2 = 10;
abc.key3 = 400;

insert(key1, key2, key3, &abc);

}
-------------------

Thanks in advance!
Ramesh



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