File: move.yo

package info (click to toggle)
c%2B%2B-annotations 13.02.02-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 13,576 kB
  • sloc: cpp: 25,297; makefile: 1,523; ansic: 165; sh: 126; perl: 90; fortran: 27
file content (34 lines) | stat: -rw-r--r-- 1,449 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
As with classes using composition derived classes may benefit from defining a
 i(move constructor).
A derived class may offer a move constructor for two reasons:
    itemization(
    it() it supports move construction for its  data members
    it() its base class is move-aware
    )

    The design of move constructors moving data members was covered in section
ref(MOVE). A move constructor for a derived class whose base class is
move-aware must em(anonymize) the rvalue reference before passing it to the
base class move constructor. The tt(std::move) function should be used when
implementing the move constructor to move the information in base classes or
composed objects to their new destination object.

    The first example shows the move constructor for the class tt(Car),
assuming it has a movable tt(char *d_brandName) data member and
assuming that tt(Land) is a move-aware class. The second example shows the
move constructor for the class tt(Land), assuming that it does not itself have
movable data members, but that its tt(Vehicle) base class is move-aware:
        verb(    Car::Car(Car &&tmp)
    :
        Land(std::move(tmp)),           // anonymize `tmp'
        d_brandName(tmp.d_brandName)    // move the char *'s value
    {
        tmp.d_brandName = 0;
    }

    Land(Land &&tmp)
    :
        Vehicle(std::move(tmp)),    // move-aware Vehicle
        d_speed(tmp.d_speed)        // plain copying of plain data
    {})