Open C++ Libraries.org develop
Loading...
Searching...
No Matches
rope.inl
1// SPDX-License-Identifier: BSL-1.0
2// Copyright 2025-2026, Amlal El Mahrouss (amlal@nekernel.org)
3// Distributed under the Boost Software License, Version 1.0. (See accompanying
4// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5// Official repository: https://github.com/open-cpp-libraries/tproc
6
7#ifndef OCL_TPROC_ROPE_INL
8#define OCL_TPROC_ROPE_INL
9
10namespace ocl::tproc::rope
11{
12
13 template <typename It, class Pred>
14 Pred find(It begin, It end, Pred pred)
15 {
16 for (auto it = begin; it != end; ++it)
17 {
18 if (*it == pred)
19 {
20 return *it;
21 }
22 }
23
24 return end;
25 }
26
27 template <typename It, class Pred>
28 Pred find_if(It begin, It end, Pred pred)
29 {
30 for (auto it = begin; it != end; ++it)
31 {
32 if (pred(it))
33 {
34 return *it;
35 }
36 }
37
38 return end;
39 }
40
41 template <typename It, class Pred>
42 typename Pred::size_type erase(It begin, It end, Pred pred)
43 {
44 typename Pred::size_type count{};
45
46 for (auto it = begin; it != end;)
47 {
48 if (*it == pred)
49 {
50 it = begin.erase(it);
51 ++count;
52 }
53 else
54 {
55 ++it;
56 }
57 }
58
59 return count;
60 }
61
62 template <typename It, class Pred>
63 typename Pred::size_type erase_if(It begin, It end, Pred)
64 {
65 typename Pred::size_type count{};
66
67 for (auto it = begin; it != end;)
68 {
69 if (pred(it))
70 {
71 it = begin.erase(it);
72 ++count;
73 }
74 else
75 {
76 ++it;
77 }
78 }
79
80 return count;
81 }
82
83} // namespace ocl::tproc::rope
84
85#endif