string_view 21 KB

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