jeudi 18 novembre 2021

Modifying unnamed objects via r-value semantics

I have a method that modifies objects passed by reference:

class T;

T& modify (T& t) {...; return t; }

What's the right way to extend modify to unnamed objects avoiding extra copies, so that the following code is valid?

T create_T () { ... }

T t = modify(create_T());

// instead of:

T t = create_T();
modify(t);

Aucun commentaire:

Enregistrer un commentaire