Skip to content

Equality Framework

Felix Gündling edited this page Oct 7, 2019 · 6 revisions

Introduction

Writing comparison operators can be tedious. Using std::tie(member, ...) == std::tie(member, ...) may help but is still a lot of boilerplate code that should be generated automatically (i.e. through C++ templates). Cista offers such code generation in the equal_to.h header file.

Interface Difference to std::equal_to

The cista::equal_to<T> class works like std::equal_to<T> with the difference that it can compare instances of type T (fixed for std::equal_to<T>) with any other type T1 (instead of only T vs. T). This comes in handy for lookup operations like hash_map::find() where it is now possible to search for a std::string_view in a cista::hash_map<std::string, int> without actually constructing a std::string. Thus, it saves (de)allocations with each lookup.

How it Works

Different variants are checked in the following order:

  • First, ...