名稱空間
變體
操作

std::function<R(Args...)>::swap

來自 cppreference.com
< cpp‎ | utility‎ | functional‎ | function
 
 
 
函式物件
函式呼叫
(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*)
 
 
void swap( function& other ) noexcept;
(C++11 起)

交換 *thisother 所儲存的可呼叫物件。

目錄

[編輯] 引數

其他 - 用於交換所儲存的可呼叫物件的函式包裝器

[編輯] 返回值

(無)

[編輯] 示例

#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::function<void(const char*, int)> f1{foo};
    std::function<void(const char*, int)> f2{bar};
 
    f1("f1", 1);
    f2("f2", 2);
 
    std::cout << "f1.swap(f2);\n";
    f1.swap(f2);
 
    f1("f1", 1);
    f2("f2", 2);
}

輸出

foo("f1", 1)
bar("f2", 2)
f1.swap(f2);
bar("f1", 1)
foo("f2", 2)

[編輯] 參閱

交換兩個 std::move_only_function 目標
(std::move_only_function 的公開成員函式) [編輯]