CS253: Software Development with C++

Spring 2018

Copy Elision

See this page as a slide show

CS253 Copy Elision

Elision

The word “elision” means “omission”, like how the two-syllable “do not” becomes the one-syllable “don’t”, or Captain Kirk never seems to brush his teeth. It’s not necessary to show everything.

The Loud Class

The following examples use my class Loud, which displays a message for every method invoked.

#include "Loud.h"

int main() {
    Loud alpha;
}
Loud::Loud()
Loud::~Loud()

No surprise, here. alpha got created & destroyed.

More Construction

#include "Loud.h"

int main() {
    Loud beta, gamma;
}
Loud::Loud()
Loud::Loud()
Loud::~Loud()
Loud::~Loud()

Sure.

Copy ctor & assignment

#include "Loud.h"

int main() {
    Loud delta;
    Loud epsilon(delta);
    delta=epsilon;
}
Loud::Loud()
Loud::Loud(const Loud &)
Loud::operator=(const Loud &)
Loud::~Loud()
Loud::~Loud()

As expected.

More copying

#include "Loud.h"

Loud foo() {
    Loud zeta;
    return zeta;
}

int main() {
    Loud eta(foo());
}
Loud::Loud()
Loud::~Loud()

Ludicrous copying

#include "Loud.h"

int main() {
    Loud theta = Loud(Loud(Loud(Loud(Loud(Loud(Loud(Loud())))))));
}
Loud::Loud()
Loud::~Loud()

There should be more than that.

Elision

#include "Loud.h"
Loud foo() {
    Loud iota;
    return iota;
}

int main() {
    Loud kappa(foo());
}
Loud::Loud()
Loud::~Loud()

Parameter Passing

User: Guest

Check: HTML CSS
Edit History Source

Modified: 2018-04-30T14:50

Apply to CSU | Contact CSU | Disclaimer | Equal Opportunity
Colorado State University, Fort Collins, CO 80523 USA
© 2018 Colorado State University
CS Building