std::experi...ranges::less(3)
π 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 theless<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:
- Compares
xandy. Equivalent toreturn ranges::less<>{}(x, y);. - Compares
tandu. Equivalent toreturn std::forward<T>(t) < std::forward<U>(u);, except when that expression resolves to a call to a builtinoperator<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 typeP, the result is instead determined as follows π
- Returns
trueif 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 typeP. 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 bothTandUtoPare 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 implementingx < 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
- 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