xentara-utils v2.0.4
The Xentara Utility Library
|
Helper concept for implementing equality comparison operators. More...
#include <xentara/utils/tools/Concepts.hpp>
Helper concept for implementing equality comparison operators.
This concept can be used instead of std::equality_comparable_with as a constraint for implementing equality comparison member operators for a class. It behaves just like std::equality_comparable_with, except that it excludes a single type.
This operator is used as a contraint for the parameter of a equality comparison operator in the case where one would normally use std::equality_comparable_with. Consider a class that has a name, and the class should be comparable with anything that can be compared with that name. We would like the implementation for this class to look like this:
Unfortunately, this will result in an error on most compilers when trying to compare two instances of MyClass, as the containt std::equality_comparable_with on operator==(const Lhs &) with try to take into account possible instantiations of operator==(const Lhs &) itself, resulting in an infinite recursion. To avoid this, MyClass can be explicitly excluded by using EqualityComparableWithExcept instead of std::equality_comparable_with:
Now, operator==(const Lhs &) can never be a cadidate for comparing two instances of MyClass, resolving the recursion.