Summary
This episode explains how to use custom comparators with C++ standard library associative containers like std::set and std::map. Jason demonstrates why simply implementing operator<() on your custom types can be problematic, particularly when the natural ordering doesn't match your desired container behavior. The solution is to create a custom comparator type with an operator() that implements the specific comparison logic needed, then provide this type as the second template parameter to the container.
Related C++ Standard Sections
This episode covers topics found in these sections of the C++ standard:
-
[comparisons]75% match -
[comparisons.three.way]49% match -
[set]40% match