How are pass-by-reference functions typically distinguished from pass-by-value functions? For example:
template <typename T>
void sort(std::vector<T>& source); // Sorts source.
// Versus...
template <typename T>
std::vector<T> sort(std::vector<T> source); // Returns a sorted copy of source.
These two functions are ambiguous; one of them must be either renamed or removed completely.
How can this situation be avoided? Should one form be preferred over the other? Or are there any common naming guidelines to distinguish them?
Can’t you just give them different names? I would name the functional version
sorted, for example.Just because you can overload functions (or function templates in this case) does not mean you have to.
By the way, you can implement the “functional version” in terms of the “imperative version”: