constexpr const Pred& pred() const; // (1) C++23
概要
メンバ変数として保持している、述語を取得する。
効果
- (1) :
return pred_;
例
#include <ranges>
#include <vector>
#include <functional>
#include <iostream>
int main() {
std::vector<int> v = {1, 2, 2, 3, 0, 4, 5, 2};
std::ranges::chunk_by_view cv{v, std::ranges::less_equal{}};
// 述語を取得
const auto& predicate = cv.pred();
// 述語を使用して比較
std::cout << "predicate(1, 2): " << predicate(1, 2) << std::endl;
std::cout << "predicate(3, 0): " << predicate(3, 0) << std::endl;
}
出力
predicate(1, 2): 1
predicate(3, 0): 0
バージョン
言語
- C++23
処理系
- Clang: 17 ✅
- GCC: 14.0 ✅
- Visual C++: 2022 Update 3 ✅