Section

Function objects

A function object is any object for which the function call operator is defined. C++ provides many built-in function objects as well as support for creation and manipulation of new function objects.

# Declarations

template< class Fn, class... Args >
concept /*callable*/ =
requires (Fn&& fn, Args&&... args) {
std::forward<Fn>(fn)(std::forward<Args>(args)...);
};

(exposition only*)

template< class Fn, class... Args >
concept /*nothrow-callable*/ =
/*callable*/<Fn, Args...> &&
requires (Fn&& fn, Args&&... args) {
{ std::forward<Fn>(fn)(std::forward<Args>(args)...) } noexcept;
};

(exposition only*)

template< class Fn, class... Args >
using /*call-result-t*/ = decltype(std::declval<Fn>()(std::declval<Args>()...));

(exposition only*)

template< const auto& T >
using /*decayed-typeof*/ = decltype(auto(T));

(exposition only*)

# Defect reports

DRApplied toBehavior as publishedCorrect behavior
LWG 185C++98using function objects improved the program efficiencyremoved the claim
LWG 660C++98function objects for bitwise operations are missingadded
LWG 2149C++98function objects taking one or two arguments were required toprovide nested types to denote the argument and result typesnot required
LWG 2219C++11INVOKE did not handle std::reference_wrapper correctlyhandles correctly
LWG 2420C++11INVOKE did not discard the return value if R is voiddiscards the return value in this case
LWG 2926(P0604R0)C++11the syntax of the INVOKE operation with a returntype R was INVOKE(f, t1, t2, …, tN, R)changed toINVOKE(f, t1, t2, …, tN)
LWG 3655C++11INVOKE did not handle unions correctlydue to the resolution of LWG issue 2219handles correctly

ranges

Range-based function object utilities from std::ranges (since C++20).

6 pages
Pages in this section