liveBook · Manning

Std::equal_to

As explained in Learn C++ by Example

std::equal_to is a C++ standard library function-object template that compares two values for equality.

std::equal_to is a function-object template that compares two values by calling operator==. In std::unordered_map, it is the default KeyEqual type used alongside std::hash to decide whether keys are equal, including after a hash collision. section 8.2.1

Comparing tuple keys

For two equal std::tuple values, bool match = std::equal_to{}.operator()(t1, t2); performs the same comparison as bool match = t1 == t2;. A tuple therefore works as an unordered-map key when a suitable hash is also provided. section 8.2.1

How Learn C++ by Example covers it

How deep it goes
Defines the call to operator== and demonstrates tuple comparison, but does not examine implementation internals.
Examples
Compares two equal tuples and supplies the default KeyEqual in an unordered_map declaration.
What it assumes
Assumes familiarity with operator==, templates, tuples, and unordered_map key hashing.
What you can do after
Evaluate equality predicates and understand how unordered_map checks keys after hashing.
How it connects
Connects std::equal_to with unordered_map, std::hash, tuple, operator==, and hash collisions.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn C++ by Example. The section links point to the parts of the book it draws on.