Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Standard Template Library
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== Functions === The STL includes classes that [[Function overloading|overload]] the function call operator ({{Cpp|operator()}}). Instances of such classes are called functors or [[function objects]]. Functors allow the behavior of the associated function to be parameterized (e.g. through arguments passed to the functor's [[Constructor (object-oriented programming)|constructor]]) and can be used to keep associated per-functor state information along with the function. Since both functors and function pointers can be invoked using the syntax of a function call, they are interchangeable as arguments to templates when the corresponding parameter only appears in function call contexts. A particularly common type of functor is the [[Predicate (computer programming)|predicate]]. For example, algorithms like {{Cpp|find_if}} take a [[unary function|unary]] predicate that operates on the elements of a sequence. Algorithms like sort, partial_sort, nth_element and all sorted [[Container (data structure)|containers]] use a [[binary function|binary]] predicate that must provide a [[strict weak ordering]], that is, it must behave like a [[set membership|membership]] test on a transitive, non-reflexive and asymmetric [[binary relation]]. If none is supplied, these algorithms and containers use [http://www.sgi.com/tech/stl/less.html less] by default, which in turn calls the less-than-operator <.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)