Namespaces
Variants

swap(std::move_only_function)

cppreference.net에서 가져옴
 
 
유틸리티 라이브러리
일반 유틸리티
관계 연산자 (C++20에서 폐지됨)
정수 비교 함수
(C++20)(C++20)(C++20)    
(C++20)
Swap 및 타입 연산
(C++14)
(C++11)
(C++11)
(C++11)
(C++17)
공통 어휘 타입
(C++11)
(C++17)
(C++17)
(C++17)
(C++11)
(C++17)
(C++23)



 
함수 객체
함수 호출
(C++17)(C++23)
항등 함수 객체
(C++20)
투명 연산자 래퍼
(C++14)
(C++14)
(C++14)
(C++14)  
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)

이전 바인더와 어댑터
(C++17까지*)
(C++17까지*)
(C++17까지*)
(C++17까지*)  
(C++17까지*)
(C++17까지*)(C++17까지*)(C++17까지*)(C++17까지*)
(C++20까지*)
(C++20까지*)
(C++17까지*)(C++17까지*)
(C++17까지*)(C++17까지*)

(C++17까지*)
(C++17까지*)(C++17까지*)(C++17까지*)(C++17까지*)
(C++20까지*)
(C++20까지*)
 
 
friend void swap( std::move_only_function& lhs, std::move_only_function& rhs ) noexcept;
(C++23부터)

std::swap 알고리즘을 std::move_only_function에 대해 오버로드합니다. lhs의 상태를 rhs의 상태와 교환합니다. 효과적으로 lhs.swap(rhs)를 호출합니다.

이 함수는 일반적인 비한정 또는 한정 조회에는 보이지 않으며, 인자 종속 조회를 통해서만 찾을 수 있습니다. 단, std::move_only_function<FunctionType>이 인자의 연관된 클래스인 경우에 한합니다.

매개변수

lhs, rhs - std::move_only_function 객체들 - 상태를 교환할 대상

반환값

(없음)

예제

#include <concepts>
#include <functional>
#include <iostream>
void foo(const char* str, int x)
{
    std::cout << "foo(\"" << str << "\", " << x << ")\n";
}
void bar(const char* str, int x)
{
    std::cout << "bar(\"" << str << "\", " << x << ")\n";
}
int main()
{
    std::move_only_function<void(const char*, int) const> f1{foo};
    std::move_only_function<void(const char*, int) const> f2{bar};
    f1("f1", 1);
    f2("f2", 2);
    std::cout << "std::ranges::swap(f1, f2);\n";
    std::ranges::swap(f1, f2); // finds the hidden friend
    f1("f1", 1);
    f2("f2", 2);
}

출력:

foo("f1", 1)
bar("f2", 2)
std::ranges::swap(f1, f2);
bar("f1", 1)
foo("f2", 2)

참고 항목

두 개의 std::move_only_function 객체의 대상을 교환합니다
(public member function)
std::swap 알고리즘을 특수화합니다
(function template)