Namespaces
Variants

std::ranges::drop_while_view<V,Pred>:: pred

From cppreference.net
Ranges library
Range adaptors
constexpr const Pred & pred ( ) const ;
(自 C++20 起)

返回对存储谓词的引用。

如果 * this 未存储谓词(例如在向 * this 赋值时抛出异常,该操作会通过复制构造或移动构造来创建 Pred 对象),则行为未定义。

参数

(无)

返回值

对存储的谓词 pred_ 的引用。

示例

#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';
}

输出:

predicate( 0) : true
predicate(-1) : true
predicate(-2) : true
predicate( 3) : false
predicate( 1) : false
predicate( 4) : false
predicate( 1) : false
predicate( 5) : false