Namespaces
Variants

std:: copyable_function

From cppreference.net
Utilities library
Function objects
Function wrappers
(C++11)
copyable_function
(C++26)
(C++11)
Function invocation
(C++17) (C++23)
Identity function object
(C++20)
Old binders and adaptors
( until C++17* )
( until C++17* )
( until C++17* )
( until C++17* )
( until C++17* ) ( until C++17* ) ( until C++17* ) ( until C++17* )
( until C++20* )
( until C++20* )
( until C++17* ) ( until C++17* )
( until C++17* ) ( until C++17* )

( until C++17* )
( until C++17* ) ( until C++17* ) ( until C++17* ) ( until C++17* )
( until C++20* )
( until C++20* )
ヘッダーで定義 <functional>
template < class ... >
class copyable_function ; // 未定義
(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 オブジェクトは、 CopyConstructible Callable ターゲット — 関数、 ラムダ式 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)
任意のコピー構築可能な呼び出し可能オブジェクトのコピー可能ラッパー
(クラステンプレート)
特定の呼び出しシグネチャで修飾子をサポートする任意の呼び出し可能オブジェクトのムーブ専用ラッパー
(クラステンプレート)
任意の呼び出し可能オブジェクトの非所有ラッパー
(クラステンプレート)