std::swap
Материал из cppreference.com
![]() |
This page has been machine-translated from the English version of the wiki using Google Translate.
The translation may contain errors and awkward wording. Hover over text to see the original version. You can help to fix errors and improve the translation. For instructions click here. |
Заголовочный файл <algorithm>
Заголовочный файл <utility> |
(до C++11) (начиная с C++11) |
|
template< class T > void swap( T& a, T& b ); |
(1) | |
template< class T2, size_t N > void swap( T2 (&a)[N], T2 (&b)[N]); |
(2) | (начиная с C++11) |
Обмен данными значениями.
1) Original:
Exchanges the given values.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
Меняет местами значения
2) a
и b
.Original:
Swaps the values
a
and b
.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
Обмены массивов
a
и b
. В действительности вызывает std::swap_ranges(a, a+N, b).Original:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
Содержание |
[править] Параметры
a, b | - | Значения должны быть поменяны местами
Original: the values to be swapped The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
Type requirements | ||
-T must meet the requirements of MoveAssignable and MoveConstructible .
| ||
-T2 must meet the requirements of Swappable .
|
[править] Возвращаемое значение
(Нет)
Original:
(none)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
[править] Исключения
1)noexcept-спецификация: (начиная с C++11)
2)
noexcept(noexcept( std::is_nothrow_move_constructible<T>::value && |
||
[править] Сложность
1)Constant
2) Original:
Constant
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
Линейный в Н
Original:
Linear in N
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
[править] Специализации
Оба пользовательских специализации и перегрузки std::swap алгоритма допускаются, но перегрузок, как правило, предпочтительнее, так как специализация шаблона функции не разрешены для шаблонов классов. Библиотека функций всегда используют предоставленные пользователем перегрузки при замене, если они находят аргументов зависит от поиска (в соответствии с концепцией
Swappable
).Original:
Both custom specializations and overloads of the std::swap algorithm are allowed, but the overloads are generally preferred since specializations of a function template aren't allowed for template classes. Library functions always use the user-provided overloads when swapping, if they are found by argument-dependent lookup (as per
Swappable
concept).The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
После перегрузки уже предусмотрены в стандартной библиотеке
Original:
The following overloads are already provided by the standard library:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
(C++11) |
Специализируется std::swap алгоритм Original: specializes the std::swap algorithm The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (шаблон функции) |
(C++11) |
Специализируется std::swap алгоритм Original: specializes the std::swap algorithm The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (шаблон функции) |
(C++11) |
Специализируется std::swap алгоритм Original: specializes the std::swap algorithm The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (шаблон функции) |
(C++11) |
Специализируется std::swap алгоритм Original: specializes the std::swap algorithm The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (шаблон функции) |
(C++11) |
Специализируется std::swap алгоритм Original: specializes the std::swap algorithm The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (шаблон функции) |
(C++11) |
Специализируется std::swap алгоритм Original: specializes the std::swap algorithm The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (шаблон функции) |
Специализируется std::swap алгоритм Original: specializes the std::swap algorithm The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (шаблон функции) | |
Специализируется std::swap алгоритм Original: specializes the std::swap algorithm The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (шаблон функции) | |
Специализируется std::swap алгоритм Original: specializes the std::swap algorithm The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (шаблон функции) | |
Специализируется std::swap алгоритм Original: specializes the std::swap algorithm The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (шаблон функции) | |
Специализируется std::swap алгоритм Original: specializes the std::swap algorithm The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (шаблон функции) | |
Специализируется std::swap алгоритм Original: specializes the std::swap algorithm The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (шаблон функции) | |
Специализируется std::swap алгоритм Original: specializes the std::swap algorithm The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (шаблон функции) | |
Специализируется std::swap алгоритм Original: specializes the std::swap algorithm The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (шаблон функции) | |
Специализируется std::swap алгоритм Original: specializes the std::swap algorithm The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (шаблон функции) | |
Специализируется std::swap алгоритм Original: specializes the std::swap algorithm The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (шаблон функции) | |
Специализируется std::swap алгоритм Original: specializes the std::swap algorithm The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (шаблон функции) | |
Специализируется std::swap алгоритм Original: specializes the std::swap algorithm The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (шаблон функции) | |
Специализируется std::swap алгоритм Original: specializes the std::swap algorithm The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (шаблон функции) | |
Специализируется std::swap алгоритм Original: specializes the std::swap algorithm The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (шаблон функции) | |
Специализируется std::swap алгоритм Original: specializes the std::swap algorithm The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (шаблон функции) | |
Специализируется std::swap алгоритм Original: specializes the std::swap algorithm The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (шаблон функции) | |
Специализируется std::swap алгоритм Original: specializes the std::swap algorithm The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (шаблон функции) | |
(C++11) |
Специализируется std::swap() алгоритмOriginal: specializes the std::swap() algorithmThe text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (шаблон функции) |
Специализируется std::swap() алгоритмOriginal: specializes the std::swap() algorithmThe text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (шаблон функции) | |
Специализируется std::swap() алгоритмOriginal: specializes the std::swap() algorithmThe text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (шаблон функции) | |
Специализируется std::swap() алгоритмOriginal: specializes the std::swap() algorithmThe text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (шаблон функции) | |
Специализируется std::swap() алгоритмOriginal: specializes the std::swap() algorithmThe text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (шаблон функции) | |
Специализируется std::swap() алгоритмOriginal: specializes the std::swap() algorithmThe text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (шаблон функции) | |
Специализируется std::swap алгоритм Original: specializes the std::swap algorithm The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (шаблон функции) | |
Специализируется std::swap алгоритм Original: specializes the std::swap algorithm The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (шаблон функции) | |
Специализируется std::swap алгоритм Original: specializes the std::swap algorithm The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (шаблон функции) | |
(C++11) |
Специализируется std::swap() алгоритмOriginal: specializes the std::swap() algorithmThe text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (шаблон функции) |
Специализируется std::swap() алгоритмOriginal: specializes the std::swap() algorithmThe text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (шаблон функции) | |
(C++11) |
Специализируется std::swap алгоритм Original: specializes the std::swap algorithm The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (шаблон функции) |
(C++11) |
Специализируется std::swap() алгоритмOriginal: specializes the std::swap() algorithmThe text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (шаблон функции) |
(C++11) |
Специализируется std::swap() алгоритмOriginal: specializes the std::swap() algorithmThe text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (шаблон функции) |
Специализируется std::swap() алгоритмOriginal: specializes the std::swap() algorithmThe text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (шаблон функции) |
[править] Пример
Этот раздел не завершён Причина: no example |
[править] См. также
свопы элементов указал на двух итераторов Original: swaps the elements pointed to by two iterators The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (шаблон функции) | |
свопы двух диапазонах элементы Original: swaps two ranges of elements The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (шаблон функции) |