Map with string key and wstring[] value

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • campesr

    Map with string key and wstring[] value

    Hi!

    I'd like to have a map with string keys, and wstring[] (arrays) values
    in c++.

    I thought map<string, wstring[]would work out, but it doesn't (at
    least I think so).

    Additionally I'd like to know what's the easiest way to populate such
    a map.

    Would - mymap["somekey"] = {L"My Unicode value one", L"My other
    unicode value"}; - work?

    Many thanks in advance.
  • Victor Bazarov

    #2
    Re: Map with string key and wstring[] value

    campesr wrote:
    I'd like to have a map with string keys, and wstring[] (arrays) values
    in c++.
    You can't do that. The stored value has to satisfy certain requirements
    (be copy-constructible and assignable), and arrays don't.
    I thought map<string, wstring[]would work out, but it doesn't (at
    least I think so).
    >
    Additionally I'd like to know what's the easiest way to populate such
    a map.
    >
    Would - mymap["somekey"] = {L"My Unicode value one", L"My other
    unicode value"}; - work?
    No. The closest you can get to what you want is to have

    std::map<string , std::vector<wst ring

    ..

    V
    --
    Please remove capital 'A's when replying by e-mail
    I do not respond to top-posted replies, please don't ask

    Comment

    • campesr

      #3
      Re: Map with string key and wstring[] value

      On 23 Mai, 17:25, Victor Bazarov <v.Abaza...@com Acast.netwrote:
      campesr wrote:
      I'd like to have a map with string keys, and wstring[] (arrays) values
      in c++.
      >
      You can't do that. The stored value has to satisfy certain requirements
      (be copy-constructible and assignable), and arrays don't.
      >
      I thought map<string, wstring[]would work out, but it doesn't (at
      least I think so).
      >
      Additionally I'd like to know what's the easiest way to populate such
      a map.
      >
      Would - mymap["somekey"] = {L"My Unicode value one", L"My other
      unicode value"}; - work?
      >
      No. The closest you can get to what you want is to have
      >
      std::map<string , std::vector<wst ring
      >
      .
      >
      V
      --
      Please remove capital 'A's when replying by e-mail
      I do not respond to top-posted replies, please don't ask
      Thanks.

      Comment

      • Frank Birbacher

        #4
        Re: Map with string key and wstring[] value

        Hi!

        Victor Bazarov schrieb:
        No. The closest you can get to what you want is to have
        >
        std::map<string , std::vector<wst ring
        I suggest to try a deque because it offers better or equally good time
        complexity for all operations:

        map<string, deque<wstring

        :)

        Regards,
        Frank

        Comment

        • Victor Bazarov

          #5
          Re: Map with string key and wstring[] value

          Frank Birbacher wrote:
          Hi!
          >
          Victor Bazarov schrieb:
          >No. The closest you can get to what you want is to have
          >>
          > std::map<string , std::vector<wst ring
          >
          I suggest to try a deque because it offers better or equally good time
          complexity for all operations:
          >
          map<string, deque<wstring
          >
          :)
          Except that std::deque does not have the same property that may be
          important to the OP -- the data are not stored contiguously. The
          storage of a vector can be easily used where an array can be used (like
          passing it to a third-party library that expects an array via a pointer
          to the first element).

          V
          --
          Please remove capital 'A's when replying by e-mail
          I do not respond to top-posted replies, please don't ask

          Comment

          • Frank Birbacher

            #6
            Re: Map with string key and wstring[] value

            Hi!

            Victor Bazarov schrieb:
            Except that std::deque does not have the same property that may be
            important to the OP -- the data are not stored contiguously.
            Yes, right. I should have mentioned it. I'm sorry.

            Frank

            Comment

            • campesr

              #7
              Re: Map with string key and wstring[] value

              On 23 Mai, 22:33, Frank Birbacher <bloodymir.c... @gmx.netwrote:
              Hi!
              >
              Victor Bazarov schrieb:
              >
              Except that std::deque does not have the same property that may be
              important to the OP -- the data are not stored contiguously.
              >
              Yes, right. I should have mentioned it. I'm sorry.
              >
              Frank
              OK. Many thanks to all of you.

              Comment

              Working...