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. C / C++ / MFC
  4. how to typedef array of 4 char to be used in map template

how to typedef array of 4 char to be used in map template

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialdata-structures
27 Posts 3 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.
  • L Lost User

    Alternatively you could use a union?

    const struct ESDID
    {
    union
    {
    char c[4];
    uint32_t i;
    } x;
    bool operator< (const ESDID e) const { return x.i < e.x.i; }
    };

    F Offline
    F Offline
    ForNow
    wrote on last edited by
    #17

    thanks richard I dont see in the map documentation when using the insert method with key of type struct '<' operator must be overloaded by the user

    C 1 Reply Last reply
    0
    • F ForNow

      thanks richard I dont see in the map documentation when using the insert method with key of type struct '<' operator must be overloaded by the user

      C Offline
      C Offline
      CPallini
      wrote on last edited by
      #18

      Actually there is (see std::map - cppreference.com[^]):

      template<
      class Key,
      class T,
      class Compare = std::less,
      class Allocator = std::allocator>

      class map;

      As it should be, because the std::map is a sorted container.

      "In testa che avete, Signor di Ceprano?" -- Rigoletto

      F 1 Reply Last reply
      0
      • F ForNow

        I understand the compare wont work correctly however what I dont see where the cast operator () is being used> Is dynamic cast used with pair i.e <> the same as the () operator ()

        C Offline
        C Offline
        CPallini
        wrote on last edited by
        #19

        The cast is used here:

        pair(s1.symesdid, s1)

        The compiler:

        "Map's key must be a uint32_t, hence s1.symesdid, being an ESDID, does NOT fit. Let's see if there is a suitable cast..."

        "In testa che avete, Signor di Ceprano?" -- Rigoletto

        1 Reply Last reply
        0
        • C CPallini

          Actually there is (see std::map - cppreference.com[^]):

          template<
          class Key,
          class T,
          class Compare = std::less,
          class Allocator = std::allocator>

          class map;

          As it should be, because the std::map is a sorted container.

          "In testa che avete, Signor di Ceprano?" -- Rigoletto

          F Offline
          F Offline
          ForNow
          wrote on last edited by
          #20

          That’s not the way the map template is defined by Microsoft map Class | Microsoft Learn[^]

          C 1 Reply Last reply
          0
          • F ForNow

            That’s not the way the map template is defined by Microsoft map Class | Microsoft Learn[^]

            C Offline
            C Offline
            CPallini
            wrote on last edited by
            #21

            cppreference.com:

            template<
            class Key,
            class T,
            class Compare = std::less,
            class Allocator = std::allocator>

            class map;

            Microsoft:

            template ,
            class Allocator=allocator>>
            class map;

            Do you see significant differences?

            "In testa che avete, Signor di Ceprano?" -- Rigoletto

            F 1 Reply Last reply
            0
            • C CPallini

              cppreference.com:

              template<
              class Key,
              class T,
              class Compare = std::less,
              class Allocator = std::allocator>

              class map;

              Microsoft:

              template ,
              class Allocator=allocator>>
              class map;

              Do you see significant differences?

              "In testa che avete, Signor di Ceprano?" -- Rigoletto

              F Offline
              F Offline
              ForNow
              wrote on last edited by
              #22

              I see the third parameter to the template in microsoft docs is class traits in the cpp reference its class compare thank you

              C 1 Reply Last reply
              0
              • F ForNow

                I see the third parameter to the template in microsoft docs is class traits in the cpp reference its class compare thank you

                C Offline
                C Offline
                CPallini
                wrote on last edited by
                #23

                That's, you know, just a matter of naming... BTW, you are welcome.

                "In testa che avete, Signor di Ceprano?" -- Rigoletto

                F 1 Reply Last reply
                0
                • C CPallini

                  That's, you know, just a matter of naming... BTW, you are welcome.

                  "In testa che avete, Signor di Ceprano?" -- Rigoletto

                  F Offline
                  F Offline
                  ForNow
                  wrote on last edited by
                  #24

                  this is just a general comment I thought MainFrame Assembler was Hard but being a C\C++ proficient coder is a very difficult skill to master as an aside just looked at the retrieval for the map class "AT" method it looks like if not found it generates an exception would of been a lot simpler if they gave back a bad return code Thank

                  L C 2 Replies Last reply
                  0
                  • F ForNow

                    this is just a general comment I thought MainFrame Assembler was Hard but being a C\C++ proficient coder is a very difficult skill to master as an aside just looked at the retrieval for the map class "AT" method it looks like if not found it generates an exception would of been a lot simpler if they gave back a bad return code Thank

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

                    It is just as easy to catch the exception. Exceptions are another useful feature of OOP languages, and provide more flexibility than simple return codes.

                    1 Reply Last reply
                    0
                    • F ForNow

                      this is just a general comment I thought MainFrame Assembler was Hard but being a C\C++ proficient coder is a very difficult skill to master as an aside just looked at the retrieval for the map class "AT" method it looks like if not found it generates an exception would of been a lot simpler if they gave back a bad return code Thank

                      C Offline
                      C Offline
                      CPallini
                      wrote on last edited by
                      #26

                      You might use find, to the purpose (see std::map<Key,T,Compare,Allocator>::find - cppreference.com[^]).

                      "In testa che avete, Signor di Ceprano?" -- Rigoletto

                      F 1 Reply Last reply
                      0
                      • C CPallini

                        You might use find, to the purpose (see std::map<Key,T,Compare,Allocator>::find - cppreference.com[^]).

                        "In testa che avete, Signor di Ceprano?" -- Rigoletto

                        F Offline
                        F Offline
                        ForNow
                        wrote on last edited by
                        #27

                        Thank you again you know I’m an assembler mail framer by birth when I post any question on IBMMAIN no matter how much research I have done I get screamed at wish IBMMAIN could be more like the codeproject thank. Time for to implement my code or actually yours

                        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