From the course: C++ Templates and the STL
Unlock this course with a free trial
Join today to access over 22,500 courses taught by industry experts.
Testing conditions - C++ Tutorial
From the course: C++ Templates and the STL
Testing conditions
- [Instructor] The STL has a few simple algorithms for testing conditions on ranges of elements. Here I have a working copy of conditional dot CPP from chapter six of the exercise files. These conditional algorithms use a predicate function and so I here have a function called is prime, a template function that takes one argument so it's a unary predicate, and when I come down here into main, you see I have a vector of ints containing a list of prime numbers under 100. And then we have this all of function, which is from the algorithm header, which tests all of the elements in a container against a predicate and in this case, it's testing if they are prime numbers, and it returns true or false. And when I build and run, of course my list of prime numbers are all prime, but if I were to come in here and add another one, say 40, which is not a prime number. And when I build and run, it says false. Course, these don't need to be in order. I can put that wherever I want and it will still…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.