Skip to content

Commit fea2b16

Browse files
author
Hana Dusíková
committed
support for wide string_views in msvc
1 parent 5357076 commit fea2b16

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

include/ctre/return_type.hpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ template <size_t Id, typename Name = void> struct captured_content {
1616
template <typename Iterator> struct storage {
1717
Iterator _begin{};
1818
Iterator _end{};
19+
20+
using char_type = typename std::iterator_traits<Iterator>::value_type;
21+
1922
bool _matched{false};
2023

2124
using name = Name;
@@ -52,10 +55,11 @@ template <size_t Id, typename Name = void> struct captured_content {
5255
}
5356

5457
constexpr CTRE_FORCE_INLINE auto to_view() const noexcept {
55-
return std::string_view{_begin, static_cast<size_t>(std::distance(_begin, _end))};
58+
return std::basic_string_view<char_type>(&*_begin, static_cast<size_t>(std::distance(_begin, _end)));
5659
}
5760

58-
constexpr operator std::string_view() const noexcept {
61+
template <typename U = char_type>
62+
constexpr operator std::basic_string_view<U>() const noexcept {
5963
return to_view();
6064
}
6165

@@ -135,6 +139,8 @@ template <> struct captures<> {
135139
};
136140

137141
template <typename Iterator, typename... Captures> struct regex_results {
142+
using char_type = typename std::iterator_traits<Iterator>::value_type;
143+
138144
captures<captured_content<0>::template storage<Iterator>, typename Captures::template storage<Iterator>...> _captures;
139145

140146
constexpr CTRE_FORCE_INLINE regex_results() noexcept { }
@@ -163,8 +169,9 @@ template <typename Iterator, typename... Captures> struct regex_results {
163169
constexpr CTRE_FORCE_INLINE operator bool() const noexcept {
164170
return bool(_captures.template select<0>());
165171
}
166-
167-
constexpr operator std::string_view() const noexcept {
172+
173+
template <typename U = char_type>
174+
constexpr operator std::basic_string_view<U>() const noexcept {
168175
return to_view();
169176
}
170177

0 commit comments

Comments
 (0)