diff options
Diffstat (limited to 'libcxx/include/string_view')
-rw-r--r-- | libcxx/include/string_view | 86 |
1 files changed, 55 insertions, 31 deletions
diff --git a/libcxx/include/string_view b/libcxx/include/string_view index bc0245cf2b5e..2c94cb85269f 100644 --- a/libcxx/include/string_view +++ b/libcxx/include/string_view @@ -19,6 +19,12 @@ namespace std { template<class charT, class traits = char_traits<charT>> class basic_string_view; + template<class charT, class traits> + inline constexpr bool ranges::enable_view<basic_string_view<charT, traits>> = true; + + template<class charT, class traits> + inline constexpr bool ranges::enable_borrowed_range<basic_string_view<charT, traits>> = true; // C++20 + // 7.9, basic_string_view non-member comparison functions template<class charT, class traits> constexpr bool operator==(basic_string_view<charT, traits> x, @@ -48,6 +54,7 @@ namespace std { // basic_string_view typedef names typedef basic_string_view<char> string_view; + typedef basic_string_view<char8_t> u8string_view; // C++20 typedef basic_string_view<char16_t> u16string_view; typedef basic_string_view<char32_t> u32string_view; typedef basic_string_view<wchar_t> wstring_view; @@ -76,6 +83,7 @@ namespace std { basic_string_view& operator=(const basic_string_view&) noexcept = default; template<class Allocator> constexpr basic_string_view(const charT* str); + basic_string_view(nullptr_t) = delete; // C++2b constexpr basic_string_view(const charT* str, size_type len); // 7.4, basic_string_view iterator support @@ -106,7 +114,7 @@ namespace std { constexpr void remove_suffix(size_type n); constexpr void swap(basic_string_view& s) noexcept; - size_type copy(charT* s, size_type n, size_type pos = 0) const; + size_type copy(charT* s, size_type n, size_type pos = 0) const; // constexpr in C++20 constexpr basic_string_view substr(size_type pos = 0, size_type n = npos) const; constexpr int compare(basic_string_view s) const noexcept; @@ -119,28 +127,28 @@ namespace std { const charT* s, size_type n2) const; constexpr size_type find(basic_string_view s, size_type pos = 0) const noexcept; constexpr size_type find(charT c, size_type pos = 0) const noexcept; - constexpr size_type find(const charT* s, size_type pos, size_type n) const; - constexpr size_type find(const charT* s, size_type pos = 0) const; + constexpr size_type find(const charT* s, size_type pos, size_type n) const noexcept; // noexcept as an extension + constexpr size_type find(const charT* s, size_type pos = 0) const noexcept; // noexcept as an extension constexpr size_type rfind(basic_string_view s, size_type pos = npos) const noexcept; constexpr size_type rfind(charT c, size_type pos = npos) const noexcept; - constexpr size_type rfind(const charT* s, size_type pos, size_type n) const; - constexpr size_type rfind(const charT* s, size_type pos = npos) const; + constexpr size_type rfind(const charT* s, size_type pos, size_type n) const noexcept; // noexcept as an extension + constexpr size_type rfind(const charT* s, size_type pos = npos) const noexcept; // noexcept as an extension constexpr size_type find_first_of(basic_string_view s, size_type pos = 0) const noexcept; constexpr size_type find_first_of(charT c, size_type pos = 0) const noexcept; - constexpr size_type find_first_of(const charT* s, size_type pos, size_type n) const; - constexpr size_type find_first_of(const charT* s, size_type pos = 0) const; + constexpr size_type find_first_of(const charT* s, size_type pos, size_type n) const noexcept; // noexcept as an extension + constexpr size_type find_first_of(const charT* s, size_type pos = 0) const noexcept; // noexcept as an extension constexpr size_type find_last_of(basic_string_view s, size_type pos = npos) const noexcept; constexpr size_type find_last_of(charT c, size_type pos = npos) const noexcept; - constexpr size_type find_last_of(const charT* s, size_type pos, size_type n) const; - constexpr size_type find_last_of(const charT* s, size_type pos = npos) const; + constexpr size_type find_last_of(const charT* s, size_type pos, size_type n) const noexcept; // noexcept as an extension + constexpr size_type find_last_of(const charT* s, size_type pos = npos) const noexcept; // noexcept as an extension constexpr size_type find_first_not_of(basic_string_view s, size_type pos = 0) const noexcept; constexpr size_type find_first_not_of(charT c, size_type pos = 0) const noexcept; - constexpr size_type find_first_not_of(const charT* s, size_type pos, size_type n) const; - constexpr size_type find_first_not_of(const charT* s, size_type pos = 0) const; + constexpr size_type find_first_not_of(const charT* s, size_type pos, size_type n) const noexcept; // noexcept as an extension + constexpr size_type find_first_not_of(const charT* s, size_type pos = 0) const noexcept; // noexcept as an extension constexpr size_type find_last_not_of(basic_string_view s, size_type pos = npos) const noexcept; constexpr size_type find_last_not_of(charT c, size_type pos = npos) const noexcept; - constexpr size_type find_last_not_of(const charT* s, size_type pos, size_type n) const; - constexpr size_type find_last_not_of(const charT* s, size_type pos = npos) const; + constexpr size_type find_last_not_of(const charT* s, size_type pos, size_type n) const noexcept; // noexcept as an extension + constexpr size_type find_last_not_of(const charT* s, size_type pos = npos) const noexcept; // noexcept as an extension constexpr bool starts_with(basic_string_view s) const noexcept; // C++20 constexpr bool starts_with(charT c) const noexcept; // C++20 @@ -161,12 +169,14 @@ namespace std { // 7.11, Hash support template <class T> struct hash; template <> struct hash<string_view>; + template <> struct hash<u8string_view>; // C++20 template <> struct hash<u16string_view>; template <> struct hash<u32string_view>; template <> struct hash<wstring_view>; constexpr basic_string_view<char> operator "" sv( const char *str, size_t len ) noexcept; constexpr basic_string_view<wchar_t> operator "" sv( const wchar_t *str, size_t len ) noexcept; + constexpr basic_string_view<char8_t> operator "" sv( const char8_t *str, size_t len ) noexcept; // C++20 constexpr basic_string_view<char16_t> operator "" sv( const char16_t *str, size_t len ) noexcept; constexpr basic_string_view<char32_t> operator "" sv( const char32_t *str, size_t len ) noexcept; @@ -176,14 +186,17 @@ namespace std { */ #include <__config> +#include <__debug> +#include <__ranges/enable_borrowed_range.h> +#include <__ranges/enable_view.h> #include <__string> -#include <iosfwd> #include <algorithm> +#include <compare> +#include <iosfwd> #include <iterator> #include <limits> #include <stdexcept> #include <version> -#include <__debug> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) #pragma GCC system_header @@ -199,7 +212,7 @@ template<class _CharT, class _Traits = char_traits<_CharT> > class _LIBCPP_TEMPLATE_VIS basic_string_view; typedef basic_string_view<char> string_view; -#ifndef _LIBCPP_NO_HAS_CHAR8_T +#ifndef _LIBCPP_HAS_NO_CHAR8_T typedef basic_string_view<char8_t> u8string_view; #endif typedef basic_string_view<char16_t> u16string_view; @@ -209,7 +222,7 @@ typedef basic_string_view<wchar_t> wstring_view; template<class _CharT, class _Traits> class _LIBCPP_PREFERRED_NAME(string_view) -#ifndef _LIBCPP_NO_HAS_CHAR8_T +#ifndef _LIBCPP_HAS_NO_CHAR8_T _LIBCPP_PREFERRED_NAME(u8string_view) #endif _LIBCPP_PREFERRED_NAME(u16string_view) @@ -261,6 +274,10 @@ public: basic_string_view(const _CharT* __s) : __data(__s), __size(_VSTD::__char_traits_length_checked<_Traits>(__s)) {} +#if _LIBCPP_STD_VER > 20 + basic_string_view(nullptr_t) = delete; +#endif + // [string.view.iterators], iterators _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY const_iterator begin() const _NOEXCEPT { return cbegin(); } @@ -356,7 +373,7 @@ public: __other.__size = __sz; } - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 size_type copy(_CharT* __s, size_type __n, size_type __pos = 0) const { if (__pos > size()) @@ -431,7 +448,7 @@ public: } _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY - size_type find(const _CharT* __s, size_type __pos, size_type __n) const + size_type find(const _CharT* __s, size_type __pos, size_type __n) const _NOEXCEPT { _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::find(): received nullptr"); return __str_find<value_type, size_type, traits_type, npos> @@ -439,7 +456,7 @@ public: } _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY - size_type find(const _CharT* __s, size_type __pos = 0) const + size_type find(const _CharT* __s, size_type __pos = 0) const _NOEXCEPT { _LIBCPP_ASSERT(__s != nullptr, "string_view::find(): received nullptr"); return __str_find<value_type, size_type, traits_type, npos> @@ -463,7 +480,7 @@ public: } _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY - size_type rfind(const _CharT* __s, size_type __pos, size_type __n) const + size_type rfind(const _CharT* __s, size_type __pos, size_type __n) const _NOEXCEPT { _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::rfind(): received nullptr"); return __str_rfind<value_type, size_type, traits_type, npos> @@ -471,7 +488,7 @@ public: } _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY - size_type rfind(const _CharT* __s, size_type __pos=npos) const + size_type rfind(const _CharT* __s, size_type __pos=npos) const _NOEXCEPT { _LIBCPP_ASSERT(__s != nullptr, "string_view::rfind(): received nullptr"); return __str_rfind<value_type, size_type, traits_type, npos> @@ -492,7 +509,7 @@ public: { return find(__c, __pos); } _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY - size_type find_first_of(const _CharT* __s, size_type __pos, size_type __n) const + size_type find_first_of(const _CharT* __s, size_type __pos, size_type __n) const _NOEXCEPT { _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::find_first_of(): received nullptr"); return __str_find_first_of<value_type, size_type, traits_type, npos> @@ -500,7 +517,7 @@ public: } _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY - size_type find_first_of(const _CharT* __s, size_type __pos=0) const + size_type find_first_of(const _CharT* __s, size_type __pos=0) const _NOEXCEPT { _LIBCPP_ASSERT(__s != nullptr, "string_view::find_first_of(): received nullptr"); return __str_find_first_of<value_type, size_type, traits_type, npos> @@ -521,7 +538,7 @@ public: { return rfind(__c, __pos); } _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY - size_type find_last_of(const _CharT* __s, size_type __pos, size_type __n) const + size_type find_last_of(const _CharT* __s, size_type __pos, size_type __n) const _NOEXCEPT { _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::find_last_of(): received nullptr"); return __str_find_last_of<value_type, size_type, traits_type, npos> @@ -529,7 +546,7 @@ public: } _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY - size_type find_last_of(const _CharT* __s, size_type __pos=npos) const + size_type find_last_of(const _CharT* __s, size_type __pos=npos) const _NOEXCEPT { _LIBCPP_ASSERT(__s != nullptr, "string_view::find_last_of(): received nullptr"); return __str_find_last_of<value_type, size_type, traits_type, npos> @@ -553,7 +570,7 @@ public: } _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY - size_type find_first_not_of(const _CharT* __s, size_type __pos, size_type __n) const + size_type find_first_not_of(const _CharT* __s, size_type __pos, size_type __n) const _NOEXCEPT { _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::find_first_not_of(): received nullptr"); return __str_find_first_not_of<value_type, size_type, traits_type, npos> @@ -561,7 +578,7 @@ public: } _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY - size_type find_first_not_of(const _CharT* __s, size_type __pos=0) const + size_type find_first_not_of(const _CharT* __s, size_type __pos=0) const _NOEXCEPT { _LIBCPP_ASSERT(__s != nullptr, "string_view::find_first_not_of(): received nullptr"); return __str_find_first_not_of<value_type, size_type, traits_type, npos> @@ -585,7 +602,7 @@ public: } _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY - size_type find_last_not_of(const _CharT* __s, size_type __pos, size_type __n) const + size_type find_last_not_of(const _CharT* __s, size_type __pos, size_type __n) const _NOEXCEPT { _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::find_last_not_of(): received nullptr"); return __str_find_last_not_of<value_type, size_type, traits_type, npos> @@ -593,7 +610,7 @@ public: } _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY - size_type find_last_not_of(const _CharT* __s, size_type __pos=npos) const + size_type find_last_not_of(const _CharT* __s, size_type __pos=npos) const _NOEXCEPT { _LIBCPP_ASSERT(__s != nullptr, "string_view::find_last_not_of(): received nullptr"); return __str_find_last_not_of<value_type, size_type, traits_type, npos> @@ -645,6 +662,13 @@ private: size_type __size; }; +#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_RANGES) +template <class _CharT, class _Traits> +inline constexpr bool ranges::enable_view<basic_string_view<_CharT, _Traits>> = true; + +template <class _CharT, class _Traits> +inline constexpr bool ranges::enable_borrowed_range<basic_string_view<_CharT, _Traits> > = true; +#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_RANGES) // [string.view.comparison] // operator == @@ -842,7 +866,7 @@ inline namespace literals return basic_string_view<wchar_t> (__str, __len); } -#ifndef _LIBCPP_NO_HAS_CHAR8_T +#ifndef _LIBCPP_HAS_NO_CHAR8_T inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR basic_string_view<char8_t> operator "" sv(const char8_t *__str, size_t __len) _NOEXCEPT { |