Boost logo

Boost :

Subject: [boost] STL MAP Insertion and Updates ..!!
From: Rahul Mathur (srivmuk_at_[hidden])
Date: 2013-12-25 09:56:20


Hi,

Looking for clue for below. Having a code which has to be inserted and
updated with following status -

1. Insert with unique ID and initially with two values (viz . v1[1100] &
v2[1000])
2. If v1 [viz 1100] is NOT accepted exit.
3. Else value v2[1000] is accepted. With v2 being accepted, further insert
with same unique ID on which v2 was accepted but now either with three
values of v3[1001] or v4[1002] or v5[1003] and UPDATE the STL MAP.
4. Print the FINAL value (v2 or v3 or v5) of STL MAP with given unique ID.

Did wrote below lines which works until value v1 [1000] insertion -

---
#include <iostream>
#include <algorithm>
#include <map>
#include <iterator>
using namespace std;
struct TBag {
        int UnqID;
        short value_code;
        TBag():UnqID(1234),value_code(1000){}
};
TBag ms_var1;
typedef std::map<int, short> map1;
class Apple {
        map1 abc;
        public:
        void TypeInsert ( TBag *ms_var );
};
void Apple::TypeInsert ( TBag *ms_var )
{
 // Insert the 'UnqID' with messages of either TC = 1000 or 1100 only.
        typedef std::pair <map1::iterator, bool> itr;
        itr it1 = abc.insert( std::make_pair( ms_var->UnqID,
ms_var->value_code ) );
        typedef std::pair <map1::iterator, bool> itr;
       //Searching for value of Value Code = 1000
        if (ms_var->value_code == 1100) {
                std::cout << "Value Error." << endl;
                exit (1);
        }
        if (it1.second) { // Checking correct insertion happened with 1000
                std::cout << "Unq ID (" << it1.first->first << ") => " <<
                "Value Code (" << it1.first->second << ")" << endl;
                std::cout << "The Status is .." << it1.first->first << " &
" << it1.first->second << endl ;
               // INSERT now with Value code of either 1001 or 1002 or 1003
& finally UPDATE the STL MAP
                std::cout << "Final Status:" << endl ;
                for( map<int, short>::iterator iter = map1.begin(); iter !=
map1.end(); ++iter )
                        std::cout << iter->first << " " << iter->second <<
endl ;
                std::cout << "All Status successful." << endl;
        }
        else
                std::cout << "Status Error." << endl;
}
int main () {
        Apple ms;
        ms.TypeInsert( &ms_var1 );
return 0;
}
---
Any help is well appreciated ..:)
~ XoXo

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk