Skip to content

Commit 6a42cc6

Browse files
committed
refs match fundamental type variants
#feat
1 parent 297c551 commit 6a42cc6

27 files changed

+1582
-917
lines changed

include/mrdocs/Support/Algorithm.hpp

+55-5
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ requires std::equality_comparable_with<El, std::ranges::range_value_t<Range>>
2626
bool
2727
contains(Range const& range, El const& el)
2828
{
29-
return std::find(range.begin(), range.end(), el) != range.end();
29+
return std::find(
30+
std::ranges::begin(range),
31+
std::ranges::end(range), el) != std::ranges::end(range);
3032
}
3133

3234
// A second overload where the range is an initializer list
@@ -41,7 +43,9 @@ requires std::equality_comparable_with<T, U>
4143
bool
4244
contains(std::initializer_list<T> const& range, U const& el)
4345
{
44-
return std::find(range.begin(), range.end(), el) != range.end();
46+
return std::find(
47+
std::ranges::begin(range),
48+
std::ranges::end(range), el) != std::ranges::end(range);
4549
}
4650

4751
/** Determine if a range contains any of the specified elements.
@@ -54,15 +58,16 @@ requires std::equality_comparable_with<std::ranges::range_value_t<Els>, std::ran
5458
bool
5559
contains_any(Range const& range, Els const& els)
5660
{
57-
return std::ranges::find_first_of(range, els) != range.end();
61+
return std::ranges::find_first_of(range, els) != std::ranges::end(range);
5862
}
5963

64+
/// @copydoc contains_any(Range const&, Els const&)
6065
template <std::ranges::range Range, class El>
6166
requires std::equality_comparable_with<El, std::ranges::range_value_t<Range>>
6267
bool
6368
contains_any(Range const& range, std::initializer_list<El> const& els)
6469
{
65-
return std::ranges::find_first_of(range, els) != range.end();
70+
return std::ranges::find_first_of(range, els) != std::ranges::end(range);
6671
}
6772

6873
/** Determine if a range contains at least N instances of the specified element.
@@ -90,10 +95,55 @@ contains_n(Range const& range, El const& el, std::size_t n)
9095
return false;
9196
}
9297

98+
/** Determine if a range contains at least N instances of any of the specified elements.
99+
@param range The range to search.
100+
@param els The elements to search for.
101+
@param n The number of instances to search for.
102+
@return True if the element is found, false otherwise.
103+
*/
104+
template <std::ranges::range Range, std::ranges::range Els>
105+
requires std::equality_comparable_with<std::ranges::range_value_t<Els>, std::ranges::range_value_t<Range>>
106+
bool
107+
contains_n_any(Range const& range, Els const& els, std::size_t n)
108+
{
109+
for (auto const& item : range)
110+
{
111+
if (contains(els, item))
112+
{
113+
--n;
114+
if (n == 0)
115+
{
116+
return true;
117+
}
118+
}
119+
}
120+
return false;
121+
}
122+
123+
/// @copydoc contains_n_any(Range const&, Els const&, std::size_t)
124+
template <std::ranges::range Range, class El>
125+
requires std::equality_comparable_with<El, std::ranges::range_value_t<Range>>
126+
bool
127+
contains_n_any(Range const& range, std::initializer_list<El> const& els, std::size_t n)
128+
{
129+
for (auto const& item : range)
130+
{
131+
if (contains(els, item))
132+
{
133+
--n;
134+
if (n == 0)
135+
{
136+
return true;
137+
}
138+
}
139+
}
140+
return false;
141+
}
142+
93143
/** Find the last element in a range that matches an element in the specified range.
94144
@param range The range to search.
95145
@param els The elements to search for.
96-
@return An iterator to the last element found, or range.end() if not found.
146+
@return An iterator to the last element found, or std::ranges::end(range) if not found.
97147
*/
98148
template <std::ranges::range Range, std::ranges::range Els>
99149
requires std::equality_comparable_with<std::ranges::range_value_t<Els>, std::ranges::range_value_t<Range>>

0 commit comments

Comments
 (0)