Map with string key and wstring[] value

C

campesr

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.
 
C

campesr

campesr said:
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<wstring> >

.

V

Thanks.
 
F

Frank Birbacher

Hi!

Victor said:
No. The closest you can get to what you want is to have

std::map<string, std::vector<wstring> >

I suggest to try a deque because it offers better or equally good time
complexity for all operations:

map<string, deque<wstring> >

:)

Regards,
Frank
 
F

Frank Birbacher

Hi!

Victor said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top