std::experi...Comparable,(3)
okay bestie, this is the std::experi...Comparable,(3) page from the C++ Standard Libary (yes, that spelling is in the header, and honestly? iconic) β we're about to make equality concepts make sense π
β¨
π NAME π
the page name is literally this: std::experimental::ranges::EqualityComparable, - std::experimental::ranges::EqualityComparable,
β¨ Synopsis β¨
Defined in header <experimental/ranges/concepts>, and the synopsis goes a little like this:
template< class T >
concept bool EqualityComparable = WeaklyEqualityComparableWith<T, T>;
template< class T, class U >
concept bool EqualityComparableWith =
EqualityComparable<T> &&
EqualityComparable<U> &&
CommonReference<
const std::remove_reference_t<T>&,
const std::remove_reference_t<U>&> &&
EqualityComparable<
ranges::common_reference_t<
const std::remove_reference_t<T>&,
const std::remove_reference_t<U>&>> &&
WeaklyEqualityComparableWith<T, U>;
The source has two little markers in there: (1) (ranges TS) and (2) (ranges TS) β those point at the two explanations below, bestie π«Ά
- The concept
EqualityComparable<T>says the comparison operators==and!=onTactually reflect equality:==givestrueif and only if the operands are equal.EqualityComparable<T>is satisfied only if, given objectsaandbof typeT,bool(a == b)istrueif and only ifaandbare equal. And becausea == balso has to be equality preserving, that means==is symmetric and transitive, plus it's reflexive for every objectathat's equal to at least one other object. periodt π - The concept
EqualityComparableWith<T, U>says the comparison operators==and!=on (possibly mixed)TandUoperands give results that are consistent with equality. Comparing mixed operands gives results equivalent to comparing the operands converted to their common type. Formally,EqualityComparableWith<T, U>is satisfied only if, given any lvaluetof typeconst std::remove_reference_t<T>and any lvalueuof typeconst std::remove_reference_t<U>, and lettingCberanges::common_reference_t<const std::remove_reference_t<T>&, const std::remove_reference_t<U>&>, this holds:bool(t == u) == bool(C(t) == C(u)). no cap π§
π Equality preservation π
An expression is equality preserving if it gives equal outputs when given equal inputs.
- The inputs to an expression are its operands.
- The outputs of an expression are its result and all operands that the expression modifies (if any).
Every expression that has to be equality preserving is also required to be stable: two evaluations of that expression with the same input objects must have equal outputs, unless something explicitly modifies those input objects in between. literally the bare minimum π
π¦ Implicit expression variations π¦
A requires-expression that uses an expression that is non-modifying for some constant lvalue operand also implicitly requires extra variations of that expression. Those variations accept a non-constant lvalue or a (possibly constant) rvalue for the given operand β unless such an expression variation is explicitly required with differing semantics. These implicit expression variations have to meet the same semantic requirements as the declared expression. The extent to which an implementation validates the syntax of the variations is unspecified. slay but make it unspecified π
and that's the tea β source: http://cppreference.com, version/date: 2024.06.10, page: std::experi...Comparable,(3) β byeee bestie πβ¨
π¦ 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