[prev in list] [next in list] [prev in thread] [next in thread]
List: gtkmm
Subject: Re: Making use of move semantics?
From: Daniel Boles <dboles.src () gmail ! com>
Date: 2017-05-22 13:15:22
Message-ID: CAKChMKMVz8JC8cuE9gGPCJzXmn6Bc1ngSfKVvK-wTBoFBh9oCA () mail ! gmail ! com
[Download RAW message or body]
[Attachment #2 (multipart/alternative)]
On 22 May 2017 at 11:23, Jonathan Wakely <gtkmm@kayari.org> wrote:
> On 21 May 2017 at 10:36, Daniel Boles wrote:
>
>> I still occasionally find myself reflexively std::move()ing strings into
>> glibmm/gtkmm functions that I unconsciously see as taking ownership of
>> their arguments - only to realise it makes no difference because all of
>> them take strings as const&.
>>
>> This made me wonder whether there are any cases where, if the user
>> instructs so by using std::move(), glibmm/gtkmm functions could steal the
>> string [ or at least it's c_str() ] and thus avoid having to copy it. All
>> those copies quickly add up to a lot.
>>
>
>
You can't steal the contents of a std::string without access to its
> internals, which only the standard library has. You can't steal the c_str()
> ... I'm not even sure what that would mean.
>
Saying "steal" was partly just my hamfisted way of explaining what the move
constructor of an std::string (or Glib::ustring) would do. But yeah, partly
I was half asleep, and imagining that maybe a C API could grab the char*
from a std::string or whatever and leave it in a 'moved-from' kinda
condition. Which is nonsense like you said, since there's no API for
anything like that.
[Attachment #5 (text/html)]
<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On 22 May 2017 at \
11:23, Jonathan Wakely <span dir="ltr"><<a href="mailto:gtkmm@kayari.org" \
target="_blank">gtkmm@kayari.org</a>></span> wrote:<br><blockquote \
class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid \
rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div \
class="gmail_quote"><span class="gmail-">On 21 May 2017 at 10:36, Daniel Boles \
wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px \
0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div \
dir="ltr"><div><div><div><div>I still occasionally find myself reflexively \
std::move()ing strings into glibmm/gtkmm functions that I unconsciously see as taking \
ownership of their arguments - only to realise it makes no difference because all of \
them take strings as const&.<br><br></div>This made me wonder whether there are \
any cases where, if the user instructs so by using std::move(), glibmm/gtkmm \
functions could steal the string [ or at least it's c_str() ] and thus avoid \
having to copy it. All those copies quickly add up to a \
lot.<br></div></div></div></div></blockquote></span></div></div></div></blockquote><blockquote \
class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid \
rgb(204,204,204);padding-left:1ex"><div> </div></blockquote><div><blockquote \
class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid \
rgb(204,204,204);padding-left:1ex"><div>You can't steal the contents of a \
std::string without access to its internals, which only the standard library has. \
You can't steal the c_str() ... I'm not even sure what that would \
mean.</div></blockquote><br> </div><div><br></div><div>Saying "steal" was \
partly just my hamfisted way of explaining what the move constructor of an \
std::string (or Glib::ustring) would do. But yeah, partly I was half asleep, and \
imagining that maybe a C API could grab the char* from a std::string or whatever and \
leave it in a 'moved-from' kinda condition. Which is nonsense like you said, \
since there's no API for anything like that.<br></div></div></div></div>
_______________________________________________
gtkmm-list mailing list
gtkmm-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtkmm-list
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic