Summary
This episode explores transparent comparators, a C++14 feature that enables more efficient lookups in associative containers like std::set and std::map. Jason demonstrates how traditional comparators force the creation of temporary objects when searching by just a key value, while transparent comparators allow direct comparison with different types. By adding the 'is_transparent' type alias and implementing templated comparison operators, containers can perform lookups without constructing unnecessary temporary objects, resulting in more efficient code.
Related C++ Standard Sections
This episode covers topics found in these sections of the C++ standard:
-
[comparisons.greater]52% match -
[comparisons.less]52% match -
[comparisons.three.way]52% match -
[comparisons.less.equal]52% match -
[comparisons.greater.equal]52% match -
[comparisons.equal.to]52% match -
[comparisons.not.equal.to]51% match -
[range.cmp]51% match -
[comparisons]50% match -
[arithmetic.operations.divides]49% match - + 10 more related sections