aboutsummaryrefslogtreecommitdiff
path: root/libcxx/include/string_view
diff options
context:
space:
mode:
Diffstat (limited to 'libcxx/include/string_view')
-rw-r--r--libcxx/include/string_view63
1 files changed, 48 insertions, 15 deletions
diff --git a/libcxx/include/string_view b/libcxx/include/string_view
index 0ad7dcce9848..a5f85e88b502 100644
--- a/libcxx/include/string_view
+++ b/libcxx/include/string_view
@@ -87,6 +87,8 @@ namespace std {
constexpr basic_string_view(const charT* str, size_type len);
template <class It, class End>
constexpr basic_string_view(It begin, End end); // C++20
+ template <class Range>
+ constexpr basic_string_view(Range&& r); // C++23
// 7.4, basic_string_view iterator support
constexpr const_iterator begin() const noexcept;
@@ -171,6 +173,8 @@ namespace std {
// basic_string_view deduction guides
template<class It, class End>
basic_string_view(It, End) -> basic_string_view<iter_value_t<It>>; // C++20
+ template<class Range>
+ basic_string_view(Range&&) -> basic_string_view<ranges::range_value_t<Range>>; // C++23
// 7.11, Hash support
template <class T> struct hash;
@@ -191,12 +195,13 @@ namespace std {
*/
-#include <__concepts/convertible_to.h>
-#include <__concepts/same_as.h>
#include <__config>
#include <__debug>
+#include <__ranges/concepts.h>
+#include <__ranges/data.h>
#include <__ranges/enable_borrowed_range.h>
#include <__ranges/enable_view.h>
+#include <__ranges/size.h>
#include <__string>
#include <algorithm>
#include <compare>
@@ -204,6 +209,7 @@ namespace std {
#include <iterator>
#include <limits>
#include <stdexcept>
+#include <type_traits>
#include <version>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
@@ -282,7 +288,7 @@ public:
#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_RANGES)
template <contiguous_iterator _It, sized_sentinel_for<_It> _End>
- requires (same_as<iter_value_t<_It>, _CharT> && !convertible_to<_End, size_type>)
+ requires (is_same_v<iter_value_t<_It>, _CharT> && !is_convertible_v<_End, size_type>)
constexpr _LIBCPP_HIDE_FROM_ABI basic_string_view(_It __begin, _End __end)
: __data(_VSTD::to_address(__begin)), __size(__end - __begin)
{
@@ -290,6 +296,25 @@ public:
}
#endif
+#if _LIBCPP_STD_VER > 20 && !defined(_LIBCPP_HAS_NO_RANGES)
+ template <class _Range>
+ requires (
+ !is_same_v<remove_cvref_t<_Range>, basic_string_view> &&
+ ranges::contiguous_range<_Range> &&
+ ranges::sized_range<_Range> &&
+ is_same_v<ranges::range_value_t<_Range>, _CharT> &&
+ !is_convertible_v<_Range, const _CharT*> &&
+ (!requires(remove_cvref_t<_Range>& d) {
+ d.operator _VSTD::basic_string_view<_CharT, _Traits>();
+ }) &&
+ (!requires {
+ typename remove_reference_t<_Range>::traits_type;
+ } || is_same_v<typename remove_reference_t<_Range>::traits_type, _Traits>)
+ )
+ constexpr _LIBCPP_HIDE_FROM_ABI
+ basic_string_view(_Range&& __r) : __data(ranges::data(__r)), __size(ranges::size(__r)) {}
+#endif
+
_LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
basic_string_view(const _CharT* __s)
: __data(__s), __size(_VSTD::__char_traits_length_checked<_Traits>(__s)) {}
@@ -697,6 +722,12 @@ template <contiguous_iterator _It, sized_sentinel_for<_It> _End>
basic_string_view(_It, _End) -> basic_string_view<iter_value_t<_It>>;
#endif
+
+#if _LIBCPP_STD_VER > 20 && !defined(_LIBCPP_HAS_NO_RANGES)
+template <ranges::contiguous_range _Range>
+ basic_string_view(_Range) -> basic_string_view<ranges::range_value_t<_Range>>;
+#endif
+
// [string.view.comparison]
// operator ==
template<class _CharT, class _Traits>
@@ -708,7 +739,9 @@ bool operator==(basic_string_view<_CharT, _Traits> __lhs,
return __lhs.compare(__rhs) == 0;
}
-template<class _CharT, class _Traits>
+// The dummy default template parameters are used to work around a MSVC issue with mangling, see VSO-409326 for details.
+// This applies to the other sufficient overloads below for the other comparison operators.
+template<class _CharT, class _Traits, int = 1>
_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
bool operator==(basic_string_view<_CharT, _Traits> __lhs,
typename common_type<basic_string_view<_CharT, _Traits> >::type __rhs) _NOEXCEPT
@@ -717,7 +750,7 @@ bool operator==(basic_string_view<_CharT, _Traits> __lhs,
return __lhs.compare(__rhs) == 0;
}
-template<class _CharT, class _Traits>
+template<class _CharT, class _Traits, int = 2>
_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
bool operator==(typename common_type<basic_string_view<_CharT, _Traits> >::type __lhs,
basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
@@ -737,7 +770,7 @@ bool operator!=(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_Cha
return __lhs.compare(__rhs) != 0;
}
-template<class _CharT, class _Traits>
+template<class _CharT, class _Traits, int = 1>
_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
bool operator!=(basic_string_view<_CharT, _Traits> __lhs,
typename common_type<basic_string_view<_CharT, _Traits> >::type __rhs) _NOEXCEPT
@@ -747,7 +780,7 @@ bool operator!=(basic_string_view<_CharT, _Traits> __lhs,
return __lhs.compare(__rhs) != 0;
}
-template<class _CharT, class _Traits>
+template<class _CharT, class _Traits, int = 2>
_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
bool operator!=(typename common_type<basic_string_view<_CharT, _Traits> >::type __lhs,
basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
@@ -766,7 +799,7 @@ bool operator<(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_Char
return __lhs.compare(__rhs) < 0;
}
-template<class _CharT, class _Traits>
+template<class _CharT, class _Traits, int = 1>
_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
bool operator<(basic_string_view<_CharT, _Traits> __lhs,
typename common_type<basic_string_view<_CharT, _Traits> >::type __rhs) _NOEXCEPT
@@ -774,7 +807,7 @@ bool operator<(basic_string_view<_CharT, _Traits> __lhs,
return __lhs.compare(__rhs) < 0;
}
-template<class _CharT, class _Traits>
+template<class _CharT, class _Traits, int = 2>
_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
bool operator<(typename common_type<basic_string_view<_CharT, _Traits> >::type __lhs,
basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
@@ -791,7 +824,7 @@ bool operator> (basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_Cha
return __lhs.compare(__rhs) > 0;
}
-template<class _CharT, class _Traits>
+template<class _CharT, class _Traits, int = 1>
_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
bool operator>(basic_string_view<_CharT, _Traits> __lhs,
typename common_type<basic_string_view<_CharT, _Traits> >::type __rhs) _NOEXCEPT
@@ -799,7 +832,7 @@ bool operator>(basic_string_view<_CharT, _Traits> __lhs,
return __lhs.compare(__rhs) > 0;
}
-template<class _CharT, class _Traits>
+template<class _CharT, class _Traits, int = 2>
_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
bool operator>(typename common_type<basic_string_view<_CharT, _Traits> >::type __lhs,
basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
@@ -816,7 +849,7 @@ bool operator<=(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_Cha
return __lhs.compare(__rhs) <= 0;
}
-template<class _CharT, class _Traits>
+template<class _CharT, class _Traits, int = 1>
_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
bool operator<=(basic_string_view<_CharT, _Traits> __lhs,
typename common_type<basic_string_view<_CharT, _Traits> >::type __rhs) _NOEXCEPT
@@ -824,7 +857,7 @@ bool operator<=(basic_string_view<_CharT, _Traits> __lhs,
return __lhs.compare(__rhs) <= 0;
}
-template<class _CharT, class _Traits>
+template<class _CharT, class _Traits, int = 2>
_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
bool operator<=(typename common_type<basic_string_view<_CharT, _Traits> >::type __lhs,
basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
@@ -842,7 +875,7 @@ bool operator>=(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_Cha
}
-template<class _CharT, class _Traits>
+template<class _CharT, class _Traits, int = 1>
_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
bool operator>=(basic_string_view<_CharT, _Traits> __lhs,
typename common_type<basic_string_view<_CharT, _Traits> >::type __rhs) _NOEXCEPT
@@ -850,7 +883,7 @@ bool operator>=(basic_string_view<_CharT, _Traits> __lhs,
return __lhs.compare(__rhs) >= 0;
}
-template<class _CharT, class _Traits>
+template<class _CharT, class _Traits, int = 2>
_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
bool operator>=(typename common_type<basic_string_view<_CharT, _Traits> >::type __lhs,
basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT