-
Notifications
You must be signed in to change notification settings - Fork 118
Equality Framework
Writing comparison operators can be tedious. Using the std::tie(member, ...) == std::tie(member, ...)
idiom/pattern 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.
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.
Different variants are checked in the following order:
- First, if both,
T
andT1
are iterable, equality of all entries are checked usingstd::equal
. - If both are standard layout, non-polymorphic aggregate types, or implement the
cista_members
function (see here,cista::to_tuple
will be applied and the entries of the resulting tuples are compared. - Otherwise, the
T::operator==(T1)
comparison is used.