Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

3 роки тому
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714
  1. // Components for manipulating non-owning sequences of characters -*- C++ -*-
  2. // Copyright (C) 2013-2020 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 experimental/string_view
  21. * This is a TS C++ Library header.
  22. * @ingroup libfund-ts
  23. */
  24. //
  25. // N3762 basic_string_view library
  26. //
  27. #ifndef _GLIBCXX_EXPERIMENTAL_STRING_VIEW
  28. #define _GLIBCXX_EXPERIMENTAL_STRING_VIEW 1
  29. #pragma GCC system_header
  30. #if __cplusplus >= 201402L
  31. #include <string>
  32. #include <limits>
  33. #include <experimental/bits/lfts_config.h>
  34. namespace std _GLIBCXX_VISIBILITY(default)
  35. {
  36. _GLIBCXX_BEGIN_NAMESPACE_VERSION
  37. namespace experimental
  38. {
  39. inline namespace fundamentals_v1
  40. {
  41. #define __cpp_lib_experimental_string_view 201411
  42. /**
  43. * @class basic_string_view <experimental/string_view>
  44. * @brief A non-owning reference to a string.
  45. *
  46. * @ingroup strings
  47. * @ingroup sequences
  48. * @ingroup libfund-ts
  49. *
  50. * @tparam _CharT Type of character
  51. * @tparam _Traits Traits for character type, defaults to
  52. * char_traits<_CharT>.
  53. *
  54. * A basic_string_view looks like this:
  55. *
  56. * @code
  57. * _CharT* _M_str
  58. * size_t _M_len
  59. * @endcode
  60. */
  61. template<typename _CharT, typename _Traits = std::char_traits<_CharT>>
  62. class basic_string_view
  63. {
  64. public:
  65. // types
  66. using traits_type = _Traits;
  67. using value_type = _CharT;
  68. using pointer = _CharT*;
  69. using const_pointer = const _CharT*;
  70. using reference = _CharT&;
  71. using const_reference = const _CharT&;
  72. using const_iterator = const _CharT*;
  73. using iterator = const_iterator;
  74. using const_reverse_iterator = std::reverse_iterator<const_iterator>;
  75. using reverse_iterator = const_reverse_iterator;
  76. using size_type = size_t;
  77. using difference_type = ptrdiff_t;
  78. static constexpr size_type npos = size_type(-1);
  79. // [string.view.cons], construct/copy
  80. constexpr
  81. basic_string_view() noexcept
  82. : _M_len{0}, _M_str{nullptr}
  83. { }
  84. constexpr basic_string_view(const basic_string_view&) noexcept = default;
  85. template<typename _Allocator>
  86. basic_string_view(const basic_string<_CharT, _Traits,
  87. _Allocator>& __str) noexcept
  88. : _M_len{__str.length()}, _M_str{__str.data()}
  89. { }
  90. constexpr basic_string_view(const _CharT* __str)
  91. : _M_len{__str == nullptr ? 0 : traits_type::length(__str)},
  92. _M_str{__str}
  93. { }
  94. constexpr basic_string_view(const _CharT* __str, size_type __len)
  95. : _M_len{__len},
  96. _M_str{__str}
  97. { }
  98. basic_string_view&
  99. operator=(const basic_string_view&) noexcept = default;
  100. // [string.view.iterators], iterators
  101. constexpr const_iterator
  102. begin() const noexcept
  103. { return this->_M_str; }
  104. constexpr const_iterator
  105. end() const noexcept
  106. { return this->_M_str + this->_M_len; }
  107. constexpr const_iterator
  108. cbegin() const noexcept
  109. { return this->_M_str; }
  110. constexpr const_iterator
  111. cend() const noexcept
  112. { return this->_M_str + this->_M_len; }
  113. const_reverse_iterator
  114. rbegin() const noexcept
  115. { return const_reverse_iterator(this->end()); }
  116. const_reverse_iterator
  117. rend() const noexcept
  118. { return const_reverse_iterator(this->begin()); }
  119. const_reverse_iterator
  120. crbegin() const noexcept
  121. { return const_reverse_iterator(this->end()); }
  122. const_reverse_iterator
  123. crend() const noexcept
  124. { return const_reverse_iterator(this->begin()); }
  125. // [string.view.capacity], capacity
  126. constexpr size_type
  127. size() const noexcept
  128. { return this->_M_len; }
  129. constexpr size_type
  130. length() const noexcept
  131. { return _M_len; }
  132. constexpr size_type
  133. max_size() const noexcept
  134. {
  135. return (npos - sizeof(size_type) - sizeof(void*))
  136. / sizeof(value_type) / 4;
  137. }
  138. _GLIBCXX_NODISCARD constexpr bool
  139. empty() const noexcept
  140. { return this->_M_len == 0; }
  141. // [string.view.access], element access
  142. constexpr const _CharT&
  143. operator[](size_type __pos) const
  144. {
  145. __glibcxx_assert(__pos < this->_M_len);
  146. return *(this->_M_str + __pos);
  147. }
  148. constexpr const _CharT&
  149. at(size_type __pos) const
  150. {
  151. return __pos < this->_M_len
  152. ? *(this->_M_str + __pos)
  153. : (__throw_out_of_range_fmt(__N("basic_string_view::at: __pos "
  154. "(which is %zu) >= this->size() "
  155. "(which is %zu)"),
  156. __pos, this->size()),
  157. *this->_M_str);
  158. }
  159. constexpr const _CharT&
  160. front() const
  161. {
  162. __glibcxx_assert(this->_M_len > 0);
  163. return *this->_M_str;
  164. }
  165. constexpr const _CharT&
  166. back() const
  167. {
  168. __glibcxx_assert(this->_M_len > 0);
  169. return *(this->_M_str + this->_M_len - 1);
  170. }
  171. constexpr const _CharT*
  172. data() const noexcept
  173. { return this->_M_str; }
  174. // [string.view.modifiers], modifiers:
  175. constexpr void
  176. remove_prefix(size_type __n)
  177. {
  178. __glibcxx_assert(this->_M_len >= __n);
  179. this->_M_str += __n;
  180. this->_M_len -= __n;
  181. }
  182. constexpr void
  183. remove_suffix(size_type __n)
  184. { this->_M_len -= __n; }
  185. constexpr void
  186. swap(basic_string_view& __sv) noexcept
  187. {
  188. auto __tmp = *this;
  189. *this = __sv;
  190. __sv = __tmp;
  191. }
  192. // [string.view.ops], string operations:
  193. template<typename _Allocator>
  194. explicit operator basic_string<_CharT, _Traits, _Allocator>() const
  195. {
  196. return { this->_M_str, this->_M_len };
  197. }
  198. template<typename _Allocator = std::allocator<_CharT>>
  199. basic_string<_CharT, _Traits, _Allocator>
  200. to_string(const _Allocator& __alloc = _Allocator()) const
  201. {
  202. return { this->_M_str, this->_M_len, __alloc };
  203. }
  204. size_type
  205. copy(_CharT* __str, size_type __n, size_type __pos = 0) const
  206. {
  207. __glibcxx_requires_string_len(__str, __n);
  208. if (__pos > this->_M_len)
  209. __throw_out_of_range_fmt(__N("basic_string_view::copy: __pos "
  210. "(which is %zu) > this->size() "
  211. "(which is %zu)"),
  212. __pos, this->size());
  213. size_type __rlen{std::min(__n, size_type{this->_M_len - __pos})};
  214. for (auto __begin = this->_M_str + __pos,
  215. __end = __begin + __rlen; __begin != __end;)
  216. *__str++ = *__begin++;
  217. return __rlen;
  218. }
  219. // [string.view.ops], string operations:
  220. constexpr basic_string_view
  221. substr(size_type __pos = 0, size_type __n = npos) const
  222. {
  223. return __pos <= this->_M_len
  224. ? basic_string_view{this->_M_str + __pos,
  225. std::min(__n, size_type{this->_M_len - __pos})}
  226. : (__throw_out_of_range_fmt(__N("basic_string_view::substr: __pos "
  227. "(which is %zu) > this->size() "
  228. "(which is %zu)"),
  229. __pos, this->size()), basic_string_view{});
  230. }
  231. constexpr int
  232. compare(basic_string_view __str) const noexcept
  233. {
  234. int __ret = traits_type::compare(this->_M_str, __str._M_str,
  235. std::min(this->_M_len, __str._M_len));
  236. if (__ret == 0)
  237. __ret = _S_compare(this->_M_len, __str._M_len);
  238. return __ret;
  239. }
  240. constexpr int
  241. compare(size_type __pos1, size_type __n1, basic_string_view __str) const
  242. { return this->substr(__pos1, __n1).compare(__str); }
  243. constexpr int
  244. compare(size_type __pos1, size_type __n1,
  245. basic_string_view __str, size_type __pos2, size_type __n2) const
  246. { return this->substr(__pos1, __n1).compare(__str.substr(__pos2, __n2)); }
  247. constexpr int
  248. compare(const _CharT* __str) const noexcept
  249. { return this->compare(basic_string_view{__str}); }
  250. constexpr int
  251. compare(size_type __pos1, size_type __n1, const _CharT* __str) const
  252. { return this->substr(__pos1, __n1).compare(basic_string_view{__str}); }
  253. constexpr int
  254. compare(size_type __pos1, size_type __n1,
  255. const _CharT* __str, size_type __n2) const
  256. {
  257. return this->substr(__pos1, __n1)
  258. .compare(basic_string_view(__str, __n2));
  259. }
  260. constexpr size_type
  261. find(basic_string_view __str, size_type __pos = 0) const noexcept
  262. { return this->find(__str._M_str, __pos, __str._M_len); }
  263. constexpr size_type
  264. find(_CharT __c, size_type __pos=0) const noexcept;
  265. constexpr size_type
  266. find(const _CharT* __str, size_type __pos, size_type __n) const noexcept;
  267. constexpr size_type
  268. find(const _CharT* __str, size_type __pos=0) const noexcept
  269. { return this->find(__str, __pos, traits_type::length(__str)); }
  270. constexpr size_type
  271. rfind(basic_string_view __str, size_type __pos = npos) const noexcept
  272. { return this->rfind(__str._M_str, __pos, __str._M_len); }
  273. constexpr size_type
  274. rfind(_CharT __c, size_type __pos = npos) const noexcept;
  275. constexpr size_type
  276. rfind(const _CharT* __str, size_type __pos, size_type __n) const noexcept;
  277. constexpr size_type
  278. rfind(const _CharT* __str, size_type __pos = npos) const noexcept
  279. { return this->rfind(__str, __pos, traits_type::length(__str)); }
  280. constexpr size_type
  281. find_first_of(basic_string_view __str, size_type __pos = 0) const noexcept
  282. { return this->find_first_of(__str._M_str, __pos, __str._M_len); }
  283. constexpr size_type
  284. find_first_of(_CharT __c, size_type __pos = 0) const noexcept
  285. { return this->find(__c, __pos); }
  286. constexpr size_type
  287. find_first_of(const _CharT* __str, size_type __pos, size_type __n) const;
  288. constexpr size_type
  289. find_first_of(const _CharT* __str, size_type __pos = 0) const noexcept
  290. { return this->find_first_of(__str, __pos, traits_type::length(__str)); }
  291. constexpr size_type
  292. find_last_of(basic_string_view __str,
  293. size_type __pos = npos) const noexcept
  294. { return this->find_last_of(__str._M_str, __pos, __str._M_len); }
  295. constexpr size_type
  296. find_last_of(_CharT __c, size_type __pos=npos) const noexcept
  297. { return this->rfind(__c, __pos); }
  298. constexpr size_type
  299. find_last_of(const _CharT* __str, size_type __pos, size_type __n) const;
  300. constexpr size_type
  301. find_last_of(const _CharT* __str, size_type __pos = npos) const noexcept
  302. { return this->find_last_of(__str, __pos, traits_type::length(__str)); }
  303. constexpr size_type
  304. find_first_not_of(basic_string_view __str,
  305. size_type __pos = 0) const noexcept
  306. { return this->find_first_not_of(__str._M_str, __pos, __str._M_len); }
  307. constexpr size_type
  308. find_first_not_of(_CharT __c, size_type __pos = 0) const noexcept;
  309. constexpr size_type
  310. find_first_not_of(const _CharT* __str,
  311. size_type __pos, size_type __n) const;
  312. constexpr size_type
  313. find_first_not_of(const _CharT* __str, size_type __pos = 0) const noexcept
  314. {
  315. return this->find_first_not_of(__str, __pos,
  316. traits_type::length(__str));
  317. }
  318. constexpr size_type
  319. find_last_not_of(basic_string_view __str,
  320. size_type __pos = npos) const noexcept
  321. { return this->find_last_not_of(__str._M_str, __pos, __str._M_len); }
  322. constexpr size_type
  323. find_last_not_of(_CharT __c, size_type __pos = npos) const noexcept;
  324. constexpr size_type
  325. find_last_not_of(const _CharT* __str,
  326. size_type __pos, size_type __n) const;
  327. constexpr size_type
  328. find_last_not_of(const _CharT* __str,
  329. size_type __pos = npos) const noexcept
  330. {
  331. return this->find_last_not_of(__str, __pos,
  332. traits_type::length(__str));
  333. }
  334. private:
  335. static constexpr int
  336. _S_compare(size_type __n1, size_type __n2) noexcept
  337. {
  338. return difference_type(__n1 - __n2) > std::numeric_limits<int>::max()
  339. ? std::numeric_limits<int>::max()
  340. : difference_type(__n1 - __n2) < std::numeric_limits<int>::min()
  341. ? std::numeric_limits<int>::min()
  342. : static_cast<int>(difference_type(__n1 - __n2));
  343. }
  344. size_t _M_len;
  345. const _CharT* _M_str;
  346. };
  347. // [string.view.comparison], non-member basic_string_view comparison functions
  348. // Several of these functions use type_identity_t to create a non-deduced
  349. // context, so that only one argument participates in template argument
  350. // deduction and the other argument gets implicitly converted to the deduced
  351. // type (see N3766).
  352. template<typename _CharT, typename _Traits>
  353. constexpr bool
  354. operator==(basic_string_view<_CharT, _Traits> __x,
  355. basic_string_view<_CharT, _Traits> __y) noexcept
  356. { return __x.size() == __y.size() && __x.compare(__y) == 0; }
  357. template<typename _CharT, typename _Traits>
  358. constexpr bool
  359. operator==(basic_string_view<_CharT, _Traits> __x,
  360. __type_identity_t<basic_string_view<_CharT, _Traits>> __y)
  361. noexcept
  362. { return __x.size() == __y.size() && __x.compare(__y) == 0; }
  363. template<typename _CharT, typename _Traits>
  364. constexpr bool
  365. operator==(__type_identity_t<basic_string_view<_CharT, _Traits>> __x,
  366. basic_string_view<_CharT, _Traits> __y) noexcept
  367. { return __x.size() == __y.size() && __x.compare(__y) == 0; }
  368. template<typename _CharT, typename _Traits>
  369. constexpr bool
  370. operator!=(basic_string_view<_CharT, _Traits> __x,
  371. basic_string_view<_CharT, _Traits> __y) noexcept
  372. { return !(__x == __y); }
  373. template<typename _CharT, typename _Traits>
  374. constexpr bool
  375. operator!=(basic_string_view<_CharT, _Traits> __x,
  376. __type_identity_t<basic_string_view<_CharT, _Traits>> __y)
  377. noexcept
  378. { return !(__x == __y); }
  379. template<typename _CharT, typename _Traits>
  380. constexpr bool
  381. operator!=(__type_identity_t<basic_string_view<_CharT, _Traits>> __x,
  382. basic_string_view<_CharT, _Traits> __y) noexcept
  383. { return !(__x == __y); }
  384. template<typename _CharT, typename _Traits>
  385. constexpr bool
  386. operator< (basic_string_view<_CharT, _Traits> __x,
  387. basic_string_view<_CharT, _Traits> __y) noexcept
  388. { return __x.compare(__y) < 0; }
  389. template<typename _CharT, typename _Traits>
  390. constexpr bool
  391. operator< (basic_string_view<_CharT, _Traits> __x,
  392. __type_identity_t<basic_string_view<_CharT, _Traits>> __y)
  393. noexcept
  394. { return __x.compare(__y) < 0; }
  395. template<typename _CharT, typename _Traits>
  396. constexpr bool
  397. operator< (__type_identity_t<basic_string_view<_CharT, _Traits>> __x,
  398. basic_string_view<_CharT, _Traits> __y) noexcept
  399. { return __x.compare(__y) < 0; }
  400. template<typename _CharT, typename _Traits>
  401. constexpr bool
  402. operator> (basic_string_view<_CharT, _Traits> __x,
  403. basic_string_view<_CharT, _Traits> __y) noexcept
  404. { return __x.compare(__y) > 0; }
  405. template<typename _CharT, typename _Traits>
  406. constexpr bool
  407. operator> (basic_string_view<_CharT, _Traits> __x,
  408. __type_identity_t<basic_string_view<_CharT, _Traits>> __y)
  409. noexcept
  410. { return __x.compare(__y) > 0; }
  411. template<typename _CharT, typename _Traits>
  412. constexpr bool
  413. operator> (__type_identity_t<basic_string_view<_CharT, _Traits>> __x,
  414. basic_string_view<_CharT, _Traits> __y) noexcept
  415. { return __x.compare(__y) > 0; }
  416. template<typename _CharT, typename _Traits>
  417. constexpr bool
  418. operator<=(basic_string_view<_CharT, _Traits> __x,
  419. basic_string_view<_CharT, _Traits> __y) noexcept
  420. { return __x.compare(__y) <= 0; }
  421. template<typename _CharT, typename _Traits>
  422. constexpr bool
  423. operator<=(basic_string_view<_CharT, _Traits> __x,
  424. __type_identity_t<basic_string_view<_CharT, _Traits>> __y)
  425. noexcept
  426. { return __x.compare(__y) <= 0; }
  427. template<typename _CharT, typename _Traits>
  428. constexpr bool
  429. operator<=(__type_identity_t<basic_string_view<_CharT, _Traits>> __x,
  430. basic_string_view<_CharT, _Traits> __y) noexcept
  431. { return __x.compare(__y) <= 0; }
  432. template<typename _CharT, typename _Traits>
  433. constexpr bool
  434. operator>=(basic_string_view<_CharT, _Traits> __x,
  435. basic_string_view<_CharT, _Traits> __y) noexcept
  436. { return __x.compare(__y) >= 0; }
  437. template<typename _CharT, typename _Traits>
  438. constexpr bool
  439. operator>=(basic_string_view<_CharT, _Traits> __x,
  440. __type_identity_t<basic_string_view<_CharT, _Traits>> __y)
  441. noexcept
  442. { return __x.compare(__y) >= 0; }
  443. template<typename _CharT, typename _Traits>
  444. constexpr bool
  445. operator>=(__type_identity_t<basic_string_view<_CharT, _Traits>> __x,
  446. basic_string_view<_CharT, _Traits> __y) noexcept
  447. { return __x.compare(__y) >= 0; }
  448. // [string.view.io], Inserters and extractors
  449. template<typename _CharT, typename _Traits>
  450. inline basic_ostream<_CharT, _Traits>&
  451. operator<<(basic_ostream<_CharT, _Traits>& __os,
  452. basic_string_view<_CharT,_Traits> __str)
  453. { return __ostream_insert(__os, __str.data(), __str.size()); }
  454. // basic_string_view typedef names
  455. using string_view = basic_string_view<char>;
  456. #ifdef _GLIBCXX_USE_WCHAR_T
  457. using wstring_view = basic_string_view<wchar_t>;
  458. #endif
  459. #ifdef _GLIBCXX_USE_CHAR8_T
  460. using u8string_view = basic_string_view<char8_t>;
  461. #endif
  462. using u16string_view = basic_string_view<char16_t>;
  463. using u32string_view = basic_string_view<char32_t>;
  464. } // namespace fundamentals_v1
  465. } // namespace experimental
  466. // [string.view.hash], hash support:
  467. template<typename _Tp>
  468. struct hash;
  469. template<>
  470. struct hash<experimental::string_view>
  471. : public __hash_base<size_t, experimental::string_view>
  472. {
  473. size_t
  474. operator()(const experimental::string_view& __str) const noexcept
  475. { return std::_Hash_impl::hash(__str.data(), __str.length()); }
  476. };
  477. template<>
  478. struct __is_fast_hash<hash<experimental::string_view>> : std::false_type
  479. { };
  480. #ifdef _GLIBCXX_USE_WCHAR_T
  481. template<>
  482. struct hash<experimental::wstring_view>
  483. : public __hash_base<size_t, wstring>
  484. {
  485. size_t
  486. operator()(const experimental::wstring_view& __s) const noexcept
  487. { return std::_Hash_impl::hash(__s.data(),
  488. __s.length() * sizeof(wchar_t)); }
  489. };
  490. template<>
  491. struct __is_fast_hash<hash<experimental::wstring_view>> : std::false_type
  492. { };
  493. #endif
  494. #ifdef _GLIBCXX_USE_CHAR8_T
  495. template<>
  496. struct hash<experimental::u8string_view>
  497. : public __hash_base<size_t, experimental::u8string_view>
  498. {
  499. size_t
  500. operator()(const experimental::u8string_view& __s) const noexcept
  501. { return std::_Hash_impl::hash(__s.data(), __s.length()); }
  502. };
  503. template<>
  504. struct __is_fast_hash<hash<experimental::u8string_view>> : std::false_type
  505. { };
  506. #endif
  507. template<>
  508. struct hash<experimental::u16string_view>
  509. : public __hash_base<size_t, experimental::u16string_view>
  510. {
  511. size_t
  512. operator()(const experimental::u16string_view& __s) const noexcept
  513. { return std::_Hash_impl::hash(__s.data(),
  514. __s.length() * sizeof(char16_t)); }
  515. };
  516. template<>
  517. struct __is_fast_hash<hash<experimental::u16string_view>> : std::false_type
  518. { };
  519. template<>
  520. struct hash<experimental::u32string_view>
  521. : public __hash_base<size_t, experimental::u32string_view>
  522. {
  523. size_t
  524. operator()(const experimental::u32string_view& __s) const noexcept
  525. { return std::_Hash_impl::hash(__s.data(),
  526. __s.length() * sizeof(char32_t)); }
  527. };
  528. template<>
  529. struct __is_fast_hash<hash<experimental::u32string_view>> : std::false_type
  530. { };
  531. namespace experimental
  532. {
  533. // I added these EMSR.
  534. inline namespace literals
  535. {
  536. inline namespace string_view_literals
  537. {
  538. #pragma GCC diagnostic push
  539. #pragma GCC diagnostic ignored "-Wliteral-suffix"
  540. inline constexpr basic_string_view<char>
  541. operator""sv(const char* __str, size_t __len) noexcept
  542. { return basic_string_view<char>{__str, __len}; }
  543. #ifdef _GLIBCXX_USE_WCHAR_T
  544. inline constexpr basic_string_view<wchar_t>
  545. operator""sv(const wchar_t* __str, size_t __len) noexcept
  546. { return basic_string_view<wchar_t>{__str, __len}; }
  547. #endif
  548. #ifdef _GLIBCXX_USE_CHAR8_T
  549. inline constexpr basic_string_view<char8_t>
  550. operator""sv(const char8_t* __str, size_t __len) noexcept
  551. { return basic_string_view<char8_t>{__str, __len}; }
  552. #endif
  553. inline constexpr basic_string_view<char16_t>
  554. operator""sv(const char16_t* __str, size_t __len) noexcept
  555. { return basic_string_view<char16_t>{__str, __len}; }
  556. inline constexpr basic_string_view<char32_t>
  557. operator""sv(const char32_t* __str, size_t __len) noexcept
  558. { return basic_string_view<char32_t>{__str, __len}; }
  559. #pragma GCC diagnostic pop
  560. } // namespace string_literals
  561. } // namespace literals
  562. } // namespace experimental
  563. #if __cpp_lib_concepts
  564. namespace ranges
  565. {
  566. // Opt-in to borrowed_range concept
  567. template<typename _CharT, typename _Traits>
  568. inline constexpr bool
  569. enable_borrowed_range<experimental::basic_string_view<_CharT, _Traits>>
  570. = true;
  571. // Opt-in to view concept
  572. template<typename _CharT, typename _Traits>
  573. inline constexpr bool
  574. enable_view<experimental::basic_string_view<_CharT, _Traits>> = true;
  575. }
  576. #endif
  577. _GLIBCXX_END_NAMESPACE_VERSION
  578. } // namespace std
  579. #include <experimental/bits/string_view.tcc>
  580. #endif // __cplusplus <= 201103L
  581. #endif // _GLIBCXX_EXPERIMENTAL_STRING_VIEW