C++ has included some functional programming features for quite sometime. Troy explores accumulate in this video.
- [Instructor] At last we've reached…the Accumulate function.…So here we will…do int results equals accumulate…and accumulate takes four parameters.…It's going to take a filtered collection dot begin…that is the begin iterator, a filtered…collection dot end for end iterator,…do a comma and then go to the next line.…
Then it takes a, and in this case…it's going to be an integer value,…which is the initial value for the accumulate.…And in our case, it's going to be zero…'cause we want to add all our numbers together…and we're going to start at zero.…Then it takes the lambda function,…which is a binary operation.…And so this takes two values,…the first one's going to be int total…and the second one we're going to call int current.…Then inside we're going to say…return total plus current.…
And then a semi-colon, end of our curly brace,…and then we're going to have a semi-colon.…And right here we'll do a c out.…And we'll call this accumulate…and an end l, then we'll do another c out.…And we'll say that…results equal results.…
- Unit testing and functional programming
- Function and Lambda functions
- C++ templates
- Working with the Standard Template Library and Boost.Hana
- Functional reactive programming
Skill Level Intermediate
2. Functional Programming in Modern C++
3. Template Metaprogramming
4. Functional Reactive Programming
RxCpp library5m 21s
- 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.