Spec-Zone.ru › C++

std::swap(std::any)

Определён в заголовочном файле <any>
void swap( any& lhs, any& rhs ) noexcept;
(начиная с C++17)

Перегружает алгоритм std::swap для std::any. Обменивает содержимое двух объектов any, вызывая lhs.swap(rhs).

Параметры

lhs, rhs - объекты для обмена

Пример

#include <any>
#include <print>
#include <string>

int main()
{
    std::any p = 42, q = std::string{"Bishop"};
    std::println("p: {}, q: {}", std::any_cast<int>(p), std::any_cast<std::string&>(q));
    std::println("swap(p, q)");
    std::swap(p, q);
    std::println("p: {}, q: {}", std::any_cast<std::string&>(p), std::any_cast<int>(q));
}

Вывод:

p: 42, q: Bishop
swap(p, q)
p: Bishop, q: 42

См. также

swap
обменивает два объекта any
(открытая функция-член)

© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
https://en.cppreference.com/cpp/utility/any/swap2

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API