Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #85474
| From | Juha Nieminen <nospam@thanks.invalid> |
|---|---|
| Newsgroups | comp.lang.c++ |
| Subject | Re: Do any STL inserters use std::move() by default? |
| Date | 2022-07-19 07:24 +0000 |
| Organization | Aioe.org NNTP Server |
| Message-ID | <tb5m7d$dsn$1@gioia.aioe.org> (permalink) |
| References | <tb3vor$1foi$1@gioia.aioe.org> <tb4u02$1ee2$1@gioia.aioe.org> |
Manfred <noname@add.invalid> wrote:
> On 7/18/2022 5:55 PM, Muttley@dastardlyhq.com wrote:
>> Having to to call move() manually eg: v.push_back(std::move(str)) when you
>> need move functionality can become tedious. Are there any or will there be any
>> inserters that use move() by default?
>>
> If the argument is an rvalue, move semantics should be used per default
> whenever a method that accepts a rvalue reference is available. If it's
> a lvalue, and you want move semantics, you have to specify it with
> std::move().
> This makes sense, since move semantics, in principle, modifies the argument.
Since the object being given to v.push_back() has a name ("str" in this
case), it cannot be an rvalue. Pretty much by definition named objects
are not rvalues.
That's the reason why you have to cast it to "rvalue" in order to have
it treated like it were one.
Back to comp.lang.c++ | Previous | Next — Previous in thread | Find similar | Unroll thread
Do any STL inserters use std::move() by default? Muttley@dastardlyhq.com - 2022-07-18 15:55 +0000
Re: Do any STL inserters use std::move() by default? Gawr Gura <gawrgura@mail.hololive.com> - 2022-07-18 10:25 -0700
Re: Do any STL inserters use std::move() by default? "Alf P. Steinbach" <alf.p.steinbach@gmail.com> - 2022-07-18 20:36 +0200
Re: Do any STL inserters use std::move() by default? Manfred <noname@add.invalid> - 2022-07-19 02:30 +0200
Re: Do any STL inserters use std::move() by default? Juha Nieminen <nospam@thanks.invalid> - 2022-07-19 07:24 +0000
csiph-web