Namespaces
Variants

std::copyable_function

ja.cppreference.net より
 
 
ユーティリティライブラリ
言語サポート
型サポート (基本型、RTTI)
ライブラリ機能テストマクロ (C++20)
プログラムユーティリティ
可変引数関数
コルーチンサポート (C++20)
契約サポート (C++26)
三方比較
(C++20)
(C++20)(C++20)(C++20)    
(C++20)(C++20)(C++20)

汎用ユーティリティ
関係演算子 (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まで*)
 
 
ヘッダ <functional>
template< class... >
class copyable_function; // not defined
で定義 (1) (C++26以上)
template< class R, class... Args >
class copyable_function<R(Args...)>;
template< class R, class... Args >
class copyable_function<R(Args...) noexcept>;
template< class R, class... Args >
class copyable_function<R(Args...) &>;
template< class R, class... Args >
class copyable_function<R(Args...) & noexcept>;
template< class R, class... Args >
class copyable_function<R(Args...) &&>;
template< class R, class... Args >
class copyable_function<R(Args...) && noexcept>;
template< class R, class... Args >
class copyable_function<R(Args...) const>;
template< class R, class... Args >
class copyable_function<R(Args...) const noexcept>;
template< class R, class... Args >
class copyable_function<R(Args...) const &>;
template< class R, class... Args >
class copyable_function<R(Args...) const & noexcept>;
template< class R, class... Args >
class copyable_function<R(Args...) const &&>;
template< class R, class... Args >
class copyable_function<R(Args...) const && noexcept>;
(2) (C++26以上)

クラステンプレート std::copyable_function は、汎用の多相的関数ラッパーです。 std::copyable_function オブジェクトは、任意の コピー構築可能 かつ 呼び出し可能なターゲット(関数、ラムダ式、bind式、その他の関数オブジェクト、メンバ関数へのポインタ、メンバオブジェクトへのポインタ)を格納し、呼び出すことができます。

格納された呼び出し可能オブジェクトは、ターゲットと呼ばれます。 std::copyable_function がターゲットを持たない場合、それはstd::copyable_function空と呼ばれます。 std::function とは異なり、空の std::copyable_function を呼び出すと未定義動作になります。

std::copyable_function は、テンプレート引数で指定された、cv修飾子(volatile は除く)、参照修飾子、およびnoexcept指定子(存在する場合)のすべての可能な組み合わせをサポートします。これらの修飾子と指定子(存在する場合)は、そのoperator()に追加されます。

std::copyable_function は、CopyConstructible と CopyAssignable の要件を満たします。

メンバー型

型 定義
result_type R

メンバー関数

新しい std::copyable_function オブジェクトを構築する
(public member function)
std::copyable_function オブジェクトを破棄する
(public member function)
ターゲットを置き換えるか破棄する
(public member function)
2つの std::copyable_function オブジェクトのターゲットを交換する
(public member function)
std::copyable_function がターゲットを持っているかチェックする
(public member function)
ターゲットを呼び出す
(public member function)

非メンバー関数

std::swap アルゴリズムをオーバーロードする
(関数)
(C++26)
std::copyable_function と nullptr を比較する
(関数)

注記

実装は、小さなサイズの呼び出し可能オブジェクトをstd::copyable_functionオブジェクト内に格納することがあります。このような小さなオブジェクト最適化は、関数ポインタとstd::reference_wrapperの特殊化に対して事実上必須であり、Tについてstd::is_nothrow_move_constructible_v<T>がtrueである型にのみ適用できます。

機能テスト マクロ 値 標準 機能
__cpp_lib_copyable_function 202306L (C++26) std::copyable_function

例

関連項目

(C++11)
任意のコピー構築可能な呼び出し可能オブジェクトのコピー可能ラッパー
(クラステンプレート)
特定の呼び出しシグネチャで修飾子をサポートする任意の呼び出し可能オブジェクトのムーブ専用ラッパー
(クラステンプレート)
任意の呼び出し可能オブジェクトの非所有ラッパー
(クラステンプレート)