std::ptr_fun
From cppreference.com
< cpp | utility | functional
C++
Feature test macros (C++20)
Concepts library (C++20)
Metaprogramming library (C++11)
Ranges library (C++20)
Filesystem library (C++17)
Concurrency support library (C++11)
Execution control library (C++26)
Utilities library
Type support (basic types, RTTI)
Library feature-test macros (C++20)
(C++11)
(C++20)
(C++26)
(C++20)
Coroutine support (C++20)
Contract support (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)
(C++20)
(C++20)
(C++20)(C++20)(C++20)
(C++20)(C++20)(C++20)
General utilities
Relational operators (deprecated in C++20)
(C++20)(C++20)(C++20)
(C++20)(C++20)(C++20)
(C++20)
Swap and type operations
Common vocabulary types
Function objects
(C++11)
(C++23)
(C++26)
(C++26)
(C++11)
(C++11)
(C++20)(C++23)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)(C++11)
(C++20)(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++14)
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
(C++17)
(C++17)
(C++17)
(C++17)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(until C++17*)
(until C++17*)
ptr_fun
(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*)
Defined in header
<functional>
template< class Arg, class Result >
(1)
(deprecated in C++11) std::pointer_to_unary_function <Arg,Result>
(removed in C++17)
template< class Arg1, class Arg2, class Result >
(2)
(deprecated in C++11) std::pointer_to_binary_function <Arg1,Arg2,Result>
(removed in C++17)
Creates a function wrapper object (either std::pointer_to_unary_function or std::pointer_to_binary_function ), deducing the target type from the template arguments.
1) Effectively calls std::pointer_to_unary_function <Arg,Result>(f).
2) Effectively calls std::pointer_to_binary_function <Arg1,Arg2,Result>(f).
This function and the related types are deprecated as of C++11 in favor of the more general std::function and std::ref , both of which create callable adaptor-compatible function objects from plain functions.
[edit] Parameters
f
-
pointer to a function to create a wrapper for
[edit] Return value
A function object wrapping f.
[edit] Exceptions
May throw implementation-defined exceptions.
[edit] Example
Run this code
#include <algorithm> #include <functional> #include <iostream> #include <string_view> constexpr bool is_vowel(char c) { return std::string_view {"aeoiuAEIOU"}.find(c) != std::string_view::npos ; } int main() { std::string_view s = "Hello, world!"; std::ranges::copy_if (s, std::ostreambuf_iterator <char>(std::cout ), std::not1 (std::ptr_fun(is_vowel))); #if 0 // C++11 alternatives: std::not1 (std::cref (is_vowel))); std::not1 (std::function <bool(char)>(is_vowel))); [](char c) { return !is_vowel(c); }); // C++17 alternatives: std::not_fn (is_vowel)); #endif }
Output:
Hll, wrld!
[edit] See also
(C++23)
(class template) [edit]