标准库头文件 <functional>
来自cppreference.com
目录 |
[编辑] 命名空间
| placeholders | 定义了用作 std::bind 表达式中的未绑定实参的占位符 |
常量 | |
| 定义于命名空间
std::placeholders | |
| (C++11) |
用作 std::bind 表达式中的未绑定实参的占位符 (常量) |
[编辑] 类
| (C++11) |
包装具有指定函数调用签名的任意类型的可调用对象 (类模板) |
| (C++11) |
从成员指针创建出函数对象 (函数模板) |
| (C++11) |
调用空的 std::function 时抛出的异常 (类) |
| (C++11) |
指示对象为 std::bind 表达式,或能被用作这种表达式 (类模板) |
| (C++11) |
表明一个对象是标准占位符,或者可以用作标准占位符 (类模板) |
| (C++11) |
可复制构造 (CopyConstructible) 且可复制赋值 (CopyAssignable) 的引用包装器 (类模板) |
散列 | |
| (C++11) |
散列函数对象 (类模板) |
|
template<> struct hash<bool>; |
对内建类型的 std::hash 特化 (类模板特化) |
[编辑] 函数
| (C++11) |
绑定一或多个实参到函数对象 (函数模板) |
| (C++11)(C++11) |
创建具有从其实参推导的类型的 std::reference_wrapper (函数模板) |
| (C++17) |
以给定实参调用任意可调用 (Callable) 对象 (函数模板) |
[编辑] 函数对象
算术运算 | |
| 实现 x + y 的函数对象 (类模板) | |
| 实现 x - y 的函数对象 (类模板) | |
| 实现 x * y 的函数对象 (类模板) | |
| 实现 x / y 的函数对象 (类模板) | |
| 实现 x % y 的函数对象 (类模板) | |
| 实现 -x 的函数对象 (类模板) | |
比较 | |
| 实现 x == y 的函数对象 (类模板) | |
| 实现 x != y 的函数对象 (类模板) | |
| 实现 x > y 的函数对象 (类模板) | |
| 实现 x < y 的函数对象 (类模板) | |
| 实现 x >= y 的函数对象 (类模板) | |
| 实现 x <= y 的函数对象 (类模板) | |
逻辑运算 | |
| 实现 x && y 的函数对象 (类模板) | |
| 实现 x || y 的函数对象 (类模板) | |
| 实现 !x 的函数对象 (类模板) | |
逐位运算 | |
| 实现 x & y 的函数对象 (类模板) | |
| 实现 x | y 的函数对象 (类模板) | |
| 实现 x ^ y 的函数对象 (类模板) | |
| (C++14) |
实现 ~x 的函数对象 (类模板) |
取反器 | |
| (C++17) |
创建返回其保有的函数对象的结果之补的函数对象 (函数模板) |
搜索器 | |
| (C++17) |
标准 C++ 库搜索算法实现 (类模板) |
| (C++17) |
Boyer-Moore 搜索算法实现 (类模板) |
| Boyer-Moore-Horspool 搜索算法实现 (类模板) | |
[编辑] C++11 中弃用并于 C++17 移除
基类 | |
| (C++11 中弃用)(C++17 中移除) |
与适配器兼容的一元函数基类 (类模板) |
| (C++11 中弃用)(C++17 中移除) |
与适配器兼容的二元函数基类 (类模板) |
绑定器 | |
| (C++11 中弃用)(C++17 中移除) |
持有一个二元函数及其实参之一的函数对象 (类模板) |
| (C++11 中弃用)(C++17 中移除) |
将一个实参绑定到二元函数 (函数模板) |
函数适配器 | |
| (C++11 中弃用)(C++17 中移除) |
适配器兼容的包装,用于包装一元函数的指针 (类模板) |
| (C++11 中弃用)(C++17 中移除) |
适配器兼容的包装,用于包装二元函数的指针 (类模板) |
| (C++11 中弃用)(C++17 中移除) |
从函数指针创建与适配器兼容的函数对象包装器 (函数模板) |
| (C++11 中弃用)(C++17 中移除) |
指向零元或一元成员函数指针的包装器,可以一个对象指针调用 (类模板) |
| (C++11 中弃用)(C++17 中移除) |
从成员函数指针创建包装器,可以一个对象指针调用 (函数模板) |
| (C++11 中弃用)(C++17 中移除) |
指向零元或一元成员函数指针的包装器,可以一个对象引用调用 (类模板) |
| (C++11 中弃用)(C++17 中移除) |
从成员函数指针创建包装器,能以一个对象引用调用 (函数模板) |
[编辑] C++17 中弃用并于 C++20 移除
取反器 | |
| (C++17 中弃用)(C++20 中移除) |
包装器函数对象,返回所持有的一元谓词的补 (类模板) |
| (C++17 中弃用)(C++20 中移除) |
包装器函数对象,返回所持有的二元谓词的补 (类模板) |
| (C++17 中弃用)(C++20 中移除) |
构造定制的 std::unary_negate 对象 (函数模板) |
| (C++17 中弃用)(C++20 中移除) |
构造定制的 std::binary_negate 对象 (函数模板) |
[编辑] 概要
namespace std { // invoke: template <class F, class... Args> invoke_result_t<F, Args...> invoke(F&& f, Args&&... args); // reference_wrapper: template <class T> class reference_wrapper; template <class T> reference_wrapper<T> ref(T&) noexcept; template <class T> reference_wrapper<const T> cref(const T&) noexcept; template <class T> void ref(const T&&) = delete; template <class T> void cref(const T&&) = delete; template <class T> reference_wrapper<T> ref(reference_wrapper<T>) noexcept; template <class T> reference_wrapper<const T> cref(reference_wrapper<T>) noexcept; // 算术运算: template <class T = void> struct plus; template <class T = void> struct minus; template <class T = void> struct multiplies; template <class T = void> struct divides; template <class T = void> struct modulus; template <class T = void> struct negate; template <> struct plus<void>; template <> struct minus<void>; template <> struct multiplies<void>; template <> struct divides<void>; template <> struct modulus<void>; template <> struct negate<void>; // 比较: template <class T = void> struct equal_to; template <class T = void> struct not_equal_to; template <class T = void> struct greater; template <class T = void> struct less; template <class T = void> struct greater_equal; template <class T = void> struct less_equal; template <> struct equal_to<void>; template <> struct not_equal_to<void>; template <> struct greater<void>; template <> struct less<void>; template <> struct greater_equal<void>; template <> struct less_equal<void>; // 逻辑运算: template <class T = void> struct logical_and; template <class T = void> struct logical_or; template <class T = void> struct logical_not; template <> struct logical_and<void>; template <> struct logical_or<void>; template <> struct logical_not<void>; // 逐位运算: template <class T = void> struct bit_and; template <class T = void> struct bit_or; template <class T = void> struct bit_xor; template <class T = void> struct bit_not; template <> struct bit_and<void>; template <> struct bit_or<void>; template <> struct bit_xor<void>; template <> struct bit_not<void>; // 函数模板 not_fn: template <class F> /* 未指明 */ not_fn(F&& f); // 绑定: template<class T> struct is_bind_expression; template<class T> struct is_placeholder; template<class F, class... BoundArgs> /* 未指明 */ bind(F&&, BoundArgs&&...); template<class R, class F, class... BoundArgs> /* 未指明 */ bind(F&&, BoundArgs&&...); namespace placeholders { // M is the implementation-defined number of placeholders /* 由实现定义 */ _1; /* 由实现定义 */ _2; ... /* 由实现定义 */ _M; } // 成员函数适配器: template<class R, class T> /* 未指明 */ mem_fn(R T::*) noexcept; // 多态函数包装器: class bad_function_call; template<class> class function; // 未予定义 template<class R, class... ArgTypes> class function<R(ArgTypes...)>; template<class R, class... ArgTypes> void swap(function<R(ArgTypes...)>&, function<R(ArgTypes...)>&); template<class R, class... ArgTypes> bool operator==(const function<R(ArgTypes...)>&, nullptr_t) noexcept; template<class R, class... ArgTypes> bool operator==(nullptr_t, const function<R(ArgTypes...)>&) noexcept; template<class R, class... ArgTypes> bool operator!=(const function<R(ArgTypes...)>&, nullptr_t) noexcept; template<class R, class... ArgTypes> bool operator!=(nullptr_t, const function<R(ArgTypes...)>&) noexcept; // 搜索器: template<class ForwardIterator, class BinaryPredicate = equal_to<>> class default_searcher; template<class RandomAccessIterator, class Hash = hash<typename iterator_traits<RandomAccessIterator>::value_type>, class BinaryPredicate = equal_to<>> class boyer_moore_searcher; template<class RandomAccessIterator, class Hash = hash<typename iterator_traits<RandomAccessIterator>::value_type>, class BinaryPredicate = equal_to<>> class boyer_moore_horspool_searcher; template<class ForwardIterator, class BinaryPredicate = equal_to<>> default_searcher<ForwardIterator, BinaryPredicate> make_default_searcher(ForwardIterator pat_first, ForwardIterator pat_last, BinaryPredicate pred = BinaryPredicate()); template<class RandomAccessIterator, class Hash = hash<typename iterator_traits<RandomAccessIterator>::value_type>, class BinaryPredicate = equal_to<>> boyer_moore_searcher<RandomAccessIterator, Hash, BinaryPredicate> make_boyer_moore_searcher(RandomAccessIterator pat_first, RandomAccessIterator pat_last, Hash hf = Hash(), BinaryPredicate pred = BinaryPredicate()); template<class RandomAccessIterator, class Hash = hash<typename iterator_traits<RandomAccessIterator>::value_type>, class BinaryPredicate = equal_to<>> boyer_moore_horspool_searcher<RandomAccessIterator, Hash, BinaryPredicate> make_boyer_moore_horspool_searcher(RandomAccessIterator pat_first, RandomAccessIterator pat_last, Hash hf = Hash(), BinaryPredicate pred = BinaryPredicate()); // 散列函数主模板: template <class T> struct hash; // 函数对象绑定器: template <class T> inline constexpr bool is_bind_expression_v = is_bind_expression<T>::value; template <class T> inline constexpr int is_placeholder_v = is_placeholder<T>::value; }
[编辑] 类 std::reference_wrapper
namespace std { template <class T> class reference_wrapper { public : // 类型 using type = T; // 构造/复制/销毁 reference_wrapper(T&) noexcept; reference_wrapper(T&&) = delete; // 不绑定到临时对象 reference_wrapper(const reference_wrapper& x) noexcept; // 赋值 reference_wrapper& operator=(const reference_wrapper& x) noexcept; // 访问 operator T& () const noexcept; T& get() const noexcept; // 调用 template <class... ArgTypes> invoke_result_t<T&, ArgTypes...> operator() (ArgTypes&&...) const; }; }
[编辑] 类 std::is_bind_expression
namespace std { template<class T> struct is_bind_expression; }
[编辑] 类 std::is_placeholder
namespace std { template<class T> struct is_placeholder; }
[编辑] 类 std::bad_function_call
class bad_function_call : public std::exception { public: // 构造函数: bad_function_call() noexcept; };
[编辑] 类 std::function
namespace std { template<class> class function; // 未予定义 template<class R, class... ArgTypes> class function<R(ArgTypes...)> { public: using result_type = R; // construct/copy/destroy: function() noexcept; function(nullptr_t) noexcept; function(const function&); function(function&&); template<class F> function(F); function& operator=(const function&); function& operator=(function&&); function& operator=(nullptr_t) noexcept; template<class F> function& operator=(F&&); template<class F> function& operator=(reference_wrapper<F>) noexcept; ~function(); // function 修改器: void swap(function&) noexcept; // function 容纳: explicit operator bool() const noexcept; // function 调用: R operator()(ArgTypes...) const; // function 目标访问: const type_info& target_type() const noexcept; template<class T> T* target() noexcept; template<class T> const T* target() const noexcept; }; // 空指针比较: template <class R, class... ArgTypes> bool operator==(const function<R(ArgTypes...)>&, nullptr_t) noexcept; template <class R, class... ArgTypes> bool operator==(nullptr_t, const function<R(ArgTypes...)>&) noexcept; template <class R, class... ArgTypes> bool operator!=(const function<R(ArgTypes...)>&, nullptr_t) noexcept; template <class R, class... ArgTypes> bool operator!=(nullptr_t, const function<R(ArgTypes...)>&) noexcept; // 特化的算法: template <class R, class... ArgTypes> void swap(function<R(ArgTypes...)>&, function<R(ArgTypes...)>&); }
[编辑] 参阅
| <string> | 针对 std::string、std::u16string、std::u32string、std::wstring 特化 std::hash |
| <system_error> | 针对 std::error_code 特化 std::hash |
| <bitset> | 针对 std::bitset 特化 std::hash |
| <memory> | 针对 std::unique_ptr、std::shared_ptr 特化 std::hash |
| <typeindex> | 针对 std::type_index 特化 std::hash |
| <vector> | 针对 std::vector<bool> 特化 std::hash |
| <thread> | 针对 std::thread::id 特化 std::hash |

