138fd1498Szrj// Components for manipulating non-owning sequences of characters -*- C++ -*- 238fd1498Szrj 338fd1498Szrj// Copyright (C) 2013-2018 Free Software Foundation, Inc. 438fd1498Szrj// 538fd1498Szrj// This file is part of the GNU ISO C++ Library. This library is free 638fd1498Szrj// software; you can redistribute it and/or modify it under the 738fd1498Szrj// terms of the GNU General Public License as published by the 838fd1498Szrj// Free Software Foundation; either version 3, or (at your option) 938fd1498Szrj// any later version. 1038fd1498Szrj 1138fd1498Szrj// This library is distributed in the hope that it will be useful, 1238fd1498Szrj// but WITHOUT ANY WARRANTY; without even the implied warranty of 1338fd1498Szrj// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1438fd1498Szrj// GNU General Public License for more details. 1538fd1498Szrj 1638fd1498Szrj// Under Section 7 of GPL version 3, you are granted additional 1738fd1498Szrj// permissions described in the GCC Runtime Library Exception, version 1838fd1498Szrj// 3.1, as published by the Free Software Foundation. 1938fd1498Szrj 2038fd1498Szrj// You should have received a copy of the GNU General Public License and 2138fd1498Szrj// a copy of the GCC Runtime Library Exception along with this program; 2238fd1498Szrj// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 2338fd1498Szrj// <http://www.gnu.org/licenses/>. 2438fd1498Szrj 2538fd1498Szrj/** @file experimental/string_view 2638fd1498Szrj * This is a TS C++ Library header. 2738fd1498Szrj */ 2838fd1498Szrj 2938fd1498Szrj// 3038fd1498Szrj// N3762 basic_string_view library 3138fd1498Szrj// 3238fd1498Szrj 3338fd1498Szrj#ifndef _GLIBCXX_EXPERIMENTAL_STRING_VIEW 3438fd1498Szrj#define _GLIBCXX_EXPERIMENTAL_STRING_VIEW 1 3538fd1498Szrj 3638fd1498Szrj#pragma GCC system_header 3738fd1498Szrj 3838fd1498Szrj#if __cplusplus >= 201402L 3938fd1498Szrj 4038fd1498Szrj#include <string> 4138fd1498Szrj#include <limits> 4238fd1498Szrj#include <experimental/bits/lfts_config.h> 4338fd1498Szrj 4438fd1498Szrjnamespace std _GLIBCXX_VISIBILITY(default) 4538fd1498Szrj{ 4638fd1498Szrj_GLIBCXX_BEGIN_NAMESPACE_VERSION 4738fd1498Szrj 4838fd1498Szrjnamespace experimental 4938fd1498Szrj{ 5038fd1498Szrjinline namespace fundamentals_v1 5138fd1498Szrj{ 5238fd1498Szrj#define __cpp_lib_experimental_string_view 201411 5338fd1498Szrj 5438fd1498Szrj /** 5538fd1498Szrj * @class basic_string_view <experimental/string_view> 5638fd1498Szrj * @brief A non-owning reference to a string. 5738fd1498Szrj * 5838fd1498Szrj * @ingroup strings 5938fd1498Szrj * @ingroup sequences 6038fd1498Szrj * @ingroup experimental 6138fd1498Szrj * 6238fd1498Szrj * @tparam _CharT Type of character 6338fd1498Szrj * @tparam _Traits Traits for character type, defaults to 6438fd1498Szrj * char_traits<_CharT>. 6538fd1498Szrj * 6638fd1498Szrj * A basic_string_view looks like this: 6738fd1498Szrj * 6838fd1498Szrj * @code 6938fd1498Szrj * _CharT* _M_str 7038fd1498Szrj * size_t _M_len 7138fd1498Szrj * @endcode 7238fd1498Szrj */ 7338fd1498Szrj template<typename _CharT, typename _Traits = std::char_traits<_CharT>> 7438fd1498Szrj class basic_string_view 7538fd1498Szrj { 7638fd1498Szrj public: 7738fd1498Szrj 7838fd1498Szrj // types 7938fd1498Szrj using traits_type = _Traits; 8038fd1498Szrj using value_type = _CharT; 8138fd1498Szrj using pointer = const _CharT*; 8238fd1498Szrj using const_pointer = const _CharT*; 8338fd1498Szrj using reference = const _CharT&; 8438fd1498Szrj using const_reference = const _CharT&; 8538fd1498Szrj using const_iterator = const _CharT*; 8638fd1498Szrj using iterator = const_iterator; 8738fd1498Szrj using const_reverse_iterator = std::reverse_iterator<const_iterator>; 8838fd1498Szrj using reverse_iterator = const_reverse_iterator; 8938fd1498Szrj using size_type = size_t; 9038fd1498Szrj using difference_type = ptrdiff_t; 9138fd1498Szrj static constexpr size_type npos = size_type(-1); 9238fd1498Szrj 9338fd1498Szrj // [string.view.cons], construct/copy 9438fd1498Szrj 9538fd1498Szrj constexpr 9638fd1498Szrj basic_string_view() noexcept 9738fd1498Szrj : _M_len{0}, _M_str{nullptr} 9838fd1498Szrj { } 9938fd1498Szrj 10038fd1498Szrj constexpr basic_string_view(const basic_string_view&) noexcept = default; 10138fd1498Szrj 10238fd1498Szrj template<typename _Allocator> 10338fd1498Szrj basic_string_view(const basic_string<_CharT, _Traits, 10438fd1498Szrj _Allocator>& __str) noexcept 10538fd1498Szrj : _M_len{__str.length()}, _M_str{__str.data()} 10638fd1498Szrj { } 10738fd1498Szrj 10838fd1498Szrj constexpr basic_string_view(const _CharT* __str) 10938fd1498Szrj : _M_len{__str == nullptr ? 0 : traits_type::length(__str)}, 11038fd1498Szrj _M_str{__str} 11138fd1498Szrj { } 11238fd1498Szrj 11338fd1498Szrj constexpr basic_string_view(const _CharT* __str, size_type __len) 11438fd1498Szrj : _M_len{__len}, 11538fd1498Szrj _M_str{__str} 11638fd1498Szrj { } 11738fd1498Szrj 11838fd1498Szrj basic_string_view& 11938fd1498Szrj operator=(const basic_string_view&) noexcept = default; 12038fd1498Szrj 12138fd1498Szrj // [string.view.iterators], iterators 12238fd1498Szrj 12338fd1498Szrj constexpr const_iterator 12438fd1498Szrj begin() const noexcept 12538fd1498Szrj { return this->_M_str; } 12638fd1498Szrj 12738fd1498Szrj constexpr const_iterator 12838fd1498Szrj end() const noexcept 12938fd1498Szrj { return this->_M_str + this->_M_len; } 13038fd1498Szrj 13138fd1498Szrj constexpr const_iterator 13238fd1498Szrj cbegin() const noexcept 13338fd1498Szrj { return this->_M_str; } 13438fd1498Szrj 13538fd1498Szrj constexpr const_iterator 13638fd1498Szrj cend() const noexcept 13738fd1498Szrj { return this->_M_str + this->_M_len; } 13838fd1498Szrj 13938fd1498Szrj const_reverse_iterator 14038fd1498Szrj rbegin() const noexcept 14138fd1498Szrj { return const_reverse_iterator(this->end()); } 14238fd1498Szrj 14338fd1498Szrj const_reverse_iterator 14438fd1498Szrj rend() const noexcept 14538fd1498Szrj { return const_reverse_iterator(this->begin()); } 14638fd1498Szrj 14738fd1498Szrj const_reverse_iterator 14838fd1498Szrj crbegin() const noexcept 14938fd1498Szrj { return const_reverse_iterator(this->end()); } 15038fd1498Szrj 15138fd1498Szrj const_reverse_iterator 15238fd1498Szrj crend() const noexcept 15338fd1498Szrj { return const_reverse_iterator(this->begin()); } 15438fd1498Szrj 15538fd1498Szrj // [string.view.capacity], capacity 15638fd1498Szrj 15738fd1498Szrj constexpr size_type 15838fd1498Szrj size() const noexcept 15938fd1498Szrj { return this->_M_len; } 16038fd1498Szrj 16138fd1498Szrj constexpr size_type 16238fd1498Szrj length() const noexcept 16338fd1498Szrj { return _M_len; } 16438fd1498Szrj 16538fd1498Szrj constexpr size_type 16638fd1498Szrj max_size() const noexcept 16738fd1498Szrj { 16838fd1498Szrj return (npos - sizeof(size_type) - sizeof(void*)) 16938fd1498Szrj / sizeof(value_type) / 4; 17038fd1498Szrj } 17138fd1498Szrj 17238fd1498Szrj constexpr bool 17338fd1498Szrj empty() const noexcept 17438fd1498Szrj { return this->_M_len == 0; } 17538fd1498Szrj 17638fd1498Szrj // [string.view.access], element access 17738fd1498Szrj 17838fd1498Szrj constexpr const _CharT& 17938fd1498Szrj operator[](size_type __pos) const 18038fd1498Szrj { 18138fd1498Szrj // TODO: Assert to restore in a way compatible with the constexpr. 18238fd1498Szrj // __glibcxx_assert(__pos < this->_M_len); 18338fd1498Szrj return *(this->_M_str + __pos); 18438fd1498Szrj } 18538fd1498Szrj 18638fd1498Szrj constexpr const _CharT& 18738fd1498Szrj at(size_type __pos) const 18838fd1498Szrj { 18938fd1498Szrj return __pos < this->_M_len 19038fd1498Szrj ? *(this->_M_str + __pos) 19138fd1498Szrj : (__throw_out_of_range_fmt(__N("basic_string_view::at: __pos " 19238fd1498Szrj "(which is %zu) >= this->size() " 19338fd1498Szrj "(which is %zu)"), 19438fd1498Szrj __pos, this->size()), 19538fd1498Szrj *this->_M_str); 19638fd1498Szrj } 19738fd1498Szrj 19838fd1498Szrj constexpr const _CharT& 19938fd1498Szrj front() const 20038fd1498Szrj { 20138fd1498Szrj // TODO: Assert to restore in a way compatible with the constexpr. 20238fd1498Szrj // __glibcxx_assert(this->_M_len > 0); 20338fd1498Szrj return *this->_M_str; 20438fd1498Szrj } 20538fd1498Szrj 20638fd1498Szrj constexpr const _CharT& 20738fd1498Szrj back() const 20838fd1498Szrj { 20938fd1498Szrj // TODO: Assert to restore in a way compatible with the constexpr. 21038fd1498Szrj // __glibcxx_assert(this->_M_len > 0); 21138fd1498Szrj return *(this->_M_str + this->_M_len - 1); 21238fd1498Szrj } 21338fd1498Szrj 21438fd1498Szrj constexpr const _CharT* 21538fd1498Szrj data() const noexcept 21638fd1498Szrj { return this->_M_str; } 21738fd1498Szrj 21838fd1498Szrj // [string.view.modifiers], modifiers: 21938fd1498Szrj 22038fd1498Szrj constexpr void 22138fd1498Szrj remove_prefix(size_type __n) 22238fd1498Szrj { 22338fd1498Szrj __glibcxx_assert(this->_M_len >= __n); 22438fd1498Szrj this->_M_str += __n; 22538fd1498Szrj this->_M_len -= __n; 22638fd1498Szrj } 22738fd1498Szrj 22838fd1498Szrj constexpr void 22938fd1498Szrj remove_suffix(size_type __n) 23038fd1498Szrj { this->_M_len -= __n; } 23138fd1498Szrj 23238fd1498Szrj constexpr void 23338fd1498Szrj swap(basic_string_view& __sv) noexcept 23438fd1498Szrj { 23538fd1498Szrj auto __tmp = *this; 23638fd1498Szrj *this = __sv; 23738fd1498Szrj __sv = __tmp; 23838fd1498Szrj } 23938fd1498Szrj 24038fd1498Szrj 24138fd1498Szrj // [string.view.ops], string operations: 24238fd1498Szrj 24338fd1498Szrj template<typename _Allocator> 24438fd1498Szrj explicit operator basic_string<_CharT, _Traits, _Allocator>() const 24538fd1498Szrj { 24638fd1498Szrj return { this->_M_str, this->_M_len }; 24738fd1498Szrj } 24838fd1498Szrj 24938fd1498Szrj template<typename _Allocator = std::allocator<_CharT>> 25038fd1498Szrj basic_string<_CharT, _Traits, _Allocator> 25138fd1498Szrj to_string(const _Allocator& __alloc = _Allocator()) const 25238fd1498Szrj { 25338fd1498Szrj return { this->_M_str, this->_M_len, __alloc }; 25438fd1498Szrj } 25538fd1498Szrj 25638fd1498Szrj size_type 25738fd1498Szrj copy(_CharT* __str, size_type __n, size_type __pos = 0) const 25838fd1498Szrj { 25938fd1498Szrj __glibcxx_requires_string_len(__str, __n); 26038fd1498Szrj if (__pos > this->_M_len) 26138fd1498Szrj __throw_out_of_range_fmt(__N("basic_string_view::copy: __pos " 26238fd1498Szrj "(which is %zu) > this->size() " 26338fd1498Szrj "(which is %zu)"), 26438fd1498Szrj __pos, this->size()); 26538fd1498Szrj size_type __rlen{std::min(__n, size_type{this->_M_len - __pos})}; 26638fd1498Szrj for (auto __begin = this->_M_str + __pos, 26738fd1498Szrj __end = __begin + __rlen; __begin != __end;) 26838fd1498Szrj *__str++ = *__begin++; 26938fd1498Szrj return __rlen; 27038fd1498Szrj } 27138fd1498Szrj 27238fd1498Szrj 27338fd1498Szrj // [string.view.ops], string operations: 27438fd1498Szrj 27538fd1498Szrj constexpr basic_string_view 276*58e805e6Szrj substr(size_type __pos = 0, size_type __n = npos) const 27738fd1498Szrj { 27838fd1498Szrj return __pos <= this->_M_len 27938fd1498Szrj ? basic_string_view{this->_M_str + __pos, 28038fd1498Szrj std::min(__n, size_type{this->_M_len - __pos})} 28138fd1498Szrj : (__throw_out_of_range_fmt(__N("basic_string_view::substr: __pos " 28238fd1498Szrj "(which is %zu) > this->size() " 28338fd1498Szrj "(which is %zu)"), 28438fd1498Szrj __pos, this->size()), basic_string_view{}); 28538fd1498Szrj } 28638fd1498Szrj 28738fd1498Szrj constexpr int 28838fd1498Szrj compare(basic_string_view __str) const noexcept 28938fd1498Szrj { 29038fd1498Szrj int __ret = traits_type::compare(this->_M_str, __str._M_str, 29138fd1498Szrj std::min(this->_M_len, __str._M_len)); 29238fd1498Szrj if (__ret == 0) 29338fd1498Szrj __ret = _S_compare(this->_M_len, __str._M_len); 29438fd1498Szrj return __ret; 29538fd1498Szrj } 29638fd1498Szrj 29738fd1498Szrj constexpr int 29838fd1498Szrj compare(size_type __pos1, size_type __n1, basic_string_view __str) const 29938fd1498Szrj { return this->substr(__pos1, __n1).compare(__str); } 30038fd1498Szrj 30138fd1498Szrj constexpr int 30238fd1498Szrj compare(size_type __pos1, size_type __n1, 30338fd1498Szrj basic_string_view __str, size_type __pos2, size_type __n2) const 30438fd1498Szrj { return this->substr(__pos1, __n1).compare(__str.substr(__pos2, __n2)); } 30538fd1498Szrj 30638fd1498Szrj constexpr int 30738fd1498Szrj compare(const _CharT* __str) const noexcept 30838fd1498Szrj { return this->compare(basic_string_view{__str}); } 30938fd1498Szrj 31038fd1498Szrj constexpr int 31138fd1498Szrj compare(size_type __pos1, size_type __n1, const _CharT* __str) const 31238fd1498Szrj { return this->substr(__pos1, __n1).compare(basic_string_view{__str}); } 31338fd1498Szrj 31438fd1498Szrj constexpr int 31538fd1498Szrj compare(size_type __pos1, size_type __n1, 31638fd1498Szrj const _CharT* __str, size_type __n2) const 31738fd1498Szrj { 31838fd1498Szrj return this->substr(__pos1, __n1) 31938fd1498Szrj .compare(basic_string_view(__str, __n2)); 32038fd1498Szrj } 32138fd1498Szrj 32238fd1498Szrj constexpr size_type 32338fd1498Szrj find(basic_string_view __str, size_type __pos = 0) const noexcept 32438fd1498Szrj { return this->find(__str._M_str, __pos, __str._M_len); } 32538fd1498Szrj 32638fd1498Szrj constexpr size_type 32738fd1498Szrj find(_CharT __c, size_type __pos=0) const noexcept; 32838fd1498Szrj 32938fd1498Szrj constexpr size_type 33038fd1498Szrj find(const _CharT* __str, size_type __pos, size_type __n) const noexcept; 33138fd1498Szrj 33238fd1498Szrj constexpr size_type 33338fd1498Szrj find(const _CharT* __str, size_type __pos=0) const noexcept 33438fd1498Szrj { return this->find(__str, __pos, traits_type::length(__str)); } 33538fd1498Szrj 33638fd1498Szrj constexpr size_type 33738fd1498Szrj rfind(basic_string_view __str, size_type __pos = npos) const noexcept 33838fd1498Szrj { return this->rfind(__str._M_str, __pos, __str._M_len); } 33938fd1498Szrj 34038fd1498Szrj constexpr size_type 34138fd1498Szrj rfind(_CharT __c, size_type __pos = npos) const noexcept; 34238fd1498Szrj 34338fd1498Szrj constexpr size_type 34438fd1498Szrj rfind(const _CharT* __str, size_type __pos, size_type __n) const noexcept; 34538fd1498Szrj 34638fd1498Szrj constexpr size_type 34738fd1498Szrj rfind(const _CharT* __str, size_type __pos = npos) const noexcept 34838fd1498Szrj { return this->rfind(__str, __pos, traits_type::length(__str)); } 34938fd1498Szrj 35038fd1498Szrj constexpr size_type 35138fd1498Szrj find_first_of(basic_string_view __str, size_type __pos = 0) const noexcept 35238fd1498Szrj { return this->find_first_of(__str._M_str, __pos, __str._M_len); } 35338fd1498Szrj 35438fd1498Szrj constexpr size_type 35538fd1498Szrj find_first_of(_CharT __c, size_type __pos = 0) const noexcept 35638fd1498Szrj { return this->find(__c, __pos); } 35738fd1498Szrj 35838fd1498Szrj constexpr size_type 35938fd1498Szrj find_first_of(const _CharT* __str, size_type __pos, size_type __n) const; 36038fd1498Szrj 36138fd1498Szrj constexpr size_type 36238fd1498Szrj find_first_of(const _CharT* __str, size_type __pos = 0) const noexcept 36338fd1498Szrj { return this->find_first_of(__str, __pos, traits_type::length(__str)); } 36438fd1498Szrj 36538fd1498Szrj constexpr size_type 36638fd1498Szrj find_last_of(basic_string_view __str, 36738fd1498Szrj size_type __pos = npos) const noexcept 36838fd1498Szrj { return this->find_last_of(__str._M_str, __pos, __str._M_len); } 36938fd1498Szrj 37038fd1498Szrj constexpr size_type 37138fd1498Szrj find_last_of(_CharT __c, size_type __pos=npos) const noexcept 37238fd1498Szrj { return this->rfind(__c, __pos); } 37338fd1498Szrj 37438fd1498Szrj constexpr size_type 37538fd1498Szrj find_last_of(const _CharT* __str, size_type __pos, size_type __n) const; 37638fd1498Szrj 37738fd1498Szrj constexpr size_type 37838fd1498Szrj find_last_of(const _CharT* __str, size_type __pos = npos) const noexcept 37938fd1498Szrj { return this->find_last_of(__str, __pos, traits_type::length(__str)); } 38038fd1498Szrj 38138fd1498Szrj constexpr size_type 38238fd1498Szrj find_first_not_of(basic_string_view __str, 38338fd1498Szrj size_type __pos = 0) const noexcept 38438fd1498Szrj { return this->find_first_not_of(__str._M_str, __pos, __str._M_len); } 38538fd1498Szrj 38638fd1498Szrj constexpr size_type 38738fd1498Szrj find_first_not_of(_CharT __c, size_type __pos = 0) const noexcept; 38838fd1498Szrj 38938fd1498Szrj constexpr size_type 39038fd1498Szrj find_first_not_of(const _CharT* __str, 39138fd1498Szrj size_type __pos, size_type __n) const; 39238fd1498Szrj 39338fd1498Szrj constexpr size_type 39438fd1498Szrj find_first_not_of(const _CharT* __str, size_type __pos = 0) const noexcept 39538fd1498Szrj { 39638fd1498Szrj return this->find_first_not_of(__str, __pos, 39738fd1498Szrj traits_type::length(__str)); 39838fd1498Szrj } 39938fd1498Szrj 40038fd1498Szrj constexpr size_type 40138fd1498Szrj find_last_not_of(basic_string_view __str, 40238fd1498Szrj size_type __pos = npos) const noexcept 40338fd1498Szrj { return this->find_last_not_of(__str._M_str, __pos, __str._M_len); } 40438fd1498Szrj 40538fd1498Szrj constexpr size_type 40638fd1498Szrj find_last_not_of(_CharT __c, size_type __pos = npos) const noexcept; 40738fd1498Szrj 40838fd1498Szrj constexpr size_type 40938fd1498Szrj find_last_not_of(const _CharT* __str, 41038fd1498Szrj size_type __pos, size_type __n) const; 41138fd1498Szrj 41238fd1498Szrj constexpr size_type 41338fd1498Szrj find_last_not_of(const _CharT* __str, 41438fd1498Szrj size_type __pos = npos) const noexcept 41538fd1498Szrj { 41638fd1498Szrj return this->find_last_not_of(__str, __pos, 41738fd1498Szrj traits_type::length(__str)); 41838fd1498Szrj } 41938fd1498Szrj 42038fd1498Szrj private: 42138fd1498Szrj 42238fd1498Szrj static constexpr int 42338fd1498Szrj _S_compare(size_type __n1, size_type __n2) noexcept 42438fd1498Szrj { 42538fd1498Szrj return difference_type(__n1 - __n2) > std::numeric_limits<int>::max() 42638fd1498Szrj ? std::numeric_limits<int>::max() 42738fd1498Szrj : difference_type(__n1 - __n2) < std::numeric_limits<int>::min() 42838fd1498Szrj ? std::numeric_limits<int>::min() 42938fd1498Szrj : static_cast<int>(difference_type(__n1 - __n2)); 43038fd1498Szrj } 43138fd1498Szrj 43238fd1498Szrj size_t _M_len; 43338fd1498Szrj const _CharT* _M_str; 43438fd1498Szrj }; 43538fd1498Szrj 43638fd1498Szrj // [string.view.comparison], non-member basic_string_view comparison functions 43738fd1498Szrj 43838fd1498Szrj namespace __detail 43938fd1498Szrj { 44038fd1498Szrj // Identity transform to create a non-deduced context, so that only one 44138fd1498Szrj // argument participates in template argument deduction and the other 44238fd1498Szrj // argument gets implicitly converted to the deduced type. See n3766.html. 44338fd1498Szrj template<typename _Tp> 44438fd1498Szrj using __idt = common_type_t<_Tp>; 44538fd1498Szrj } 44638fd1498Szrj 44738fd1498Szrj template<typename _CharT, typename _Traits> 44838fd1498Szrj constexpr bool 44938fd1498Szrj operator==(basic_string_view<_CharT, _Traits> __x, 45038fd1498Szrj basic_string_view<_CharT, _Traits> __y) noexcept 45138fd1498Szrj { return __x.size() == __y.size() && __x.compare(__y) == 0; } 45238fd1498Szrj 45338fd1498Szrj template<typename _CharT, typename _Traits> 45438fd1498Szrj constexpr bool 45538fd1498Szrj operator==(basic_string_view<_CharT, _Traits> __x, 45638fd1498Szrj __detail::__idt<basic_string_view<_CharT, _Traits>> __y) noexcept 45738fd1498Szrj { return __x.size() == __y.size() && __x.compare(__y) == 0; } 45838fd1498Szrj 45938fd1498Szrj template<typename _CharT, typename _Traits> 46038fd1498Szrj constexpr bool 46138fd1498Szrj operator==(__detail::__idt<basic_string_view<_CharT, _Traits>> __x, 46238fd1498Szrj basic_string_view<_CharT, _Traits> __y) noexcept 46338fd1498Szrj { return __x.size() == __y.size() && __x.compare(__y) == 0; } 46438fd1498Szrj 46538fd1498Szrj template<typename _CharT, typename _Traits> 46638fd1498Szrj constexpr bool 46738fd1498Szrj operator!=(basic_string_view<_CharT, _Traits> __x, 46838fd1498Szrj basic_string_view<_CharT, _Traits> __y) noexcept 46938fd1498Szrj { return !(__x == __y); } 47038fd1498Szrj 47138fd1498Szrj template<typename _CharT, typename _Traits> 47238fd1498Szrj constexpr bool 47338fd1498Szrj operator!=(basic_string_view<_CharT, _Traits> __x, 47438fd1498Szrj __detail::__idt<basic_string_view<_CharT, _Traits>> __y) noexcept 47538fd1498Szrj { return !(__x == __y); } 47638fd1498Szrj 47738fd1498Szrj template<typename _CharT, typename _Traits> 47838fd1498Szrj constexpr bool 47938fd1498Szrj operator!=(__detail::__idt<basic_string_view<_CharT, _Traits>> __x, 48038fd1498Szrj basic_string_view<_CharT, _Traits> __y) noexcept 48138fd1498Szrj { return !(__x == __y); } 48238fd1498Szrj 48338fd1498Szrj template<typename _CharT, typename _Traits> 48438fd1498Szrj constexpr bool 48538fd1498Szrj operator< (basic_string_view<_CharT, _Traits> __x, 48638fd1498Szrj basic_string_view<_CharT, _Traits> __y) noexcept 48738fd1498Szrj { return __x.compare(__y) < 0; } 48838fd1498Szrj 48938fd1498Szrj template<typename _CharT, typename _Traits> 49038fd1498Szrj constexpr bool 49138fd1498Szrj operator< (basic_string_view<_CharT, _Traits> __x, 49238fd1498Szrj __detail::__idt<basic_string_view<_CharT, _Traits>> __y) noexcept 49338fd1498Szrj { return __x.compare(__y) < 0; } 49438fd1498Szrj 49538fd1498Szrj template<typename _CharT, typename _Traits> 49638fd1498Szrj constexpr bool 49738fd1498Szrj operator< (__detail::__idt<basic_string_view<_CharT, _Traits>> __x, 49838fd1498Szrj basic_string_view<_CharT, _Traits> __y) noexcept 49938fd1498Szrj { return __x.compare(__y) < 0; } 50038fd1498Szrj 50138fd1498Szrj template<typename _CharT, typename _Traits> 50238fd1498Szrj constexpr bool 50338fd1498Szrj operator> (basic_string_view<_CharT, _Traits> __x, 50438fd1498Szrj basic_string_view<_CharT, _Traits> __y) noexcept 50538fd1498Szrj { return __x.compare(__y) > 0; } 50638fd1498Szrj 50738fd1498Szrj template<typename _CharT, typename _Traits> 50838fd1498Szrj constexpr bool 50938fd1498Szrj operator> (basic_string_view<_CharT, _Traits> __x, 51038fd1498Szrj __detail::__idt<basic_string_view<_CharT, _Traits>> __y) noexcept 51138fd1498Szrj { return __x.compare(__y) > 0; } 51238fd1498Szrj 51338fd1498Szrj template<typename _CharT, typename _Traits> 51438fd1498Szrj constexpr bool 51538fd1498Szrj operator> (__detail::__idt<basic_string_view<_CharT, _Traits>> __x, 51638fd1498Szrj basic_string_view<_CharT, _Traits> __y) noexcept 51738fd1498Szrj { return __x.compare(__y) > 0; } 51838fd1498Szrj 51938fd1498Szrj template<typename _CharT, typename _Traits> 52038fd1498Szrj constexpr bool 52138fd1498Szrj operator<=(basic_string_view<_CharT, _Traits> __x, 52238fd1498Szrj basic_string_view<_CharT, _Traits> __y) noexcept 52338fd1498Szrj { return __x.compare(__y) <= 0; } 52438fd1498Szrj 52538fd1498Szrj template<typename _CharT, typename _Traits> 52638fd1498Szrj constexpr bool 52738fd1498Szrj operator<=(basic_string_view<_CharT, _Traits> __x, 52838fd1498Szrj __detail::__idt<basic_string_view<_CharT, _Traits>> __y) noexcept 52938fd1498Szrj { return __x.compare(__y) <= 0; } 53038fd1498Szrj 53138fd1498Szrj template<typename _CharT, typename _Traits> 53238fd1498Szrj constexpr bool 53338fd1498Szrj operator<=(__detail::__idt<basic_string_view<_CharT, _Traits>> __x, 53438fd1498Szrj basic_string_view<_CharT, _Traits> __y) noexcept 53538fd1498Szrj { return __x.compare(__y) <= 0; } 53638fd1498Szrj 53738fd1498Szrj template<typename _CharT, typename _Traits> 53838fd1498Szrj constexpr bool 53938fd1498Szrj operator>=(basic_string_view<_CharT, _Traits> __x, 54038fd1498Szrj basic_string_view<_CharT, _Traits> __y) noexcept 54138fd1498Szrj { return __x.compare(__y) >= 0; } 54238fd1498Szrj 54338fd1498Szrj template<typename _CharT, typename _Traits> 54438fd1498Szrj constexpr bool 54538fd1498Szrj operator>=(basic_string_view<_CharT, _Traits> __x, 54638fd1498Szrj __detail::__idt<basic_string_view<_CharT, _Traits>> __y) noexcept 54738fd1498Szrj { return __x.compare(__y) >= 0; } 54838fd1498Szrj 54938fd1498Szrj template<typename _CharT, typename _Traits> 55038fd1498Szrj constexpr bool 55138fd1498Szrj operator>=(__detail::__idt<basic_string_view<_CharT, _Traits>> __x, 55238fd1498Szrj basic_string_view<_CharT, _Traits> __y) noexcept 55338fd1498Szrj { return __x.compare(__y) >= 0; } 55438fd1498Szrj 55538fd1498Szrj // [string.view.io], Inserters and extractors 55638fd1498Szrj template<typename _CharT, typename _Traits> 55738fd1498Szrj inline basic_ostream<_CharT, _Traits>& 55838fd1498Szrj operator<<(basic_ostream<_CharT, _Traits>& __os, 55938fd1498Szrj basic_string_view<_CharT,_Traits> __str) 56038fd1498Szrj { return __ostream_insert(__os, __str.data(), __str.size()); } 56138fd1498Szrj 56238fd1498Szrj 56338fd1498Szrj // basic_string_view typedef names 56438fd1498Szrj 56538fd1498Szrj using string_view = basic_string_view<char>; 56638fd1498Szrj#ifdef _GLIBCXX_USE_WCHAR_T 56738fd1498Szrj using wstring_view = basic_string_view<wchar_t>; 56838fd1498Szrj#endif 56938fd1498Szrj#ifdef _GLIBCXX_USE_C99_STDINT_TR1 57038fd1498Szrj using u16string_view = basic_string_view<char16_t>; 57138fd1498Szrj using u32string_view = basic_string_view<char32_t>; 57238fd1498Szrj#endif 57338fd1498Szrj} // namespace fundamentals_v1 57438fd1498Szrj} // namespace experimental 57538fd1498Szrj 57638fd1498Szrj 57738fd1498Szrj // [string.view.hash], hash support: 57838fd1498Szrj template<typename _Tp> 57938fd1498Szrj struct hash; 58038fd1498Szrj 58138fd1498Szrj template<> 58238fd1498Szrj struct hash<experimental::string_view> 58338fd1498Szrj : public __hash_base<size_t, experimental::string_view> 58438fd1498Szrj { 58538fd1498Szrj size_t 58638fd1498Szrj operator()(const experimental::string_view& __str) const noexcept 58738fd1498Szrj { return std::_Hash_impl::hash(__str.data(), __str.length()); } 58838fd1498Szrj }; 58938fd1498Szrj 59038fd1498Szrj template<> 59138fd1498Szrj struct __is_fast_hash<hash<experimental::string_view>> : std::false_type 59238fd1498Szrj { }; 59338fd1498Szrj 59438fd1498Szrj#ifdef _GLIBCXX_USE_WCHAR_T 59538fd1498Szrj template<> 59638fd1498Szrj struct hash<experimental::wstring_view> 59738fd1498Szrj : public __hash_base<size_t, wstring> 59838fd1498Szrj { 59938fd1498Szrj size_t 60038fd1498Szrj operator()(const experimental::wstring_view& __s) const noexcept 60138fd1498Szrj { return std::_Hash_impl::hash(__s.data(), 60238fd1498Szrj __s.length() * sizeof(wchar_t)); } 60338fd1498Szrj }; 60438fd1498Szrj 60538fd1498Szrj template<> 60638fd1498Szrj struct __is_fast_hash<hash<experimental::wstring_view>> : std::false_type 60738fd1498Szrj { }; 60838fd1498Szrj#endif 60938fd1498Szrj 61038fd1498Szrj#ifdef _GLIBCXX_USE_C99_STDINT_TR1 61138fd1498Szrj template<> 61238fd1498Szrj struct hash<experimental::u16string_view> 61338fd1498Szrj : public __hash_base<size_t, experimental::u16string_view> 61438fd1498Szrj { 61538fd1498Szrj size_t 61638fd1498Szrj operator()(const experimental::u16string_view& __s) const noexcept 61738fd1498Szrj { return std::_Hash_impl::hash(__s.data(), 61838fd1498Szrj __s.length() * sizeof(char16_t)); } 61938fd1498Szrj }; 62038fd1498Szrj 62138fd1498Szrj template<> 62238fd1498Szrj struct __is_fast_hash<hash<experimental::u16string_view>> : std::false_type 62338fd1498Szrj { }; 62438fd1498Szrj 62538fd1498Szrj template<> 62638fd1498Szrj struct hash<experimental::u32string_view> 62738fd1498Szrj : public __hash_base<size_t, experimental::u32string_view> 62838fd1498Szrj { 62938fd1498Szrj size_t 63038fd1498Szrj operator()(const experimental::u32string_view& __s) const noexcept 63138fd1498Szrj { return std::_Hash_impl::hash(__s.data(), 63238fd1498Szrj __s.length() * sizeof(char32_t)); } 63338fd1498Szrj }; 63438fd1498Szrj 63538fd1498Szrj template<> 63638fd1498Szrj struct __is_fast_hash<hash<experimental::u32string_view>> : std::false_type 63738fd1498Szrj { }; 63838fd1498Szrj#endif 63938fd1498Szrj 64038fd1498Szrjnamespace experimental 64138fd1498Szrj{ 64238fd1498Szrj // I added these EMSR. 64338fd1498Szrj inline namespace literals 64438fd1498Szrj { 64538fd1498Szrj inline namespace string_view_literals 64638fd1498Szrj { 64738fd1498Szrj#pragma GCC diagnostic push 64838fd1498Szrj#pragma GCC diagnostic ignored "-Wliteral-suffix" 64938fd1498Szrj inline constexpr basic_string_view<char> 65038fd1498Szrj operator""sv(const char* __str, size_t __len) noexcept 65138fd1498Szrj { return basic_string_view<char>{__str, __len}; } 65238fd1498Szrj 65338fd1498Szrj#ifdef _GLIBCXX_USE_WCHAR_T 65438fd1498Szrj inline constexpr basic_string_view<wchar_t> 65538fd1498Szrj operator""sv(const wchar_t* __str, size_t __len) noexcept 65638fd1498Szrj { return basic_string_view<wchar_t>{__str, __len}; } 65738fd1498Szrj#endif 65838fd1498Szrj 65938fd1498Szrj#ifdef _GLIBCXX_USE_C99_STDINT_TR1 66038fd1498Szrj inline constexpr basic_string_view<char16_t> 66138fd1498Szrj operator""sv(const char16_t* __str, size_t __len) noexcept 66238fd1498Szrj { return basic_string_view<char16_t>{__str, __len}; } 66338fd1498Szrj 66438fd1498Szrj inline constexpr basic_string_view<char32_t> 66538fd1498Szrj operator""sv(const char32_t* __str, size_t __len) noexcept 66638fd1498Szrj { return basic_string_view<char32_t>{__str, __len}; } 66738fd1498Szrj#endif 66838fd1498Szrj#pragma GCC diagnostic pop 66938fd1498Szrj } // namespace string_literals 67038fd1498Szrj } // namespace literals 67138fd1498Szrj} // namespace experimental 67238fd1498Szrj 67338fd1498Szrj_GLIBCXX_END_NAMESPACE_VERSION 67438fd1498Szrj} // namespace std 67538fd1498Szrj 67638fd1498Szrj#include <experimental/bits/string_view.tcc> 67738fd1498Szrj 67838fd1498Szrj#endif // __cplusplus <= 201103L 67938fd1498Szrj 68038fd1498Szrj#endif // _GLIBCXX_EXPERIMENTAL_STRING_VIEW 681