std::experi...mparableWith(3)
π NAME π
okay so bestie, welcome to std::experi...mparableWith(3) β that's a page straight out of the C++ Standard Libary manual (yes the whole gang of man pages lives there), and the star of the show today is std::experimental::ranges::WeaklyEqualityComparableWith</p>. say it with me: Weakly. Equality. Comparable. With. it's a concept, it's iconic, it's giving "can these two things be compared for equality in either order and do they actually agree about it" πβ¨
β¨ Synopsis β¨
first things first, where does this lil guy even live? π
Defined in header <experimental/ranges/concepts>
and here's the whole declaration, verbatim, no cap, don't touch a single character π
template< class T, class U >
concept bool WeaklyEqualityComparableWith =
requires(const std::remove_reference_t<T>& t,
const std::remove_reference_t<U>& u) {
{ t == u } -> Boolean&&; (ranges TS)
{ t != u } -> Boolean&&;
{ u == t } -> Boolean&&;
{ u != t } -> Boolean&&;
};
so likeβ¦ the concept WeaklyEqualityComparableWith<T, U> is basically saying: an object of type T and an object of type U can be compared for equality with each other (in either order!!) using both == and !=, and the results of the comparisons are consistent. consistency is the whole vibe check here, bestie β if you say two things are equal one way, you gotta say it the other way too π
more formally (put your serious glasses on π), WeaklyEqualityComparableWith<T, U> is satisfied only if, given:
t, an lvalue of typeconst std::remove_reference_t<T>, andu, an lvalue of typeconst std::remove_reference_t<U>,
the following are true:
t == u,u == t,t != u,u != thave the same domain;bool(u == t) == bool(t == u);bool(t != u) == !bool(t == u); andbool(u != t) == bool(t != u).
see? the domain's gotta match, the equality's gotta match both directions, the != has got to be the literal opposite of ==, and the flipped != has gotta agree with the other !=. symmetry and logic, slay π
π¦ Equality preservation π¦
an expression is equality preserving if it results in equal outputs given equal inputs. same in, same out, periodt β¨
- The inputs to an expression consist of its operands.
- The outputs of an expression consist of its result and all operands modified by the expression (if any).
every expression that's required to be equality preserving is further required to be stable: two evaluations of such an expression with the same input objects must have equal outputs absent any explicit intervening modification of those input objects. translation: don't be out here changing your answer when nobody touched anything, that's so not it π
unless noted otherwise, every expression used in a requires-expression is required to be equality preserving and stable, and the evaluation of the expression may only modify its non-constant operands. Operands that are constant must not be modified. like, hands off the const ones, fr fr π«Ά
πΈ Implicit expression variations πΈ
a requires-expression that uses an expression that's non-modifying for some constant lvalue operand also implicitly requires additional variations of that expression that accept a non-constant lvalue or (possibly constant) rvalue for the given operand β unless such an expression variation is explicitly required with differing semantics. these implicit expression variations must meet the same semantic requirements of the declared expression. the extent to which an implementation validates the syntax of the variations is unspecified. iykyk π
π See also π
EqualityComparableβ specifies thatoperator ==is an equivalence relationEqualityComparableWith(concept)
go read those next bestie, they're the sibling concepts and they ate πβ
and that's the page!! π shoutout to http://cppreference.com for hosting it, version 2024.06.10, dated 2024.06.10, filed under std::experi...mparableWith(3) β mwah, love u cppreference, this one was giving main character energy ππ¦π
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms