Is std :: swap guaranteed to find implicit ADL exchange?

A Torsten T. Will tutorial in C ++ 11 says that since C ++ 11, it std::swapwill use the carrier swapfound by ADL if such a function without a member is defined, thus the pattern

using std::swap;
swap (obj1, obj2);

can always be replaced by simple

std::swap (obj1, obj2);

Unfortunately, I have not found such a statement anywhere.

What is the truth?

+4
source share
1 answer

From C ++ 14 (or, more specifically, N4140):

Required: The type Tmust be MoveConstructible (Table 20) and MoveAssignable (Table 22). Effects: Exchange of values ​​stored in two places.

swap. , , std::swap - swap.

, std::swap ADL swap, .

+6

Source: https://habr.com/ru/post/1622111/


All Articles