WX_STRING_HASH_MAP Init: const wxStringMap Map("key", "value")

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
iwl
In need of some credit
In need of some credit
Posts: 3
Joined: Mon Apr 27, 2020 11:54 am

WX_STRING_HASH_MAP Init: const wxStringMap Map("key", "value")

Post by iwl » Mon Apr 27, 2020 12:15 pm

Code: Select all

#include <wx/hashmap.h>
WX_DECLARE_STRING_HASH_MAP(wxString, wxStringMap);

const wxStringMap Map("key", "value");  // HOW THIS IS DONE ??

PB
Part Of The Furniture
Part Of The Furniture
Posts: 2387
Joined: Sun Jan 03, 2010 5:45 pm

Re: WX_STRING_HASH_MAP Init: const wxStringMap Map("key", "value")

Post by PB » Mon Apr 27, 2020 1:12 pm

(The post does rather unusually does not really has a question aside from the comment in the code but I suppose I understood what you meant)

This container (and similar declared with macros) is considered obsolete and should be no longer used in the user code: std::map should be used instead.

If you still insist on using it, see the example in
https://docs.wxwidgets.org/trunk/group_ ... iners.html

There is already a predefined map which has wxString both for a key and value: wxStringToStringHashMap

Code: Select all

wxStringToStringHashMap strMap;

strMap["key"] = "value";

iwl
In need of some credit
In need of some credit
Posts: 3
Joined: Mon Apr 27, 2020 11:54 am

Re: WX_STRING_HASH_MAP Init: const wxStringMap Map("key", "value")

Post by iwl » Wed May 06, 2020 9:27 am

Question: "// How this is done" is in the Code, I think post it is sufficiently short to see.

What I would like to do is initialize the map in a short effektive way with some

= { ( , ) }

strMap["key"] = "value"; is to Long and inefficient for many key/values and also don't work for some const map.

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 4058
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: WX_STRING_HASH_MAP Init: const wxStringMap Map("key", "value")

Post by ONEEYEMAN » Wed May 06, 2020 3:10 pm

Hi,
You should use std::map instead.

This and other container classes in wxWidgets are kept for backward compatibility only.

Thank you.

Post Reply