On Mon, 5 Aug 2024 23:51:44 -0700 (PDT) Rossano Paris wrote:
RP> Talking about the wx version series 3.2, I'd like to understand whether
RP> enabling the implicit conversion to std::string in wxString could results
RP> in an advantage or not.
RP> Containers and IO streams options are already added as default
RP> but wxUSE_STD_STRING_CONV_IN_WXSTRING.
RP>
RP> When should be convenient to enable std:string ?
RP> Are there different considerations to know regarding differents OSs?
There are several considerations:
1. Implicit conversions are dangerous, but can be convenient, so it's up
to you to balance the advantages against the risks:
- Conversion to std::string is especially dangerous as it can result in
data loss if the current encoding is not UTF-8 (which can be the case
under any platform in theory, but in practice is only going to happen
under Windows), so it's strongly recommended to disable this one by
defining wxNO_UNSAFE_WXSTRING_CONV, see this old blog post for more
details:
https://www.wxwidgets.org/blog/2020/08/implicit_explicit_encoding/
- Conversion to std::wstring is fine, though, so if you work with APIs
taking std::wstring (which is relative rare IME), then it can be nice
to have it.
2. Enabling implicit conversions to std::[w]string disables implicit
conversions to "const char*" and "const wchar_t*". This is a good
thing, in theory, as these conversions are even more dangerous, but
it can result in many (like hundreds or thousands of) errors in the
existing code bases as this is something that is used a lot. So you
may not be able to easily fix compilation of your code after enabling
wxUSE_STD_STRING_CONV_IN_WXSTRING -- but if you can, or if you're
writing something new, you should consider doing it.
Hope this helps,
VZ
--
TT-Solutions: wxWidgets consultancy and technical support
https://www.tt-solutions.com/