c++ - In-place function with return value -


i have function has similar behavior of this:

void process(const t& input,t& output){     if(&input==&output){         //alter output directly     }     else{         output=input; //deep copy         //alter output     } } 

use case 1:

t i; //fill t o; process(i,o); 

use case 2:

t io; //fill io process(io,io); 

i want change function deceleration more readable:

t process(const t& input){    //what here? } 

use case 1:

t i; //fill auto o = process(i); 

use case 2:

t io; //fill io io=process(io); 

question: how can imitate previous methodology of dealing in-place cases? how should implement it? need avoid deep copying when same object.


Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -