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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. std::map but with multiple values for one key?

std::map but with multiple values for one key?

Scheduled Pinned Locked Moved C / C++ / MFC
c++dockerquestion
6 Posts 3 Posters 1 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.
  • C Offline
    C Offline
    Cyrilix
    wrote on last edited by
    #1

    I'm wondering if there is a way to use the STL map class in such a way that you pass in, say, 4 parameters, the first being a key, and the other 3 being values of any type. What I mainly want is an associative container that is not limited to key/value pair. Thanks.

    CPalliniC M 2 Replies Last reply
    0
    • C Cyrilix

      I'm wondering if there is a way to use the STL map class in such a way that you pass in, say, 4 parameters, the first being a key, and the other 3 being values of any type. What I mainly want is an associative container that is not limited to key/value pair. Thanks.

      CPalliniC Online
      CPalliniC Online
      CPallini
      wrote on last edited by
      #2

      This is easy achieved using an object (e.g. a vector) as the template type of the map. :)

      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

      In testa che avete, signor di Ceprano?

      C 1 Reply Last reply
      0
      • CPalliniC CPallini

        This is easy achieved using an object (e.g. a vector) as the template type of the map. :)

        If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

        C Offline
        C Offline
        Cyrilix
        wrote on last edited by
        #3

        Hmm... now why didn't I think about that... I like it. :) Thanks.

        1 Reply Last reply
        0
        • C Cyrilix

          I'm wondering if there is a way to use the STL map class in such a way that you pass in, say, 4 parameters, the first being a key, and the other 3 being values of any type. What I mainly want is an associative container that is not limited to key/value pair. Thanks.

          M Offline
          M Offline
          Michael Sadlon
          wrote on last edited by
          #4

          There is multi_map and multi_hash_map.

          C 1 Reply Last reply
          0
          • M Michael Sadlon

            There is multi_map and multi_hash_map.

            C Offline
            C Offline
            Cyrilix
            wrote on last edited by
            #5

            AFAIK, a multi-map is a map, but the keys do not have to be unique. I haven't checked the hash map though.

            M 1 Reply Last reply
            0
            • C Cyrilix

              AFAIK, a multi-map is a map, but the keys do not have to be unique. I haven't checked the hash map though.

              M Offline
              M Offline
              Michael Sadlon
              wrote on last edited by
              #6

              Multiple-key map Maps are a kind of associative containers that stores elements formed by the combination of a key value and a mapped value, much like map containers, but allowing different elements to have the same key value. From: http://www.cplusplus.com/reference/stl/multimap/[^] It should let you store multiple values per key, which is what you said you wanted. I've never used it myself, but it doesn't look much harder than a normal map. multi_hash_map is just the hash_map version of it :) It exists in the stdex namespace in the VC++ compiler only. Hope it helps!

              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