Skip to content

Commit 3cf637a

Browse files
author
Hana Dusíková
committed
merge comparison and std::data(), std::size() support
2 parents 72ea419 + 11edf31 commit 3cf637a

File tree

3 files changed

+232
-186
lines changed

3 files changed

+232
-186
lines changed

include/ctre/return_type.hpp

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ template <size_t Id, typename Name = void> struct captured_content {
5454
constexpr CTRE_FORCE_INLINE operator bool() const noexcept {
5555
return _matched;
5656
}
57+
58+
constexpr CTRE_FORCE_INLINE const auto * data() const noexcept {
59+
return &*_begin;
60+
}
5761

5862
constexpr CTRE_FORCE_INLINE auto size() const noexcept {
5963
return static_cast<size_t>(std::distance(_begin, _end));
@@ -86,6 +90,19 @@ template <size_t Id, typename Name = void> struct captured_content {
8690
constexpr CTRE_FORCE_INLINE static size_t get_id() noexcept {
8791
return Id;
8892
}
93+
94+
friend CTRE_FORCE_INLINE constexpr bool operator==(const storage & lhs, std::basic_string_view<char_type> rhs) noexcept {
95+
return lhs.view() == rhs;
96+
}
97+
friend CTRE_FORCE_INLINE constexpr bool operator!=(const storage & lhs, std::basic_string_view<char_type> rhs) noexcept {
98+
return lhs.view() != rhs;
99+
}
100+
friend CTRE_FORCE_INLINE constexpr bool operator==(std::basic_string_view<char_type> lhs, const storage & rhs) noexcept {
101+
return lhs == rhs.view();
102+
}
103+
friend CTRE_FORCE_INLINE constexpr bool operator!=(std::basic_string_view<char_type> lhs, const storage & rhs) noexcept {
104+
return lhs != rhs.view();
105+
}
89106
};
90107
};
91108

@@ -226,7 +243,7 @@ template <typename Iterator, typename... Captures> class regex_results {
226243
#endif
227244
return _captures.template select<Name>();
228245
}
229-
static constexpr size_t size() noexcept {
246+
static constexpr size_t count() noexcept {
230247
return sizeof...(Captures) + 1;
231248
}
232249
constexpr CTRE_FORCE_INLINE regex_results & matched() noexcept {
@@ -265,6 +282,14 @@ template <typename Iterator, typename... Captures> class regex_results {
265282
return _captures.template select<0>().to_string();
266283
}
267284

285+
constexpr CTRE_FORCE_INLINE size_t size() const noexcept {
286+
return _captures.template select<0>().size();
287+
}
288+
289+
constexpr CTRE_FORCE_INLINE const auto * data() const noexcept {
290+
return _captures.template select<0>().data();
291+
}
292+
268293
constexpr CTRE_FORCE_INLINE regex_results & set_start_mark(Iterator pos) noexcept {
269294
_captures.template select<0>().set_start(pos);
270295
return *this;
@@ -284,6 +309,18 @@ template <typename Iterator, typename... Captures> class regex_results {
284309
_captures.template select<Id>().set_end(pos).matched();
285310
return *this;
286311
}
312+
friend CTRE_FORCE_INLINE constexpr bool operator==(const regex_results & lhs, std::basic_string_view<char_type> rhs) noexcept {
313+
return lhs.view() == rhs;
314+
}
315+
friend CTRE_FORCE_INLINE constexpr bool operator!=(const regex_results & lhs, std::basic_string_view<char_type> rhs) noexcept {
316+
return lhs.view() != rhs;
317+
}
318+
friend CTRE_FORCE_INLINE constexpr bool operator==(std::basic_string_view<char_type> lhs, const regex_results & rhs) noexcept {
319+
return lhs == rhs.view();
320+
}
321+
friend CTRE_FORCE_INLINE constexpr bool operator!=(std::basic_string_view<char_type> lhs, const regex_results & rhs) noexcept {
322+
return lhs != rhs.view();
323+
}
287324
};
288325

289326
template <typename Iterator, typename... Captures> regex_results(Iterator, ctll::list<Captures...>) -> regex_results<Iterator, Captures...>;
@@ -299,7 +336,7 @@ template <typename Iterator, typename... Captures> regex_results(Iterator, ctll:
299336
#endif
300337

301338
namespace std {
302-
template <typename... Captures> struct tuple_size<ctre::regex_results<Captures...>> : public std::integral_constant<size_t, ctre::regex_results<Captures...>::size()> { };
339+
template <typename... Captures> struct tuple_size<ctre::regex_results<Captures...>> : public std::integral_constant<size_t, ctre::regex_results<Captures...>::count()> { };
303340

304341
template <size_t N, typename... Captures> struct tuple_element<N, ctre::regex_results<Captures...>> {
305342
public:

0 commit comments

Comments
 (0)