From Jason Turner
Watch on YouTube

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.

Resources

Tags