Skip to content

Commit 9e2c8ec

Browse files
authored
Update set and remove_if syntax in "Function Objects in the C++ Standard Library" article
1 parent f8ed85f commit 9e2c8ec

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

docs/standard-library/function-objects-in-the-stl.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ The C++ Standard Library contains several function objects in the [`<functional>
4242

4343
```cpp
4444
template <class Key,
45-
class Traits=less<Key>,
46-
class Allocator=allocator<Key>>
47-
class set
45+
class Compare = std::less<Key>,
46+
class Allocator = std::allocator<Key>>
47+
class set;
4848
```
4949
5050
The second template argument is the function object [`less`](less-struct.md). This function object returns **`true`** if the first parameter is less than the second parameter. Since some containers sort their elements, the container needs a way of comparing two elements. The comparison is done by using the function object. You can define your own sorting criteria for containers by creating a function object and specifying it in the template list for the container.
@@ -54,11 +54,11 @@ The second template argument is the function object [`less`](less-struct.md). Th
5454
Another use of function objects is in algorithms. For example, the [`remove_if`](algorithm-functions.md#remove_if) algorithm is declared as follows:
5555
5656
```cpp
57-
template <class ForwardIterator, class Predicate>
57+
template <class ForwardIterator, class UnaryPredicate>
5858
ForwardIterator remove_if(
5959
ForwardIterator first,
6060
ForwardIterator last,
61-
Predicate pred);
61+
UnaryPredicate pred);
6262
```
6363

6464
The last argument to `remove_if` is a function object that returns a boolean value (a *predicate*). If the result of the function object is **`true`**, then the element is shifted such that it's beyond the new end returned by `remove_if`. You can use any of the function objects declared in the [`<functional>`](functional.md) header for the argument `pred` or you can create your own.

0 commit comments

Comments
 (0)