O'Reilly logo

C++ Common Knowledge: Essential Intermediate Programming by Stephen C. Dewhurst

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Item 20. STL Function Objects

How did we ever get by without the STL? Not only is it easier and faster to write complex code, but that code is both standard and highly optimized.

std::vector<std::string> names;//...std::sort( names.begin(), names.end() );

Another nice thing about the STL is that it’s highly configurable. In the code above, we used string’s less-than operator to sort a vector of strings, but we don’t always have a less-than operator to work with, or we may not want to sort in ascending order.

image

The State class (which represents a state of the union) doesn’t have a less-than operator, and we probably don’t want to implement one ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required