std::ranges..._view::pred(3)
std::ranges..._view::pred(3) π
okay so bestie, this is the std::ranges..._view::pred(3) page from the C++ Standard Libary manual β yes, that's the manual name, typo and all, and we are not fixing it because it's iconic. It's all about std::ranges::drop_while_view::pred, which is a tiny little accessor with a very serious little warning sticker on it. π
NAME π
std::ranges::drop_while_view::pred - std::ranges::drop_while_view::pred
Synopsis π¦
constexpr const Pred& pred() const; (since C++20)
The way this works: it hands you back a reference to the stored predicate. That's the whole main character move. π«Ά
π¨ undefined behavior alert, fr fr: if*thisdoes not store a predicate (e.g. an exception is thrown on the assignment to*this, which copy-constructs or move-constructs aPred), the behavior is undefined ππ. That is not a vibe check you want to fail. Do not rely on it, and please do not go poking it on purpose.
Parameters π«Ά
(none) β literally none, bestie π
Return value β¨
A reference to the stored predicate. That's it. That's the whole return value. Slay. π
Example πΈ
bestie, here's the code, and yes, keep every character exactly as it is β this is not a drill π
// Run this code
#include <array>
#include <iomanip>
#include <iostream>
#include <ranges>
int main()
{
constexpr std::array data{0, -1, -2, 3, 1, 4, 1, 5};
auto view = std::ranges::drop_while_view
{
data, [](int x) { return x <= 0; }
};
std::cout << std::boolalpha;
for (int x : data)
std::cout << "predicate(" << std::setw(2) << x << ") : "
<< view.pred()(x) << '\n';
}
Output: π
predicate( 0) : true
predicate(-1) : true
predicate(-2) : true
predicate( 3) : false
predicate( 1) : false
predicate( 4) : false
predicate( 1) : false
predicate( 5) : false
okay bestie, that's the page! source/version and date for the footer: http://cppreference.com Β· 2024.06.10 β mwah, periodt πβ¨π«Ά
π¦ 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