std::experi...ranges::less(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

πŸ’… std::experimental::ranges::less

ok so bestie, buckle up β€” this is the man page for std::experimental::ranges::less, straight out of the C++ Standard Library docs (the cppreference ones, you know the vibe). It's a ranges TS situation, it's giving "function object that compares stuff", and honestly it ate. Let's get into it 🫢


✨ NAME ✨

std::experimental::ranges::less β€” literally exactly that, std::experimental::ranges::less. no notes, iconic of it πŸ’…


🌸 SYNOPSIS 🌸

Defined in header <experimental/ranges/functional> β€” that's where this little icon lives πŸŽ€

template< class T = void >
    requires StrictTotallyOrdered<T> ||
             Same<T, void> ||
             /* < on two const T lvalues invokes a built-in operator
                comparing pointers */
struct less;

template<>
    struct less<void>;
Both of those declarations are marked (ranges TS) in the original, bestie β€” just so you know what era we're in πŸ¦‹

So what even is this? It's a function object for performing comparisons. The primary template invokes operator< on const lvalues of type T. The specialization less<void> deduces the parameter types of the function call operator from the arguments (but not the return type). Slay πŸ’–

And a lil' fact for the vibe check: all specializations of less are Semiregular. periodt ✨


πŸŽ€ MEMBER TYPES πŸŽ€

  • is_transparent β€” member only of the less<void> specialization, and its definition is /* unspecified */ πŸ™ˆ (mysterious queen behavior, honestly)

πŸ‘‘ MEMBER FUNCTIONS πŸ‘‘

  • operator() β€” checks if the first argument is less than the second (public member function) πŸ’…

🌈 std::experimental::ranges::less::operator()

bestie there are TWO of these, ok, don't get them mixed up:

constexpr bool operator()(const T& x, const T& y) const;

(1) β€” member only of the primary less<T> template

template< class T, class U >
    requires StrictTotallyOrderedWith<T, U> ||
             /* std::declval<T>() < std::declval<U>() resolves to
                a built-in operator comparing pointers */
constexpr bool operator()(T&& t, U&& u) const;

(2) β€” member only of the less<void> specialization

Now the deets, numbered because we're organized like that:

  1. Compares x and y. Equivalent to return ranges::less<>{}(x, y);.
  2. Compares t and u. Equivalent to return std::forward<T>(t) < std::forward<U>(u);, except when that expression resolves to a call to a builtin operator< comparing pointers.
⚠️ and here's the pointer plot twist: when a call to (1) or (2) would invoke a built-in operator comparing pointers of type P, the result is instead determined as follows πŸ‘‡
  • Returns true if the (possibly converted) value of the first argument precedes the (possibly converted) value of the second argument in the implementation-defined strict total ordering over all pointer values of type P. This strict total ordering is consistent with the partial order imposed by the builtin operators <, >, <=, and >=.
  • Otherwise, returns false.
🫢 fr fr important: the behavior is undefined unless the conversion sequences from both T and U to P are equality-preserving (see below). don't skip that part, bestie, undefined behavior is not the main character energy you want 😭

πŸ’œ Equality preservation

An expression is equality preserving if it results in equal outputs given equal inputs. no cap ✨

  • 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 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. πŸ¦‹


πŸ”₯ NOTES πŸ”₯

Unlike std::less, ranges::less requires all six comparison operators β€” <, <=, >, >=, == and != β€” to be valid (via the StrictTotallyOrdered and StrictTotallyOrderedWith constraints). yeah, all six. it's thorough, it's extra, we love that for it πŸ‘‘


πŸ’€ EXAMPLE πŸ’€

This section is incomplete. Reason: no example 😭

(the docs really said "no thoughts, head empty" on this one, bestie β€” but I respect the honesty πŸ™ˆ)


πŸ¦‹ SEE ALSO πŸ¦‹

  • less β€” function object implementing x < y (class template) 🫢

πŸ“ CATEGORY πŸ“

  • Todo no example πŸŽ€ (yes, again. it's a whole thing.)

that's the whole page, bestie β€” you're officially an expert on std::experimental::ranges::less πŸ’–

kisses from http://cppreference.com, dated 2024.06.10 β€” go forth and compare things in the ranges TS style, mwah πŸ’…βœ¨πŸŒΈ

πŸ“¦ where this page comes from