Your myswap takes items by value.
Essentially you are replacing two links ( std::reference_wrapper s) in the local scope of the function.
The values ββthey indicate will not change.
template <typename T> void incrementer(T a) { ++a; } int a = 20;
In this case, conversion to int& c occurs:
operator T& () const noexcept { return *_ptr; }
In your code, on the other hand:
T temp = a;
just call the copy constructor, which will copy the main pointer:
reference_wrapper(const reference_wrapper&) noexcept = default;
then on the following lines you will again copy the pointer:
reference_wrapper& operator=(const reference_wrapper& x) noexcept = default;
source share