Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. ATL / WTL / STL
  4. Feature of STL map

Feature of STL map

Scheduled Pinned Locked Moved ATL / WTL / STL
tutorialc++
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    ra_sasi
    wrote on last edited by
    #1

    Hi, In IBM open class library,we have a class called IKeySet which has to be replaced by map in STL as per IBM migration guide.But in eh IKeySet we have a provision to add an elelemnt with key as well as an element.(this feature it inherited from ICollection class which is equivalent to list or deque in STL). I am trying in vain to have this type with map also but dint succeed. Can you guys give some idea as how to implement this.That would pull me out of this soup.. Thanks Sasi

    V 1 Reply Last reply
    0
    • R ra_sasi

      Hi, In IBM open class library,we have a class called IKeySet which has to be replaced by map in STL as per IBM migration guide.But in eh IKeySet we have a provision to add an elelemnt with key as well as an element.(this feature it inherited from ICollection class which is equivalent to list or deque in STL). I am trying in vain to have this type with map also but dint succeed. Can you guys give some idea as how to implement this.That would pull me out of this soup.. Thanks Sasi

      V Offline
      V Offline
      valikac
      wrote on last edited by
      #2

      Explain what you meant by "add an elelemnt with key as well as an element." Kuphryn

      L 1 Reply Last reply
      0
      • V valikac

        Explain what you meant by "add an elelemnt with key as well as an element." Kuphryn

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        Infact IKeyset inherited the feautures of ICollection( which is like list) and IAKeySet(its like map).SO we can add the elements of both with key (like in map)as well as just the element(liek in list). Hope this will suffice.Please look at the code below #include #include #include #include #include using namespace std; typedef const string& CIR; typedef enum { IEArgString, IEArgNumber, IEArgSpecial } IEArgType; class IEArg { public: //* Element name and value and embedded datatype. string name; string value; IEArgType dataType; //* Default constructor given name and value. IEArg(CIR n, CIR v) : name(n), value(v) { dataType = IEArgString; } IEArg(CIR n, CIR v, IEArgType t) : name(n), value(v), dataType(t) { } friend bool operator<(const IEArg& lhs, const IEArg& rhs); }; inline bool operator<(const IEArg& lhs, const IEArg& rhs) { if (lhs.name == rhs.name && lhs.value == rhs.value) return FALSE; else return TRUE; } typedef map IEArgList; inline CIR key(const IEArg& iea) { return iea.name; } typedef deque < IEArg > IEOArgList; typedef deque < IEOArgList > SUMMARY; main() { int days=10; IEArgList al; string where; string nam="1235"; string val="12"; // Maps and multimaps deal with pairs typedef pair entry; entry p0("Time",IEArg("1100","A")); entry p1("Time",IEArg("1234","A")); entry p2("Transaction",IEArg("4567","D")); entry p4("xransaction",IEArg("2345","B")); entry p3("ResultCode",IEArg("5678","C")); al.insert(p0); al.insert(p1); al.insert(p2); al.insert(p4); al.insert(p3); /******** I want add just IEArgList just liek a collection with out key ********/ IEArgList::iterator iter; for (iter = al.begin(); iter != al.end(); iter++) { cout<<"values are:"<<(*iter).first<<":"<<(*iter).second.value<<":"<<(*iter).second.name<

        V P 2 Replies Last reply
        0
        • L Lost User

          Infact IKeyset inherited the feautures of ICollection( which is like list) and IAKeySet(its like map).SO we can add the elements of both with key (like in map)as well as just the element(liek in list). Hope this will suffice.Please look at the code below #include #include #include #include #include using namespace std; typedef const string& CIR; typedef enum { IEArgString, IEArgNumber, IEArgSpecial } IEArgType; class IEArg { public: //* Element name and value and embedded datatype. string name; string value; IEArgType dataType; //* Default constructor given name and value. IEArg(CIR n, CIR v) : name(n), value(v) { dataType = IEArgString; } IEArg(CIR n, CIR v, IEArgType t) : name(n), value(v), dataType(t) { } friend bool operator<(const IEArg& lhs, const IEArg& rhs); }; inline bool operator<(const IEArg& lhs, const IEArg& rhs) { if (lhs.name == rhs.name && lhs.value == rhs.value) return FALSE; else return TRUE; } typedef map IEArgList; inline CIR key(const IEArg& iea) { return iea.name; } typedef deque < IEArg > IEOArgList; typedef deque < IEOArgList > SUMMARY; main() { int days=10; IEArgList al; string where; string nam="1235"; string val="12"; // Maps and multimaps deal with pairs typedef pair entry; entry p0("Time",IEArg("1100","A")); entry p1("Time",IEArg("1234","A")); entry p2("Transaction",IEArg("4567","D")); entry p4("xransaction",IEArg("2345","B")); entry p3("ResultCode",IEArg("5678","C")); al.insert(p0); al.insert(p1); al.insert(p2); al.insert(p4); al.insert(p3); /******** I want add just IEArgList just liek a collection with out key ********/ IEArgList::iterator iter; for (iter = al.begin(); iter != al.end(); iter++) { cout<<"values are:"<<(*iter).first<<":"<<(*iter).second.value<<":"<<(*iter).second.name<

          V Offline
          V Offline
          valikac
          wrote on last edited by
          #4

          Essentially, you want to store an into sorted container, correct? In your example, you are storing it inside a map and requires key/value. One solution is a set. Kuphryn

          1 Reply Last reply
          0
          • L Lost User

            Infact IKeyset inherited the feautures of ICollection( which is like list) and IAKeySet(its like map).SO we can add the elements of both with key (like in map)as well as just the element(liek in list). Hope this will suffice.Please look at the code below #include #include #include #include #include using namespace std; typedef const string& CIR; typedef enum { IEArgString, IEArgNumber, IEArgSpecial } IEArgType; class IEArg { public: //* Element name and value and embedded datatype. string name; string value; IEArgType dataType; //* Default constructor given name and value. IEArg(CIR n, CIR v) : name(n), value(v) { dataType = IEArgString; } IEArg(CIR n, CIR v, IEArgType t) : name(n), value(v), dataType(t) { } friend bool operator<(const IEArg& lhs, const IEArg& rhs); }; inline bool operator<(const IEArg& lhs, const IEArg& rhs) { if (lhs.name == rhs.name && lhs.value == rhs.value) return FALSE; else return TRUE; } typedef map IEArgList; inline CIR key(const IEArg& iea) { return iea.name; } typedef deque < IEArg > IEOArgList; typedef deque < IEOArgList > SUMMARY; main() { int days=10; IEArgList al; string where; string nam="1235"; string val="12"; // Maps and multimaps deal with pairs typedef pair entry; entry p0("Time",IEArg("1100","A")); entry p1("Time",IEArg("1234","A")); entry p2("Transaction",IEArg("4567","D")); entry p4("xransaction",IEArg("2345","B")); entry p3("ResultCode",IEArg("5678","C")); al.insert(p0); al.insert(p1); al.insert(p2); al.insert(p4); al.insert(p3); /******** I want add just IEArgList just liek a collection with out key ********/ IEArgList::iterator iter; for (iter = al.begin(); iter != al.end(); iter++) { cout<<"values are:"<<(*iter).first<<":"<<(*iter).second.value<<":"<<(*iter).second.name<

            P Offline
            P Offline
            Paul Ranson
            wrote on last edited by
            #5

            I can't understand what your code is supposed to be doing. Why not describe your basic data structures and what this collection is supposed to be used for? You obviously cannot make a map or a set of a type and then store things that are not actually instances of that type in the map or set. FWIW when you reply with code if you check the little box after the text box it will display the template definitions directly and not require us to 'view source' and generally mess about. Paul

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups