Abseil C++

An open-source collection of C++ library code designed to augment the C++ standard library

  • Tip of the Week #144: Heterogeneous Lookup in Associative Containers
    https://abseil.io/tips/144

    Originally posted as TotW #144 on March 23, 2018

    By Samuel Benzaquen

    Introduction

    Associative containers associate an element with a key. Inserting into or looking up an element from the container requires an equivalent key. In general, containers require the keys to be of a specific type, which can lead to inefficiencies at call sites that need to convert between near-equivalent types (like std::string and string_view).

    To avoid this unnecessary work, some containers provide heterogeneous lookup. This feature allows callers to pass keys of any type (as long as the user-specified comparator functor supports them). See std::map::find for an example of this feature in an STL container.

    Transparent Functors

    A transparent functor is one that accepts more than one particular type. It must (...)