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.

Logical functors

Logical functors

- [Instructor] The logical operator functors, or standard template functors, defined in the functional header of the STL. And there's the functional header there. Here I have a working copy of logical.cpp from chapter five of the exercise files. The transformation function down here is the binary version, and I have three vectors of ints. And of course these can be any logical, compatible type, so any scaler value. They could just easily be bool. If we build and run this, you see that the results are in ones and zeroes. If I change all these to bool, it works exactly the same. And build and run. The logical and does what you'd expect it to do. In each of the positions where both of these values are true, the result will be true. The logical or. We'll run that. That is true where you have a one in either place. And the logical not is actually a unary function. So I can take this out and when I build and run, it gives you the inverse of our V1 vector. These logical operators are often…

Contents