opynsim
Unofficial C++ Documentation
Loading...
Searching...
No Matches
ranges.h
Go to the documentation of this file.
1#pragma once
2
3#include <algorithm>
4#include <iterator>
5#include <ranges>
6#include <utility>
7
8namespace osc::cpp23
9{
10 // see: std::ranges::contains
11 template<
12 std::input_iterator I,
13 std::sentinel_for<I> S,
14 class T,
15 class Proj = std::identity
16 >
17 requires std::indirect_binary_predicate<std::ranges::equal_to, std::projected<I, Proj>, const T*>
18 constexpr bool contains(I first, S last, const T& value, Proj proj = {})
19 {
20 return std::ranges::find(first, last, value, proj) != last;
21 }
22
23 // see: std::ranges::contains
24 template<
25 std::ranges::forward_range R,
26 class T,
27 class Proj = std::identity
28 >
29 requires std::indirect_binary_predicate<std::ranges::equal_to, std::projected<std::ranges::iterator_t<R>, Proj>, const T*>
30 constexpr bool contains(R&& r, const T& value, Proj proj = {})
31 {
32 return contains(std::ranges::begin(r), std::ranges::end(r), value, std::move(proj));
33 }
34}
Definition algorithm.h:4
constexpr bool contains(I first, S last, const T &value, Proj proj={})
Definition ranges.h:18
constexpr U to(T &&value)
Definition conversion.h:56