Saurabh Singh describes in a brief tutorial on how to correctly implement the comparator function for STL containers and algorithms.
Strict Weak Ordering and STL
by Saurabh Singh
From the article:
If you had ever used a map or set or even std::sort I bet you would have to give a comparator function. (Or an overload to the < (less than) operator).
I will try to give an overview of how certain associative stl containers use this property for ordering the elements.
Almost all stl containers rely on strict weak ordering A strict weak ordering defines the relative position of elements in terms of precedence of one item over other. For eg. if you have a room full of person and you have to form a queue based on their height, a person with "lesser" height will "precede" the person with greater height. For a function to be satisfying strict weak ordering following conditions need to be met.The PDF version of the document is available here.
Add a Comment
Comments are closed.