> My professor likes to use the swap function when sorting.
> It does the job with less code
It also does the job in the most efficient way possible.
The standard library already has several overloads of std::swap() customized for efficient swapping of objects belonging to different types used by the library.
In addition, std::swap() is one of those standard functions for which specializations / overloads for user-defined types are expressly permitted by the standard.
Say, we have a swappable class sprite provided by some third party library. To swap two sprites in the most efficient manner possible (without violating its encapsulation), we can confidently write std::swap( sprite_one, sprite_two ) ;.
Subject to the obvious assumption that the people who wrote sprite as a swappable type knew what they were doing - if the general std::swap() is not the most efficient way of swapping sprites, an overload of std::swap() would have been provided by the implementer of the class.