Lecture overview -- Keyboard shortcut: 'u'  Previous page: Using the sort algorithm -- Keyboard shortcut: 'p'  Next page: Use of function objects in STL -- Keyboard shortcut: 'n'  Lecture notes - all slides and notes together  slide -- Keyboard shortcut: 't'  Help page about these notes  Alphabetic index  Course home  Lecture 5 - Page 37 : 39
Notes about C++
Templates and The Standard Library
An example of for-each and function objects

An sample use of for-each() to find out if a list is sorted

Initial discussions of possible solutions to this simple problem

y:/Kurt/Files/Advanced-programming-cpp/cpp/kn/algorithms/for-each-examples/for-each-1.cppA possible use of for-each to solve this problem.


  • Observations

    • Use of objects as functions via an overload of the application operator

    • A function surrounded by private, mutable state

    • Use of the returned value from for-each

y:/Kurt/Files/Advanced-programming-cpp/cpp/kn/algorithms/for-each-examples/adjacent-1.cppFollowing the advice: Solve the problem with a more appropriate algorithm.


  • Observation

    • greater is a wrapper around the > operator, §18.4.2.1

y:/Kurt/Files/Advanced-programming-cpp/cpp/kn/algorithms/for-each-examples/greater-and-binary-function.cppThe type greater and its base class.