Reading C++ named requirements: Swappable I've come across the following note
It is unspecified whether
<utility>is actually included when the standard library functions perform the swap, so the user-provided swap() should not expect it to be included.
Suppose I have a user-defined type class Foo with a user-provided swap(). I'd like to use a Standard Library algorithm for my class Foo that performs a swap with
using std::swap;
swap(arg1, arg2);
as described in the above-mentioned cppreference article, and the file that I have to
#include to use this algorithm does NOT #include <utility>.
If I relied on functionality provided by <utility> in my swap(), how could this lead to a problem? I'd have to #include <utility> myself in the file that defines my swap(). The scenario should be similar to the following: I have a file that #includes my class Foo with my user-provided swap() and the header for the algorithm that I use. Consequently, there should never be an issue regarding whether the algorithm does #include <utility> or not.
I might have misunderstandings revolving around how #include and compilation could interact with each other in some different scenarios. Which situation could potentially lead to compilation issues here?