string_view 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661
  1. // Components for manipulating non-owning sequences of characters -*- C++ -*-
  2. // Copyright (C) 2013-2018 Free Software Foundation, Inc.
  3. //
  4. // This file is part of the GNU ISO C++ Library. This library is free
  5. // software; you can redistribute it and/or modify it under the
  6. // terms of the GNU General Public License as published by the
  7. // Free Software Foundation; either version 3, or (at your option)
  8. // any later version.
  9. // This library is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. // Under Section 7 of GPL version 3, you are granted additional
  14. // permissions described in the GCC Runtime Library Exception, version
  15. // 3.1, as published by the Free Software Foundation.
  16. // You should have received a copy of the GNU General Public License and
  17. // a copy of the GCC Runtime Library Exception along with this program;
  18. // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  19. // <http://www.gnu.org/licenses/>.
  20. /** @file string_view
  21. * This is a Standard C++ Library header.
  22. */
  23. //
  24. // N3762 basic_string_view library
  25. //
  26. #ifndef _GLIBCXX_STRING_VIEW
  27. #define _GLIBCXX_STRING_VIEW 1
  28. #pragma GCC system_header
  29. #if __cplusplus >= 201703L
  30. #include <limits>
  31. #include <iosfwd>
  32. #include <bits/char_traits.h>
  33. #include <bits/functional_hash.h>
  34. #include <bits/range_access.h>
  35. namespace std _GLIBCXX_VISIBILITY(default)
  36. {
  37. _GLIBCXX_BEGIN_NAMESPACE_VERSION
  38. #define __cpp_lib_string_view 201603
  39. /**
  40. * @class basic_string_view <string_view>
  41. * @brief A non-owning reference to a string.
  42. *
  43. * @ingroup strings
  44. * @ingroup sequences
  45. *
  46. * @tparam _CharT Type of character
  47. * @tparam _Traits Traits for character type, defaults to
  48. * char_traits<_CharT>.
  49. *
  50. * A basic_string_view looks like this:
  51. *
  52. * @code
  53. * _CharT* _M_str
  54. * size_t _M_len
  55. * @endcode
  56. */
  57. template<typename _CharT, typename _Traits = std::char_traits<_CharT>>
  58. class basic_string_view
  59. {
  60. public:
  61. // types
  62. using traits_type = _Traits;
  63. using value_type = _CharT;
  64. using pointer = const _CharT*;
  65. using const_pointer = const _CharT*;
  66. using reference = const _CharT&;
  67. using const_reference = const _CharT&;
  68. using const_iterator = const _CharT*;
  69. using iterator = const_iterator;
  70. using const_reverse_iterator = std::reverse_iterator<const_iterator>;
  71. using reverse_iterator = const_reverse_iterator;
  72. using size_type = size_t;
  73. using difference_type = ptrdiff_t;
  74. static constexpr size_type npos = size_type(-1);
  75. // [string.view.cons], construct/copy
  76. constexpr
  77. basic_string_view() noexcept
  78. : _M_len{0}, _M_str{nullptr}
  79. { }
  80. constexpr basic_string_view(const basic_string_view&) noexcept = default;
  81. constexpr basic_string_view(const _CharT* __str) noexcept
  82. : _M_len{__str == nullptr ? 0 : traits_type::length(__str)},
  83. _M_str{__str}
  84. { }
  85. constexpr
  86. basic_string_view(const _CharT* __str, size_type __len) noexcept
  87. : _M_len{__len}, _M_str{__str}
  88. { }
  89. constexpr basic_string_view&
  90. operator=(const basic_string_view&) noexcept = default;
  91. // [string.view.iterators], iterators
  92. constexpr const_iterator
  93. begin() const noexcept
  94. { return this->_M_str; }
  95. constexpr const_iterator
  96. end() const noexcept
  97. { return this->_M_str + this->_M_len; }
  98. constexpr const_iterator
  99. cbegin() const noexcept
  100. { return this->_M_str; }
  101. constexpr const_iterator
  102. cend() const noexcept
  103. { return this->_M_str + this->_M_len; }
  104. constexpr const_reverse_iterator
  105. rbegin() const noexcept
  106. { return const_reverse_iterator(this->end()); }
  107. constexpr const_reverse_iterator
  108. rend() const noexcept
  109. { return const_reverse_iterator(this->begin()); }
  110. constexpr const_reverse_iterator
  111. crbegin() const noexcept
  112. { return const_reverse_iterator(this->end()); }
  113. constexpr const_reverse_iterator
  114. crend() const noexcept
  115. { return const_reverse_iterator(this->begin()); }
  116. // [string.view.capacity], capacity
  117. constexpr size_type
  118. size() const noexcept
  119. { return this->_M_len; }
  120. constexpr size_type
  121. length() const noexcept
  122. { return _M_len; }
  123. constexpr size_type
  124. max_size() const noexcept
  125. {
  126. return (npos - sizeof(size_type) - sizeof(void*))
  127. / sizeof(value_type) / 4;
  128. }
  129. [[nodiscard]] constexpr bool
  130. empty() const noexcept
  131. { return this->_M_len == 0; }
  132. // [string.view.access], element access
  133. constexpr const _CharT&
  134. operator[](size_type __pos) const noexcept
  135. {
  136. // TODO: Assert to restore in a way compatible with the constexpr.
  137. // __glibcxx_assert(__pos < this->_M_len);
  138. return *(this->_M_str + __pos);
  139. }
  140. constexpr const _CharT&
  141. at(size_type __pos) const
  142. {
  143. if (__pos >= _M_len)
  144. __throw_out_of_range_fmt(__N("basic_string_view::at: __pos "
  145. "(which is %zu) >= this->size() "
  146. "(which is %zu)"), __pos, this->size());
  147. return *(this->_M_str + __pos);
  148. }
  149. constexpr const _CharT&
  150. front() const noexcept
  151. {
  152. // TODO: Assert to restore in a way compatible with the constexpr.
  153. // __glibcxx_assert(this->_M_len > 0);
  154. return *this->_M_str;
  155. }
  156. constexpr const _CharT&
  157. back() const noexcept
  158. {
  159. // TODO: Assert to restore in a way compatible with the constexpr.
  160. // __glibcxx_assert(this->_M_len > 0);
  161. return *(this->_M_str + this->_M_len - 1);
  162. }
  163. constexpr const _CharT*
  164. data() const noexcept
  165. { return this->_M_str; }
  166. // [string.view.modifiers], modifiers:
  167. constexpr void
  168. remove_prefix(size_type __n) noexcept
  169. {
  170. __glibcxx_assert(this->_M_len >= __n);
  171. this->_M_str += __n;
  172. this->_M_len -= __n;
  173. }
  174. constexpr void
  175. remove_suffix(size_type __n) noexcept
  176. { this->_M_len -= __n; }
  177. constexpr void
  178. swap(basic_string_view& __sv) noexcept
  179. {
  180. auto __tmp = *this;
  181. *this = __sv;
  182. __sv = __tmp;
  183. }
  184. // [string.view.ops], string operations:
  185. size_type
  186. copy(_CharT* __str, size_type __n, size_type __pos = 0) const
  187. {
  188. __glibcxx_requires_string_len(__str, __n);
  189. __pos = _M_check(__pos, "basic_string_view::copy");
  190. const size_type __rlen = std::min(__n, _M_len - __pos);
  191. // _GLIBCXX_RESOLVE_LIB_DEFECTS
  192. // 2777. basic_string_view::copy should use char_traits::copy
  193. traits_type::copy(__str, data() + __pos, __rlen);
  194. return __rlen;
  195. }
  196. constexpr basic_string_view
  197. substr(size_type __pos = 0, size_type __n = npos) const noexcept(false)
  198. {
  199. __pos = _M_check(__pos, "basic_string_view::substr");
  200. const size_type __rlen = std::min(__n, _M_len - __pos);
  201. return basic_string_view{_M_str + __pos, __rlen};
  202. }
  203. constexpr int
  204. compare(basic_string_view __str) const noexcept
  205. {
  206. const size_type __rlen = std::min(this->_M_len, __str._M_len);
  207. int __ret = traits_type::compare(this->_M_str, __str._M_str, __rlen);
  208. if (__ret == 0)
  209. __ret = _S_compare(this->_M_len, __str._M_len);
  210. return __ret;
  211. }
  212. constexpr int
  213. compare(size_type __pos1, size_type __n1, basic_string_view __str) const
  214. { return this->substr(__pos1, __n1).compare(__str); }
  215. constexpr int
  216. compare(size_type __pos1, size_type __n1,
  217. basic_string_view __str, size_type __pos2, size_type __n2) const
  218. {
  219. return this->substr(__pos1, __n1).compare(__str.substr(__pos2, __n2));
  220. }
  221. constexpr int
  222. compare(const _CharT* __str) const noexcept
  223. { return this->compare(basic_string_view{__str}); }
  224. constexpr int
  225. compare(size_type __pos1, size_type __n1, const _CharT* __str) const
  226. { return this->substr(__pos1, __n1).compare(basic_string_view{__str}); }
  227. constexpr int
  228. compare(size_type __pos1, size_type __n1,
  229. const _CharT* __str, size_type __n2) const noexcept(false)
  230. {
  231. return this->substr(__pos1, __n1)
  232. .compare(basic_string_view(__str, __n2));
  233. }
  234. constexpr size_type
  235. find(basic_string_view __str, size_type __pos = 0) const noexcept
  236. { return this->find(__str._M_str, __pos, __str._M_len); }
  237. constexpr size_type
  238. find(_CharT __c, size_type __pos = 0) const noexcept;
  239. constexpr size_type
  240. find(const _CharT* __str, size_type __pos, size_type __n) const noexcept;
  241. constexpr size_type
  242. find(const _CharT* __str, size_type __pos = 0) const noexcept
  243. { return this->find(__str, __pos, traits_type::length(__str)); }
  244. constexpr size_type
  245. rfind(basic_string_view __str, size_type __pos = npos) const noexcept
  246. { return this->rfind(__str._M_str, __pos, __str._M_len); }
  247. constexpr size_type
  248. rfind(_CharT __c, size_type __pos = npos) const noexcept;
  249. constexpr size_type
  250. rfind(const _CharT* __str, size_type __pos, size_type __n) const noexcept;
  251. constexpr size_type
  252. rfind(const _CharT* __str, size_type __pos = npos) const noexcept
  253. { return this->rfind(__str, __pos, traits_type::length(__str)); }
  254. constexpr size_type
  255. find_first_of(basic_string_view __str, size_type __pos = 0) const noexcept
  256. { return this->find_first_of(__str._M_str, __pos, __str._M_len); }
  257. constexpr size_type
  258. find_first_of(_CharT __c, size_type __pos = 0) const noexcept
  259. { return this->find(__c, __pos); }
  260. constexpr size_type
  261. find_first_of(const _CharT* __str, size_type __pos, size_type __n) const noexcept;
  262. constexpr size_type
  263. find_first_of(const _CharT* __str, size_type __pos = 0) const noexcept
  264. { return this->find_first_of(__str, __pos, traits_type::length(__str)); }
  265. constexpr size_type
  266. find_last_of(basic_string_view __str,
  267. size_type __pos = npos) const noexcept
  268. { return this->find_last_of(__str._M_str, __pos, __str._M_len); }
  269. constexpr size_type
  270. find_last_of(_CharT __c, size_type __pos=npos) const noexcept
  271. { return this->rfind(__c, __pos); }
  272. constexpr size_type
  273. find_last_of(const _CharT* __str, size_type __pos,
  274. size_type __n) const noexcept;
  275. constexpr size_type
  276. find_last_of(const _CharT* __str, size_type __pos = npos) const noexcept
  277. { return this->find_last_of(__str, __pos, traits_type::length(__str)); }
  278. constexpr size_type
  279. find_first_not_of(basic_string_view __str,
  280. size_type __pos = 0) const noexcept
  281. { return this->find_first_not_of(__str._M_str, __pos, __str._M_len); }
  282. constexpr size_type
  283. find_first_not_of(_CharT __c, size_type __pos = 0) const noexcept;
  284. constexpr size_type
  285. find_first_not_of(const _CharT* __str,
  286. size_type __pos, size_type __n) const noexcept;
  287. constexpr size_type
  288. find_first_not_of(const _CharT* __str, size_type __pos = 0) const noexcept
  289. {
  290. return this->find_first_not_of(__str, __pos,
  291. traits_type::length(__str));
  292. }
  293. constexpr size_type
  294. find_last_not_of(basic_string_view __str,
  295. size_type __pos = npos) const noexcept
  296. { return this->find_last_not_of(__str._M_str, __pos, __str._M_len); }
  297. constexpr size_type
  298. find_last_not_of(_CharT __c, size_type __pos = npos) const noexcept;
  299. constexpr size_type
  300. find_last_not_of(const _CharT* __str,
  301. size_type __pos, size_type __n) const noexcept;
  302. constexpr size_type
  303. find_last_not_of(const _CharT* __str,
  304. size_type __pos = npos) const noexcept
  305. {
  306. return this->find_last_not_of(__str, __pos,
  307. traits_type::length(__str));
  308. }
  309. constexpr size_type
  310. _M_check(size_type __pos, const char* __s) const noexcept(false)
  311. {
  312. if (__pos > this->size())
  313. __throw_out_of_range_fmt(__N("%s: __pos (which is %zu) > "
  314. "this->size() (which is %zu)"),
  315. __s, __pos, this->size());
  316. return __pos;
  317. }
  318. // NB: _M_limit doesn't check for a bad __pos value.
  319. constexpr size_type
  320. _M_limit(size_type __pos, size_type __off) const noexcept
  321. {
  322. const bool __testoff = __off < this->size() - __pos;
  323. return __testoff ? __off : this->size() - __pos;
  324. }
  325. private:
  326. static constexpr int
  327. _S_compare(size_type __n1, size_type __n2) noexcept
  328. {
  329. const difference_type __diff = __n1 - __n2;
  330. if (__diff > std::numeric_limits<int>::max())
  331. return std::numeric_limits<int>::max();
  332. if (__diff < std::numeric_limits<int>::min())
  333. return std::numeric_limits<int>::min();
  334. return static_cast<int>(__diff);
  335. }
  336. size_t _M_len;
  337. const _CharT* _M_str;
  338. };
  339. // [string.view.comparison], non-member basic_string_view comparison function
  340. namespace __detail
  341. {
  342. // Identity transform to create a non-deduced context, so that only one
  343. // argument participates in template argument deduction and the other
  344. // argument gets implicitly converted to the deduced type. See n3766.html.
  345. template<typename _Tp>
  346. using __idt = common_type_t<_Tp>;
  347. }
  348. template<typename _CharT, typename _Traits>
  349. constexpr bool
  350. operator==(basic_string_view<_CharT, _Traits> __x,
  351. basic_string_view<_CharT, _Traits> __y) noexcept
  352. { return __x.size() == __y.size() && __x.compare(__y) == 0; }
  353. template<typename _CharT, typename _Traits>
  354. constexpr bool
  355. operator==(basic_string_view<_CharT, _Traits> __x,
  356. __detail::__idt<basic_string_view<_CharT, _Traits>> __y) noexcept
  357. { return __x.size() == __y.size() && __x.compare(__y) == 0; }
  358. template<typename _CharT, typename _Traits>
  359. constexpr bool
  360. operator==(__detail::__idt<basic_string_view<_CharT, _Traits>> __x,
  361. basic_string_view<_CharT, _Traits> __y) noexcept
  362. { return __x.size() == __y.size() && __x.compare(__y) == 0; }
  363. template<typename _CharT, typename _Traits>
  364. constexpr bool
  365. operator!=(basic_string_view<_CharT, _Traits> __x,
  366. basic_string_view<_CharT, _Traits> __y) noexcept
  367. { return !(__x == __y); }
  368. template<typename _CharT, typename _Traits>
  369. constexpr bool
  370. operator!=(basic_string_view<_CharT, _Traits> __x,
  371. __detail::__idt<basic_string_view<_CharT, _Traits>> __y) noexcept
  372. { return !(__x == __y); }
  373. template<typename _CharT, typename _Traits>
  374. constexpr bool
  375. operator!=(__detail::__idt<basic_string_view<_CharT, _Traits>> __x,
  376. basic_string_view<_CharT, _Traits> __y) noexcept
  377. { return !(__x == __y); }
  378. template<typename _CharT, typename _Traits>
  379. constexpr bool
  380. operator< (basic_string_view<_CharT, _Traits> __x,
  381. basic_string_view<_CharT, _Traits> __y) noexcept
  382. { return __x.compare(__y) < 0; }
  383. template<typename _CharT, typename _Traits>
  384. constexpr bool
  385. operator< (basic_string_view<_CharT, _Traits> __x,
  386. __detail::__idt<basic_string_view<_CharT, _Traits>> __y) noexcept
  387. { return __x.compare(__y) < 0; }
  388. template<typename _CharT, typename _Traits>
  389. constexpr bool
  390. operator< (__detail::__idt<basic_string_view<_CharT, _Traits>> __x,
  391. basic_string_view<_CharT, _Traits> __y) noexcept
  392. { return __x.compare(__y) < 0; }
  393. template<typename _CharT, typename _Traits>
  394. constexpr bool
  395. operator> (basic_string_view<_CharT, _Traits> __x,
  396. basic_string_view<_CharT, _Traits> __y) noexcept
  397. { return __x.compare(__y) > 0; }
  398. template<typename _CharT, typename _Traits>
  399. constexpr bool
  400. operator> (basic_string_view<_CharT, _Traits> __x,
  401. __detail::__idt<basic_string_view<_CharT, _Traits>> __y) noexcept
  402. { return __x.compare(__y) > 0; }
  403. template<typename _CharT, typename _Traits>
  404. constexpr bool
  405. operator> (__detail::__idt<basic_string_view<_CharT, _Traits>> __x,
  406. basic_string_view<_CharT, _Traits> __y) noexcept
  407. { return __x.compare(__y) > 0; }
  408. template<typename _CharT, typename _Traits>
  409. constexpr bool
  410. operator<=(basic_string_view<_CharT, _Traits> __x,
  411. basic_string_view<_CharT, _Traits> __y) noexcept
  412. { return __x.compare(__y) <= 0; }
  413. template<typename _CharT, typename _Traits>
  414. constexpr bool
  415. operator<=(basic_string_view<_CharT, _Traits> __x,
  416. __detail::__idt<basic_string_view<_CharT, _Traits>> __y) noexcept
  417. { return __x.compare(__y) <= 0; }
  418. template<typename _CharT, typename _Traits>
  419. constexpr bool
  420. operator<=(__detail::__idt<basic_string_view<_CharT, _Traits>> __x,
  421. basic_string_view<_CharT, _Traits> __y) noexcept
  422. { return __x.compare(__y) <= 0; }
  423. template<typename _CharT, typename _Traits>
  424. constexpr bool
  425. operator>=(basic_string_view<_CharT, _Traits> __x,
  426. basic_string_view<_CharT, _Traits> __y) noexcept
  427. { return __x.compare(__y) >= 0; }
  428. template<typename _CharT, typename _Traits>
  429. constexpr bool
  430. operator>=(basic_string_view<_CharT, _Traits> __x,
  431. __detail::__idt<basic_string_view<_CharT, _Traits>> __y) noexcept
  432. { return __x.compare(__y) >= 0; }
  433. template<typename _CharT, typename _Traits>
  434. constexpr bool
  435. operator>=(__detail::__idt<basic_string_view<_CharT, _Traits>> __x,
  436. basic_string_view<_CharT, _Traits> __y) noexcept
  437. { return __x.compare(__y) >= 0; }
  438. // [string.view.io], Inserters and extractors
  439. template<typename _CharT, typename _Traits>
  440. inline basic_ostream<_CharT, _Traits>&
  441. operator<<(basic_ostream<_CharT, _Traits>& __os,
  442. basic_string_view<_CharT,_Traits> __str)
  443. { return __ostream_insert(__os, __str.data(), __str.size()); }
  444. // basic_string_view typedef names
  445. using string_view = basic_string_view<char>;
  446. #ifdef _GLIBCXX_USE_WCHAR_T
  447. using wstring_view = basic_string_view<wchar_t>;
  448. #endif
  449. #ifdef _GLIBCXX_USE_C99_STDINT_TR1
  450. using u16string_view = basic_string_view<char16_t>;
  451. using u32string_view = basic_string_view<char32_t>;
  452. #endif
  453. // [string.view.hash], hash support:
  454. template<typename _Tp>
  455. struct hash;
  456. template<>
  457. struct hash<string_view>
  458. : public __hash_base<size_t, string_view>
  459. {
  460. size_t
  461. operator()(const string_view& __str) const noexcept
  462. { return std::_Hash_impl::hash(__str.data(), __str.length()); }
  463. };
  464. template<>
  465. struct __is_fast_hash<hash<string_view>> : std::false_type
  466. { };
  467. #ifdef _GLIBCXX_USE_WCHAR_T
  468. template<>
  469. struct hash<wstring_view>
  470. : public __hash_base<size_t, wstring>
  471. {
  472. size_t
  473. operator()(const wstring_view& __s) const noexcept
  474. { return std::_Hash_impl::hash(__s.data(),
  475. __s.length() * sizeof(wchar_t)); }
  476. };
  477. template<>
  478. struct __is_fast_hash<hash<wstring_view>> : std::false_type
  479. { };
  480. #endif
  481. #ifdef _GLIBCXX_USE_C99_STDINT_TR1
  482. template<>
  483. struct hash<u16string_view>
  484. : public __hash_base<size_t, u16string_view>
  485. {
  486. size_t
  487. operator()(const u16string_view& __s) const noexcept
  488. { return std::_Hash_impl::hash(__s.data(),
  489. __s.length() * sizeof(char16_t)); }
  490. };
  491. template<>
  492. struct __is_fast_hash<hash<u16string_view>> : std::false_type
  493. { };
  494. template<>
  495. struct hash<u32string_view>
  496. : public __hash_base<size_t, u32string_view>
  497. {
  498. size_t
  499. operator()(const u32string_view& __s) const noexcept
  500. { return std::_Hash_impl::hash(__s.data(),
  501. __s.length() * sizeof(char32_t)); }
  502. };
  503. template<>
  504. struct __is_fast_hash<hash<u32string_view>> : std::false_type
  505. { };
  506. #endif
  507. inline namespace literals
  508. {
  509. inline namespace string_view_literals
  510. {
  511. #pragma GCC diagnostic push
  512. #pragma GCC diagnostic ignored "-Wliteral-suffix"
  513. inline constexpr basic_string_view<char>
  514. operator""sv(const char* __str, size_t __len) noexcept
  515. { return basic_string_view<char>{__str, __len}; }
  516. #ifdef _GLIBCXX_USE_WCHAR_T
  517. inline constexpr basic_string_view<wchar_t>
  518. operator""sv(const wchar_t* __str, size_t __len) noexcept
  519. { return basic_string_view<wchar_t>{__str, __len}; }
  520. #endif
  521. #ifdef _GLIBCXX_USE_C99_STDINT_TR1
  522. inline constexpr basic_string_view<char16_t>
  523. operator""sv(const char16_t* __str, size_t __len) noexcept
  524. { return basic_string_view<char16_t>{__str, __len}; }
  525. inline constexpr basic_string_view<char32_t>
  526. operator""sv(const char32_t* __str, size_t __len) noexcept
  527. { return basic_string_view<char32_t>{__str, __len}; }
  528. #endif
  529. #pragma GCC diagnostic pop
  530. } // namespace string_literals
  531. } // namespace literals
  532. _GLIBCXX_END_NAMESPACE_VERSION
  533. } // namespace std
  534. #include <bits/string_view.tcc>
  535. #endif // __cplusplus <= 201402L
  536. #endif // _GLIBCXX_EXPERIMENTAL_STRING_VIEW