Re: is it convenient to enable std::string using wxUSE_STD_STRING_CONV_IN_WXSTRING ?

Rossano Paris <[email protected]>
Newsgroups gmane.comp.lib.wxwindows.general
Message-ID <[email protected]>
thank you for your explanation.

On Saturday 10 August 2024 at 15:10:31 UTC+2 Vadim Zeitlin wrote:

> 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/
>

-- 
Please read https://www.wxwidgets.org/support/mlhowto.htm before posting.
--- 
You received this message because you are subscribed to the Google Groups "wx-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/wx-users/ddd06341-fb4a-40c0-993c-2b447e184bc2n%40googlegroups.com.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.