For “in” parameters, pass cheaply-copied types by value and others by reference to const What is “cheap to copy” depends on the machine architecture, but two or three words (doubles, pointers, references) are usually best passed by value. When copying is cheap, nothing beats the simplicity and safety of copying, and for small objects (up to two or three words) it is also faster than passing by reference because it does not require an extra indirection to access from the function. ... For advanced uses (only), where you really need to optimize for rvalues passed to “input-only” parameters: . If the function is going to unconditionally move from the argument, take it by &&. See F.18. . If the function is going to keep a copy of the argument, in addition to passing by const& (for lvalues), add an overload that passes the parameter by && (for rvalues) and in the body std::moves it to its destination. Essentially this overloads a “will-move-from”; see F.18. . In special cases, such as multiple “input + copy” parameters, consider using perfect forwarding. See F.19. ... Avoid “esoteric techniques” such as: . Passing arguments as T&& “for efficiency”. Most rumors about performance advantages from passing by && are false or brittle (but see F.18 and F.19). . Returning const T& from assignments and similar operations (see F.47.) |