[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [lmi] Converting std::string to wxString
From: |
Greg Chicares |
Subject: |
Re: [lmi] Converting std::string to wxString |
Date: |
Mon, 6 Feb 2017 16:57:16 +0000 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Icedove/45.6.0 |
On 2017-02-06 15:17, Vadim Zeitlin wrote:
> On Mon, 6 Feb 2017 04:10:56 +0000 (UTC) Greg Chicares <address@hidden> wrote:
[...]
> GC> + return wxString(parser_diagnostics.c_str());
That replaced this:
- wxString msg = sequence.formatted_diagnostics(true).c_str();
and this is VS's original from 2011:
+ return sequence.formatted_diagnostics().c_str();
so I was in no rush to make a speculative change that might be incorrect.
But now on your assurance I have changed it, in a commit that I have not
yet pushed.
> This is not really related to the changes of this patch series, but while
> reading them I noticed this line and just wanted to say that an explicit
> call to "c_str()" is not needed with any relatively recent version of
> wxWidgets (i.e. since many years) as wxString has a ctor from std::string
> (unless it was explicitly disabled by setting wxUSE_STD_STRING, which is 1
> by default, to 0).
Perhaps some people would wish to override that, but I am not one of them.
> Moreover, this ctor is implicit, so you don't even need
Implicit? It's been years since I looked at the wx sources, but I thought
it was a typedef. Wait...no, it can't be, because wxString has all those
extra functions--I must have been thinking of the container classes.
Oh...and wxString handles UTF-8. Maybe in C++37.
> to write "wxString(...)" neither, so the last added line above could be
> rewritten either as
>
> return wxString(parser_diagnostics);
>
> or even as just
>
> return parser_diagnostics;
Yes, that's best.
> I'm not sure if the latter is not too magic and I'd understand if you
> preferred to keep "wxString(...)" for clarity, but I'd definitely remove
> ".c_str()" which is just superfluous.
>
> Finally, for completeness, notice that the situation in the other
> direction is, unfortunately, not symmetric as we can't add a ctor from
> wxString to std::string class, so you still have to explicitly call
> wxString::ToStdString() to convert a wxString to std::string.
We've been having this discussion for ages, and I never can remember
what the rules are. But let me ask this: if I just do whatever seems
simplest to me, can I trust the compiler to give a warning whenever
I've oversimplified? "Code for simplicity, but don't commit anything
that doesn't compile" is a rule I can memorize.