Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #89500

Re: reference to reference (Type &&)

From James Kuyper <jameskuyper@alumni.caltech.edu>
Newsgroups comp.lang.c++
Subject Re: reference to reference (Type &&)
Date 2023-03-06 19:48 -0500
Organization A noiseless patient Spider
Message-ID <tu61k3$4c5t$1@dont-email.me> (permalink)
References <tu2f60$1cnvt$2@dont-email.me> <tu5np6$2qqc$1@dont-email.me> <tu5p3e$31uv$1@dont-email.me>

Show all headers | View raw


On 3/6/23 17:22, MarioCPPP wrote:
...
> But I still cant'imagine its use.
> I have to understand what is a MOVE SEMANTIC.
> 
> In my old-styled mind move IS copying (and deleting the 
> original object).

Only when necessary. What the semantics of moving are is up to the
implementor of the relevant special functions.

A typical example is when an object doesn't contain the actual data, but
only a pointer to the data. A copy constructor would copy the data that
was pointed at, and then put a pointer to the copied data in the new
object. The destructor would deallocate the memory the data was stored in.
A move constructor, on the other hand, would move the pointer from the
existing object to the new one, replacing the pointer in the existing
object with a null pointer to indicate that it no longer had any data.
The data that was pointed at would remain untouched. As a result, a move
can be much faster than a copy followed by a delete. The only point in
creating a move constructor is if it can, indeed, be faster than a copy
followed by a delete.

I don't know anywhere near as much about r-value references as other
people, so I'll let them try to explain how that is connected.

Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

reference to reference (Type &&) MarioCPPP <NoliMihiFrangereMentulam@libero.it> - 2023-03-05 17:14 +0100
  Re: reference to reference (Type &&) Öö Tiib <ootiib@hot.ee> - 2023-03-05 22:24 -0800
  Re: reference to reference (Type &&) Paavo Helde <eesnimi@osa.pri.ee> - 2023-03-06 12:53 +0200
  Re: reference to reference (Type &&) James Kuyper <jameskuyper@alumni.caltech.edu> - 2023-03-06 14:31 -0500
  Re: reference to reference (Type &&) Andrey Tarasevich <andreytarasevich@hotmail.com> - 2023-03-06 14:00 -0800
    Re: reference to reference (Type &&) MarioCPPP <NoliMihiFrangereMentulam@libero.it> - 2023-03-06 23:22 +0100
      Re: reference to reference (Type &&) James Kuyper <jameskuyper@alumni.caltech.edu> - 2023-03-06 19:48 -0500
        Re: reference to reference (Type &&) MarioCPPP <NoliMihiFrangereMentulam@libero.it> - 2023-03-07 12:19 +0100
      Re: reference to reference (Type &&) Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2023-03-07 03:48 -0800
        Re: reference to reference (Type &&) Öö Tiib <ootiib@hot.ee> - 2023-03-07 04:30 -0800
        Re: reference to reference (Type &&) Muttley@dastardlyhq.com - 2023-03-07 15:58 +0000
          Re: reference to reference (Type &&) Paavo Helde <eesnimi@osa.pri.ee> - 2023-03-08 00:10 +0200
            Re: reference to reference (Type &&) Muttley@dastardlyhq.com - 2023-03-08 09:21 +0000
              Re: reference to reference (Type &&) Paavo Helde <eesnimi@osa.pri.ee> - 2023-03-08 14:41 +0200
                Re: reference to reference (Type &&) Muttley@dastardlyhq.com - 2023-03-08 16:26 +0000
                Re: reference to reference (Type &&) "Alf P. Steinbach" <alf.p.steinbach@gmail.com> - 2023-03-08 18:08 +0100
                Re: reference to reference (Type &&) Paavo Helde <eesnimi@osa.pri.ee> - 2023-03-08 19:23 +0200
                Re: reference to reference (Type &&) Bonita Montero <Bonita.Montero@gmail.com> - 2023-03-10 07:58 +0100
                Re: reference to reference (Type &&) MarioCPPP <NoliMihiFrangereMentulam@libero.it> - 2023-03-09 02:19 +0100

csiph-web