samedi 20 avril 2019

Should every function taking an lvalue reference be overloaded to take an rvalue reference?

Let's imagine I have a function like this :

auto funct(T const& lhs) { ... };

This function could often be optimized by stealing ressources, so we could overload it as follows :

auto funct(T&& lhs) { ... };

Knowing that temporary values are implicitly converted into rvalue references, this would actually improve performance when stealing is relevant.

Should I overload every function like this ? That seems to lead to a lot of code duplication... If I'm right, can this duplication be avoided ?

Aucun commentaire:

Enregistrer un commentaire