Learn how the STL provides arithmetic functors for use with transform and other functions that require operator functions.
- The arithmetic functors are standard template functors…defined in the functional header, it's right there,…of the STL.…Here I have a working copy of arithmetic.cpp…from chapter five of the exercise files.…And I've defined down here three vectors,…v1, v2, which have some numbers that we'll do arithmetic on,…and v3 for the results.…I have a functor defined, this is the plus functor,…I've created an object from the class,…course if we wanted to we could use the functor directly…like this with parentheses with a function call operator.…
Really to get the full value of a functor,…you'll want to use it as an object.…So when I build and run,…you'll notice that the plus functor…adds these numbers together,…so 26 plus one is 27,…52 plus two is 54, et cetera.…The minus functor,…will subtract the two numbers.…So we're using the binary version of transform here.…It has the five arguments.…
And here we got the subtraction.…We can multiply with the multiplies functor.…Build and run we have the product of those two numbers.…And we can divide with the divides functor.…
- Template fundamentals
- STL containers
- Accessing iterators
- Output, forward, and bidirectional iterators
- The transform function
- Transforming strings and types
- Arithmetic, relational, and logical functions
- STL algorithms
Skill Level Intermediate
2. STL Containers
3. STL Iterators
5. STL Functions
6. STL Algorithm
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.