head	1.1;
branch	1.1.1;
access;
symbols
	netbsd-11-0-RC4:1.1.1.10
	netbsd-11-0-RC3:1.1.1.10
	netbsd-11-0-RC2:1.1.1.10
	netbsd-11-0-RC1:1.1.1.10
	gcc-14-3-0:1.1.1.11
	perseant-exfatfs-base-20250801:1.1.1.10
	netbsd-11:1.1.1.10.0.2
	netbsd-11-base:1.1.1.10
	gcc-12-5-0:1.1.1.10
	netbsd-10-1-RELEASE:1.1.1.7
	perseant-exfatfs-base-20240630:1.1.1.9
	gcc-12-4-0:1.1.1.9
	perseant-exfatfs:1.1.1.8.0.2
	perseant-exfatfs-base:1.1.1.8
	netbsd-9-4-RELEASE:1.1.1.1
	netbsd-10-0-RELEASE:1.1.1.7
	netbsd-10-0-RC6:1.1.1.7
	netbsd-10-0-RC5:1.1.1.7
	netbsd-10-0-RC4:1.1.1.7
	netbsd-10-0-RC3:1.1.1.7
	netbsd-10-0-RC2:1.1.1.7
	netbsd-10-0-RC1:1.1.1.7
	gcc-12-3-0:1.1.1.8
	gcc-10-5-0:1.1.1.7
	netbsd-10:1.1.1.7.0.2
	netbsd-10-base:1.1.1.7
	netbsd-9-3-RELEASE:1.1.1.1
	gcc-10-4-0:1.1.1.7
	cjep_sun2x-base1:1.1.1.6
	cjep_sun2x:1.1.1.6.0.4
	cjep_sun2x-base:1.1.1.6
	cjep_staticlib_x-base1:1.1.1.6
	netbsd-9-2-RELEASE:1.1.1.1
	cjep_staticlib_x:1.1.1.6.0.2
	cjep_staticlib_x-base:1.1.1.6
	gcc-10-3-0:1.1.1.6
	netbsd-9-1-RELEASE:1.1.1.1
	gcc-9-3-0:1.1.1.5
	gcc-7-5-0:1.1.1.3
	phil-wifi-20200421:1.1.1.2
	phil-wifi-20200411:1.1.1.2
	is-mlppp:1.1.1.2.0.2
	is-mlppp-base:1.1.1.2
	phil-wifi-20200406:1.1.1.2
	gcc-8-4-0:1.1.1.4
	netbsd-9-0-RELEASE:1.1.1.1
	netbsd-9-0-RC2:1.1.1.1
	netbsd-9-0-RC1:1.1.1.1
	phil-wifi-20191119:1.1.1.2
	gcc-8-3-0:1.1.1.2
	netbsd-9:1.1.1.1.0.6
	netbsd-9-base:1.1.1.1
	phil-wifi:1.1.1.1.0.4
	phil-wifi-20190609:1.1.1.1
	pgoyette-compat-merge-20190127:1.1.1.1.2.2
	pgoyette-compat:1.1.1.1.0.2
	pgoyette-compat-20190127:1.1.1.1
	gcc-7-4-0:1.1.1.1
	FSF:1.1.1;
locks; strict;
comment	@# @;


1.1
date	2019.01.19.10.14.11;	author mrg;	state Exp;
branches
	1.1.1.1;
next	;
commitid	VQ8OwWIg5RS9kn8B;

1.1.1.1
date	2019.01.19.10.14.11;	author mrg;	state Exp;
branches
	1.1.1.1.2.1
	1.1.1.1.4.1;
next	1.1.1.2;
commitid	VQ8OwWIg5RS9kn8B;

1.1.1.2
date	2019.10.01.09.36.06;	author mrg;	state Exp;
branches;
next	1.1.1.3;
commitid	smvgr2IPAQDr89FB;

1.1.1.3
date	2020.08.11.05.10.39;	author mrg;	state Exp;
branches;
next	1.1.1.4;
commitid	5dBRDT7i6e65xBjC;

1.1.1.4
date	2020.08.11.05.30.09;	author mrg;	state Exp;
branches;
next	1.1.1.5;
commitid	7AI4OfpLi4eqEBjC;

1.1.1.5
date	2020.09.05.07.52.09;	author mrg;	state Exp;
branches;
next	1.1.1.6;
commitid	ZRYA7IOuwfMjAPmC;

1.1.1.6
date	2021.04.10.22.10.04;	author mrg;	state Exp;
branches;
next	1.1.1.7;
commitid	eC4g0MRpqTvEkNOC;

1.1.1.7
date	2022.07.22.19.52.36;	author mrg;	state Exp;
branches;
next	1.1.1.8;
commitid	fUYPgdKzIHqhwVMD;

1.1.1.8
date	2023.07.30.05.21.20;	author mrg;	state Exp;
branches
	1.1.1.8.2.1;
next	1.1.1.9;
commitid	tk6nV4mbc9nVEMyE;

1.1.1.9
date	2024.06.30.07.35.40;	author mrg;	state Exp;
branches;
next	1.1.1.10;
commitid	m7BwZsPdfJvuHYfF;

1.1.1.10
date	2025.07.21.02.43.41;	author mrg;	state Exp;
branches;
next	1.1.1.11;
commitid	9k1gPU4fqf8VHy3G;

1.1.1.11
date	2025.09.13.23.45.48;	author mrg;	state Exp;
branches;
next	;
commitid	KwhwN4krNWa6XBaG;

1.1.1.1.2.1
date	2019.01.19.10.14.11;	author pgoyette;	state dead;
branches;
next	1.1.1.1.2.2;
commitid	JKpcmvSjdT25dl9B;

1.1.1.1.2.2
date	2019.01.26.21.59.39;	author pgoyette;	state Exp;
branches;
next	;
commitid	JKpcmvSjdT25dl9B;

1.1.1.1.4.1
date	2019.01.19.10.14.11;	author christos;	state dead;
branches;
next	1.1.1.1.4.2;
commitid	jtc8rnCzWiEEHGqB;

1.1.1.1.4.2
date	2019.06.10.21.54.58;	author christos;	state Exp;
branches;
next	1.1.1.1.4.3;
commitid	jtc8rnCzWiEEHGqB;

1.1.1.1.4.3
date	2020.04.13.07.58.43;	author martin;	state Exp;
branches;
next	;
commitid	X01YhRUPVUDaec4C;

1.1.1.8.2.1
date	2024.07.01.01.00.59;	author perseant;	state Exp;
branches;
next	1.1.1.8.2.2;
commitid	NkoYLLCQWWw9v4gF;

1.1.1.8.2.2
date	2025.08.02.05.25.54;	author perseant;	state Exp;
branches;
next	;
commitid	23j6GFaDws3O875G;


desc
@@


1.1
log
@Initial revision
@
text
@// Components for manipulating non-owning sequences of characters -*- C++ -*-

// Copyright (C) 2013-2017 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library.  This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.

// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// Under Section 7 of GPL version 3, you are granted additional
// permissions described in the GCC Runtime Library Exception, version
// 3.1, as published by the Free Software Foundation.

// You should have received a copy of the GNU General Public License and
// a copy of the GCC Runtime Library Exception along with this program;
// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
// <http://www.gnu.org/licenses/>.

/** @@file string_view
 *  This is a Standard C++ Library header.
 */

//
// N3762 basic_string_view library
//

#ifndef _GLIBCXX_STRING_VIEW
#define _GLIBCXX_STRING_VIEW 1

#pragma GCC system_header

#if __cplusplus >= 201703L

#include <limits>
#include <iosfwd>
#include <bits/char_traits.h>
#include <bits/functional_hash.h>
#include <bits/range_access.h>

namespace std _GLIBCXX_VISIBILITY(default)
{
_GLIBCXX_BEGIN_NAMESPACE_VERSION

#define __cpp_lib_string_view 201603

  /**
   *  @@class basic_string_view <string_view>
   *  @@brief  A non-owning reference to a string.
   *
   *  @@ingroup strings
   *  @@ingroup sequences
   *
   *  @@tparam _CharT  Type of character
   *  @@tparam _Traits  Traits for character type, defaults to
   *                   char_traits<_CharT>.
   *
   *  A basic_string_view looks like this:
   *
   *  @@code
   *    _CharT*    _M_str
   *    size_t     _M_len
   *  @@endcode
   */
  template<typename _CharT, typename _Traits = std::char_traits<_CharT>>
    class basic_string_view
    {
    public:

      // types
      using traits_type = _Traits;
      using value_type = _CharT;
      using pointer = const _CharT*;
      using const_pointer = const _CharT*;
      using reference = const _CharT&;
      using const_reference = const _CharT&;
      using const_iterator = const _CharT*;
      using iterator = const_iterator;
      using const_reverse_iterator = std::reverse_iterator<const_iterator>;
      using reverse_iterator = const_reverse_iterator;
      using size_type = size_t;
      using difference_type = ptrdiff_t;
      static constexpr size_type npos = size_type(-1);

      // [string.view.cons], construct/copy

      constexpr
      basic_string_view() noexcept
      : _M_len{0}, _M_str{nullptr}
      { }

      constexpr basic_string_view(const basic_string_view&) noexcept = default;

      constexpr basic_string_view(const _CharT* __str)
      : _M_len{__str == nullptr ? 0 : traits_type::length(__str)},
	_M_str{__str}
      { }

      constexpr basic_string_view(const _CharT* __str, size_type __len)
      : _M_len{__len},
        _M_str{__str}
      { }

      constexpr basic_string_view&
      operator=(const basic_string_view&) noexcept = default;

      // [string.view.iterators], iterators

      constexpr const_iterator
      begin() const noexcept
      { return this->_M_str; }

      constexpr const_iterator
      end() const noexcept
      { return this->_M_str + this->_M_len; }

      constexpr const_iterator
      cbegin() const noexcept
      { return this->_M_str; }

      constexpr const_iterator
      cend() const noexcept
      { return this->_M_str + this->_M_len; }

      constexpr const_reverse_iterator
      rbegin() const noexcept
      { return const_reverse_iterator(this->end()); }

      constexpr const_reverse_iterator
      rend() const noexcept
      { return const_reverse_iterator(this->begin()); }

      constexpr const_reverse_iterator
      crbegin() const noexcept
      { return const_reverse_iterator(this->end()); }

      constexpr const_reverse_iterator
      crend() const noexcept
      { return const_reverse_iterator(this->begin()); }

      // [string.view.capacity], capacity

      constexpr size_type
      size() const noexcept
      { return this->_M_len; }

      constexpr size_type
      length() const noexcept
      { return _M_len; }

      constexpr size_type
      max_size() const noexcept
      {
	return (npos - sizeof(size_type) - sizeof(void*))
		/ sizeof(value_type) / 4;
      }

      constexpr bool
      empty() const noexcept
      { return this->_M_len == 0; }

      // [string.view.access], element access

      constexpr const _CharT&
      operator[](size_type __pos) const noexcept
      {
	// TODO: Assert to restore in a way compatible with the constexpr.
	// __glibcxx_assert(__pos < this->_M_len);
	return *(this->_M_str + __pos);
      }

      constexpr const _CharT&
      at(size_type __pos) const
      {
	return __pos < this->_M_len
	     ? *(this->_M_str + __pos)
	     : (__throw_out_of_range_fmt(__N("basic_string_view::at: __pos "
					     "(which is %zu) >= this->size() "
					     "(which is %zu)"),
					 __pos, this->size()),
		*this->_M_str);
      }

      constexpr const _CharT&
      front() const
      {
	// TODO: Assert to restore in a way compatible with the constexpr.
	// __glibcxx_assert(this->_M_len > 0);
	return *this->_M_str;
      }

      constexpr const _CharT&
      back() const
      {
	// TODO: Assert to restore in a way compatible with the constexpr.
	// __glibcxx_assert(this->_M_len > 0);
	return *(this->_M_str + this->_M_len - 1);
      }

      constexpr const _CharT*
      data() const noexcept
      { return this->_M_str; }

      // [string.view.modifiers], modifiers:

      constexpr void
      remove_prefix(size_type __n)
      {
	__glibcxx_assert(this->_M_len >= __n);
	this->_M_str += __n;
	this->_M_len -= __n;
      }

      constexpr void
      remove_suffix(size_type __n)
      { this->_M_len -= __n; }

      constexpr void
      swap(basic_string_view& __sv) noexcept
      {
	auto __tmp = *this;
	*this = __sv;
	__sv = __tmp;
      }


      // [string.view.ops], string operations:

      size_type
      copy(_CharT* __str, size_type __n, size_type __pos = 0) const
      {
	__glibcxx_requires_string_len(__str, __n);
	if (__pos > this->_M_len)
	  __throw_out_of_range_fmt(__N("basic_string_view::copy: __pos "
				       "(which is %zu) > this->size() "
				       "(which is %zu)"),
				   __pos, this->size());
	size_type __rlen{std::min(__n, size_type{this->_M_len  - __pos})};
	for (auto __begin = this->_M_str + __pos,
	     __end = __begin + __rlen; __begin != __end;)
	  *__str++ = *__begin++;
	return __rlen;
      }


      // [string.view.ops], string operations:

      constexpr basic_string_view
      substr(size_type __pos, size_type __n=npos) const
      {
	return __pos <= this->_M_len
	     ? basic_string_view{this->_M_str + __pos,
				std::min(__n, size_type{this->_M_len  - __pos})}
	     : (__throw_out_of_range_fmt(__N("basic_string_view::substr: __pos "
					     "(which is %zu) > this->size() "
					     "(which is %zu)"),
				     __pos, this->size()), basic_string_view{});
      }

      constexpr int
      compare(basic_string_view __str) const noexcept
      {
	int __ret = traits_type::compare(this->_M_str, __str._M_str,
					 std::min(this->_M_len, __str._M_len));
	if (__ret == 0)
	  __ret = _S_compare(this->_M_len, __str._M_len);
	return __ret;
      }

      constexpr int
      compare(size_type __pos1, size_type __n1, basic_string_view __str) const
      { return this->substr(__pos1, __n1).compare(__str); }

      constexpr int
      compare(size_type __pos1, size_type __n1,
	      basic_string_view __str, size_type __pos2, size_type __n2) const
      { return this->substr(__pos1, __n1).compare(__str.substr(__pos2, __n2)); }

      constexpr int
      compare(const _CharT* __str) const noexcept
      { return this->compare(basic_string_view{__str}); }

      constexpr int
      compare(size_type __pos1, size_type __n1, const _CharT* __str) const
      { return this->substr(__pos1, __n1).compare(basic_string_view{__str}); }

      constexpr int
      compare(size_type __pos1, size_type __n1,
	      const _CharT* __str, size_type __n2) const
      {
	return this->substr(__pos1, __n1)
		   .compare(basic_string_view(__str, __n2));
      }

      constexpr size_type
      find(basic_string_view __str, size_type __pos = 0) const noexcept
      { return this->find(__str._M_str, __pos, __str._M_len); }

      constexpr size_type
      find(_CharT __c, size_type __pos=0) const noexcept;

      constexpr size_type
      find(const _CharT* __str, size_type __pos, size_type __n) const noexcept;

      constexpr size_type
      find(const _CharT* __str, size_type __pos=0) const noexcept
      { return this->find(__str, __pos, traits_type::length(__str)); }

      constexpr size_type
      rfind(basic_string_view __str, size_type __pos = npos) const noexcept
      { return this->rfind(__str._M_str, __pos, __str._M_len); }

      constexpr size_type
      rfind(_CharT __c, size_type __pos = npos) const noexcept;

      constexpr size_type
      rfind(const _CharT* __str, size_type __pos, size_type __n) const noexcept;

      constexpr size_type
      rfind(const _CharT* __str, size_type __pos = npos) const noexcept
      { return this->rfind(__str, __pos, traits_type::length(__str)); }

      constexpr size_type
      find_first_of(basic_string_view __str, size_type __pos = 0) const noexcept
      { return this->find_first_of(__str._M_str, __pos, __str._M_len); }

      constexpr size_type
      find_first_of(_CharT __c, size_type __pos = 0) const noexcept
      { return this->find(__c, __pos); }

      constexpr size_type
      find_first_of(const _CharT* __str, size_type __pos, size_type __n) const;

      constexpr size_type
      find_first_of(const _CharT* __str, size_type __pos = 0) const noexcept
      { return this->find_first_of(__str, __pos, traits_type::length(__str)); }

      constexpr size_type
      find_last_of(basic_string_view __str,
		   size_type __pos = npos) const noexcept
      { return this->find_last_of(__str._M_str, __pos, __str._M_len); }

      constexpr size_type
      find_last_of(_CharT __c, size_type __pos=npos) const noexcept
      { return this->rfind(__c, __pos); }

      constexpr size_type
      find_last_of(const _CharT* __str, size_type __pos, size_type __n) const;

      constexpr size_type
      find_last_of(const _CharT* __str, size_type __pos = npos) const noexcept
      { return this->find_last_of(__str, __pos, traits_type::length(__str)); }

      constexpr size_type
      find_first_not_of(basic_string_view __str,
			size_type __pos = 0) const noexcept
      { return this->find_first_not_of(__str._M_str, __pos, __str._M_len); }

      constexpr size_type
      find_first_not_of(_CharT __c, size_type __pos = 0) const noexcept;

      constexpr size_type
      find_first_not_of(const _CharT* __str,
			size_type __pos, size_type __n) const;

      constexpr size_type
      find_first_not_of(const _CharT* __str, size_type __pos = 0) const noexcept
      {
	return this->find_first_not_of(__str, __pos,
				       traits_type::length(__str));
      }

      constexpr size_type
      find_last_not_of(basic_string_view __str,
		       size_type __pos = npos) const noexcept
      { return this->find_last_not_of(__str._M_str, __pos, __str._M_len); }

      constexpr size_type
      find_last_not_of(_CharT __c, size_type __pos = npos) const noexcept;

      constexpr size_type
      find_last_not_of(const _CharT* __str,
		       size_type __pos, size_type __n) const;

      constexpr size_type
      find_last_not_of(const _CharT* __str,
		       size_type __pos = npos) const noexcept
      {
	return this->find_last_not_of(__str, __pos,
				      traits_type::length(__str));
      }

      constexpr size_type
      _M_check(size_type __pos, const char* __s) const
      {
	if (__pos > this->size())
	  __throw_out_of_range_fmt(__N("%s: __pos (which is %zu) > "
				       "this->size() (which is %zu)"),
				   __s, __pos, this->size());
	return __pos;
      }

      // NB: _M_limit doesn't check for a bad __pos value.
      constexpr size_type
      _M_limit(size_type __pos, size_type __off) const _GLIBCXX_NOEXCEPT
      {
	const bool __testoff =  __off < this->size() - __pos;
	return __testoff ? __off : this->size() - __pos;
      }
      
    private:

      static constexpr int
      _S_compare(size_type __n1, size_type __n2) noexcept
      {
	return difference_type{__n1 - __n2} > std::numeric_limits<int>::max()
	     ? std::numeric_limits<int>::max()
	     : difference_type{__n1 - __n2} < std::numeric_limits<int>::min()
	     ? std::numeric_limits<int>::min()
	     : static_cast<int>(difference_type{__n1 - __n2});
      }

      size_t	    _M_len;
      const _CharT* _M_str;
    };
_GLIBCXX_END_NAMESPACE_VERSION

  // [string.view.comparison], non-member basic_string_view comparison function

  namespace __detail
  {
_GLIBCXX_BEGIN_NAMESPACE_VERSION
    // Identity transform to create a non-deduced context, so that only one
    // argument participates in template argument deduction and the other
    // argument gets implicitly converted to the deduced type. See n3766.html.
    template<typename _Tp>
      using __idt = common_type_t<_Tp>;
_GLIBCXX_END_NAMESPACE_VERSION
  }

_GLIBCXX_BEGIN_NAMESPACE_VERSION

  template<typename _CharT, typename _Traits>
    constexpr bool
    operator==(basic_string_view<_CharT, _Traits> __x,
               basic_string_view<_CharT, _Traits> __y) noexcept
    { return __x.size() == __y.size() && __x.compare(__y) == 0; }

  template<typename _CharT, typename _Traits>
    constexpr bool
    operator==(basic_string_view<_CharT, _Traits> __x,
               __detail::__idt<basic_string_view<_CharT, _Traits>> __y) noexcept
    { return __x.size() == __y.size() && __x.compare(__y) == 0; }

  template<typename _CharT, typename _Traits>
    constexpr bool
    operator==(__detail::__idt<basic_string_view<_CharT, _Traits>> __x,
               basic_string_view<_CharT, _Traits> __y) noexcept
    { return __x.size() == __y.size() && __x.compare(__y) == 0; }

  template<typename _CharT, typename _Traits>
    constexpr bool
    operator!=(basic_string_view<_CharT, _Traits> __x,
               basic_string_view<_CharT, _Traits> __y) noexcept
    { return !(__x == __y); }

  template<typename _CharT, typename _Traits>
    constexpr bool
    operator!=(basic_string_view<_CharT, _Traits> __x,
               __detail::__idt<basic_string_view<_CharT, _Traits>> __y) noexcept
    { return !(__x == __y); }

  template<typename _CharT, typename _Traits>
    constexpr bool
    operator!=(__detail::__idt<basic_string_view<_CharT, _Traits>> __x,
               basic_string_view<_CharT, _Traits> __y) noexcept
    { return !(__x == __y); }

  template<typename _CharT, typename _Traits>
    constexpr bool
    operator< (basic_string_view<_CharT, _Traits> __x,
               basic_string_view<_CharT, _Traits> __y) noexcept
    { return __x.compare(__y) < 0; }

  template<typename _CharT, typename _Traits>
    constexpr bool
    operator< (basic_string_view<_CharT, _Traits> __x,
               __detail::__idt<basic_string_view<_CharT, _Traits>> __y) noexcept
    { return __x.compare(__y) < 0; }

  template<typename _CharT, typename _Traits>
    constexpr bool
    operator< (__detail::__idt<basic_string_view<_CharT, _Traits>> __x,
               basic_string_view<_CharT, _Traits> __y) noexcept
    { return __x.compare(__y) < 0; }

  template<typename _CharT, typename _Traits>
    constexpr bool
    operator> (basic_string_view<_CharT, _Traits> __x,
               basic_string_view<_CharT, _Traits> __y) noexcept
    { return __x.compare(__y) > 0; }

  template<typename _CharT, typename _Traits>
    constexpr bool
    operator> (basic_string_view<_CharT, _Traits> __x,
               __detail::__idt<basic_string_view<_CharT, _Traits>> __y) noexcept
    { return __x.compare(__y) > 0; }

  template<typename _CharT, typename _Traits>
    constexpr bool
    operator> (__detail::__idt<basic_string_view<_CharT, _Traits>> __x,
               basic_string_view<_CharT, _Traits> __y) noexcept
    { return __x.compare(__y) > 0; }

  template<typename _CharT, typename _Traits>
    constexpr bool
    operator<=(basic_string_view<_CharT, _Traits> __x,
               basic_string_view<_CharT, _Traits> __y) noexcept
    { return __x.compare(__y) <= 0; }

  template<typename _CharT, typename _Traits>
    constexpr bool
    operator<=(basic_string_view<_CharT, _Traits> __x,
               __detail::__idt<basic_string_view<_CharT, _Traits>> __y) noexcept
    { return __x.compare(__y) <= 0; }

  template<typename _CharT, typename _Traits>
    constexpr bool
    operator<=(__detail::__idt<basic_string_view<_CharT, _Traits>> __x,
               basic_string_view<_CharT, _Traits> __y) noexcept
    { return __x.compare(__y) <= 0; }

  template<typename _CharT, typename _Traits>
    constexpr bool
    operator>=(basic_string_view<_CharT, _Traits> __x,
               basic_string_view<_CharT, _Traits> __y) noexcept
    { return __x.compare(__y) >= 0; }

  template<typename _CharT, typename _Traits>
    constexpr bool
    operator>=(basic_string_view<_CharT, _Traits> __x,
               __detail::__idt<basic_string_view<_CharT, _Traits>> __y) noexcept
    { return __x.compare(__y) >= 0; }

  template<typename _CharT, typename _Traits>
    constexpr bool
    operator>=(__detail::__idt<basic_string_view<_CharT, _Traits>> __x,
               basic_string_view<_CharT, _Traits> __y) noexcept
    { return __x.compare(__y) >= 0; }

  // [string.view.io], Inserters and extractors
  template<typename _CharT, typename _Traits>
    inline basic_ostream<_CharT, _Traits>&
    operator<<(basic_ostream<_CharT, _Traits>& __os,
	       basic_string_view<_CharT,_Traits> __str)
    { return __ostream_insert(__os, __str.data(), __str.size()); }


  // basic_string_view typedef names

  using string_view = basic_string_view<char>;
#ifdef _GLIBCXX_USE_WCHAR_T
  using wstring_view = basic_string_view<wchar_t>;
#endif
#ifdef _GLIBCXX_USE_C99_STDINT_TR1
  using u16string_view = basic_string_view<char16_t>;
  using u32string_view = basic_string_view<char32_t>;
#endif

  // [string.view.hash], hash support:

  template<typename _Tp>
    struct hash;

  template<>
    struct hash<string_view>
    : public __hash_base<size_t, string_view>
    {
      size_t
      operator()(const string_view& __str) const noexcept
      { return std::_Hash_impl::hash(__str.data(), __str.length()); }
    };

  template<>
    struct __is_fast_hash<hash<string_view>> : std::false_type
    { };

#ifdef _GLIBCXX_USE_WCHAR_T
  template<>
    struct hash<wstring_view>
    : public __hash_base<size_t, wstring>
    {
      size_t
      operator()(const wstring_view& __s) const noexcept
      { return std::_Hash_impl::hash(__s.data(),
                                     __s.length() * sizeof(wchar_t)); }
    };

  template<>
    struct __is_fast_hash<hash<wstring_view>> : std::false_type
    { };
#endif

#ifdef _GLIBCXX_USE_C99_STDINT_TR1
  template<>
    struct hash<u16string_view>
    : public __hash_base<size_t, u16string_view>
    {
      size_t
      operator()(const u16string_view& __s) const noexcept
      { return std::_Hash_impl::hash(__s.data(),
                                     __s.length() * sizeof(char16_t)); }
    };

  template<>
    struct __is_fast_hash<hash<u16string_view>> : std::false_type
    { };

  template<>
    struct hash<u32string_view>
    : public __hash_base<size_t, u32string_view>
    {
      size_t
      operator()(const u32string_view& __s) const noexcept
      { return std::_Hash_impl::hash(__s.data(),
                                     __s.length() * sizeof(char32_t)); }
    };

  template<>
    struct __is_fast_hash<hash<u32string_view>> : std::false_type
    { };
#endif
_GLIBCXX_END_NAMESPACE_VERSION

  inline namespace literals
  {
  inline namespace string_view_literals
  {
_GLIBCXX_BEGIN_NAMESPACE_VERSION

    inline constexpr basic_string_view<char>
    operator""sv(const char* __str, size_t __len) noexcept
    { return basic_string_view<char>{__str, __len}; }

#ifdef _GLIBCXX_USE_WCHAR_T
    inline constexpr basic_string_view<wchar_t>
    operator""sv(const wchar_t* __str, size_t __len) noexcept
    { return basic_string_view<wchar_t>{__str, __len}; }
#endif

#ifdef _GLIBCXX_USE_C99_STDINT_TR1
    inline constexpr basic_string_view<char16_t>
    operator""sv(const char16_t* __str, size_t __len) noexcept
    { return basic_string_view<char16_t>{__str, __len}; }

    inline constexpr basic_string_view<char32_t>
    operator""sv(const char32_t* __str, size_t __len) noexcept
    { return basic_string_view<char32_t>{__str, __len}; }
#endif

_GLIBCXX_END_NAMESPACE_VERSION
  } // namespace string_literals
  } // namespace literals

} // namespace std

#include <bits/string_view.tcc>

#endif // __cplusplus <= 201402L

#endif // _GLIBCXX_EXPERIMENTAL_STRING_VIEW
@


1.1.1.1
log
@import GCC 7.4.0.  main changes include:

The non-standard C++0x type traits has_trivial_default_constructor,
has_trivial_copy_constructor and has_trivial_copy_assign have been
removed.

On ARM targets (arm*-*-*), a bug introduced in GCC 5 that affects
conformance to the procedure call standard (AAPCS) has been fixed.

Many optimiser improvements

DWARF-5 support.

Many new and enhanced warnings.

Warnings about format strings now underline the pertinent part of
the string, and can offer suggested fixes.

Several new warnings related to buffer overflows and buffer
truncation.

New __builtin_add_overflow_p, __builtin_sub_overflow_p,
__builtin_mul_overflow_p built-ins added that test for overflow.

The C++ front end has experimental support for all of the current
C++17 draft.

The -fverbose-asm option has been expanded to prints comments
showing the source lines that correspond to the assembly.

The gcc and g++ driver programs will now provide suggestions for
misspelled arguments to command-line options.


AArch64 specific:

GCC has been updated to the latest revision of the procedure call
standard (AAPCS64) to provide support for parameter passing when
data types have been over-aligned.

The ARMv8.2-A and ARMv8.3-A architecture are now supported.

ARM specific:

Support for the ARMv5 and ARMv5E architectures has been
deprecated (which have no known implementations).

A new command-line option -mpure-code has been added. It does not
allow constant data to be placed in code sections.

x86 specific:

Support for the AVX-512 4FMAPS, 4VNNIW, VPOPCNTDQ and Software
Guard Extensions (SGX) ISA extensions has been added.

PPC specific:

GCC now diagnoses inline assembly that clobbers register r2.

RISC-V specific:

Support for the RISC-V instruction set has been added.

SH specific:

Support for SH5/SH64 has been removed.

Support for SH2A has been enhanced.
@
text
@@


1.1.1.2
log
@import GCC 8.3.  it includes these new features:
- many optimisations improved: inter-procedural, profile-directed,
  LTO, loops including user-controllable unroll support, and more.
- columns numbers added to line numbers in dwarf
- gcov extended significantly
- many sanitizer updates
- many new warning messages
- many better hints and more useful error messages
- minor ABI changes on x86-64 libstdc++, and some c++17 modes
- draft c++2a features
- better c++17 experimental support
- Armv8.4-A supported, better 8.2-A and 8.3-A support, including
  32 bit arm port.  cortex a-55, a-75 and a-55.a-75 combo support.
- in the GCC bugzilla, 8.1 shows 1149 bugs fixed, 8.2 shows 100, and
  8.3 shows 158.
@
text
@d3 1
a3 1
// Copyright (C) 2013-2018 Free Software Foundation, Inc.
d99 1
a99 1
      constexpr basic_string_view(const _CharT* __str) noexcept
d104 3
a106 3
      constexpr
      basic_string_view(const _CharT* __str, size_type __len) noexcept
      : _M_len{__len}, _M_str{__str}
d163 1
a163 1
      [[nodiscard]] constexpr bool
d180 7
a186 5
	if (__pos >= _M_len)
	  __throw_out_of_range_fmt(__N("basic_string_view::at: __pos "
				       "(which is %zu) >= this->size() "
				       "(which is %zu)"), __pos, this->size());
	return *(this->_M_str + __pos);
d190 1
a190 1
      front() const noexcept
d198 1
a198 1
      back() const noexcept
d212 1
a212 1
      remove_prefix(size_type __n) noexcept
d220 1
a220 1
      remove_suffix(size_type __n) noexcept
d238 9
a246 5
	__pos = _M_check(__pos, "basic_string_view::copy");
	const size_type __rlen = std::min(__n, _M_len - __pos);
	// _GLIBCXX_RESOLVE_LIB_DEFECTS
	// 2777. basic_string_view::copy should use char_traits::copy
	traits_type::copy(__str, data() + __pos, __rlen);
d250 3
d254 1
a254 1
      substr(size_type __pos = 0, size_type __n = npos) const noexcept(false)
d256 7
a262 3
	__pos = _M_check(__pos, "basic_string_view::substr");
	const size_type __rlen = std::min(__n, _M_len - __pos);
	return basic_string_view{_M_str + __pos, __rlen};
d268 2
a269 2
	const size_type __rlen = std::min(this->_M_len, __str._M_len);
	int __ret = traits_type::compare(this->_M_str, __str._M_str, __rlen);
d282 1
a282 3
      {
	return this->substr(__pos1, __n1).compare(__str.substr(__pos2, __n2));
      }
d294 1
a294 1
	      const _CharT* __str, size_type __n2) const noexcept(false)
d305 1
a305 1
      find(_CharT __c, size_type __pos = 0) const noexcept;
d311 1
a311 1
      find(const _CharT* __str, size_type __pos = 0) const noexcept
d337 1
a337 1
      find_first_of(const _CharT* __str, size_type __pos, size_type __n) const noexcept;
d353 1
a353 2
      find_last_of(const _CharT* __str, size_type __pos,
		   size_type __n) const noexcept;
d369 1
a369 1
			size_type __pos, size_type __n) const noexcept;
d388 1
a388 1
		       size_type __pos, size_type __n) const noexcept;
d399 1
a399 1
      _M_check(size_type __pos, const char* __s) const noexcept(false)
d410 1
a410 1
      _M_limit(size_type __pos, size_type __off) const noexcept
d421 5
a425 6
	const difference_type __diff = __n1 - __n2;
	if (__diff > std::numeric_limits<int>::max())
	  return std::numeric_limits<int>::max();
	if (__diff < std::numeric_limits<int>::min())
	  return std::numeric_limits<int>::min();
	return static_cast<int>(__diff);
d431 1
d437 1
d443 1
d446 2
d638 1
d644 2
a645 2
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wliteral-suffix"
d665 2
a666 1
#pragma GCC diagnostic pop
a669 1
_GLIBCXX_END_NAMESPACE_VERSION
@


1.1.1.3
log
@import GCC 7.5.0.  doing this here so that the vendor branch has
the code we'll merge into gcc.old and the netbsd-9 tree gcc tree.
GCC 8.4.0 will be imported immediately on top of this again,
restoring the current status.

these PRs in the GCC bugzilla are fixed with this update:

89869 80693 89795 84272 85593 86669 87148 87647 87895 88103 88107 88563
88870 88976 89002 89187 89195 89234 89303 89314 89354 89361 89403 89412
89512 89520 89590 89621 89663 89679 89704 89734 89872 89933 90090 90208
87075 85870 89009 89242 88167 80864 81933 85890 86608 87145 88857 89024
89119 89214 89511 89612 89705 89400 81740 82186 84552 86554 87609 88105
88149 88415 88739 88903 89135 89223 89296 89505 89572 89677 89698 89710
90006 90020 90071 90328 90474 91126 91162 91812 91887 90075 88998 89945
87047 87506 88074 88656 88740 91137 89008 84010 89349 91136 91347 91995
89397 87030 60702 78884 85594 87649 87725 88181 88470 88553 88568 88588
88620 88644 88906 88949 89246 89587 89726 89768 89796 89998 90108 90756
90950 91704 88825 88983 86538 51333 89446 90220 91308 92143 89392 90213
90278 91131 91200 91510 89037 91481 87673 88418 88938 88948 90547 27221
58321 61250 67183 67958 77583 83531 86215 88648 88720 88726 89091 89466
89629 90105 90329 90585 90760 90924 91087 89222 81956 71861 35031 69455
81849 82993 85798 88138 88155 88169 88205 88206 88228 88249 88269 88376
77703 80260 82077 86248 88393 90786 57048 66089 66695 67679 68009 71723
72714 84394 85544 87734 88298 90937 91557 63891 64132 65342 68649 68717
71066 71860 71935 77746 78421 78645 78865 78983 79485 79540 85953 88326
89651 90744
@
text
@d3 1
a3 1
// Copyright (C) 2013-2017 Free Software Foundation, Inc.
d99 1
a99 1
      constexpr basic_string_view(const _CharT* __str)
d104 3
a106 3
      constexpr basic_string_view(const _CharT* __str, size_type __len)
      : _M_len{__len},
        _M_str{__str}
d163 1
a163 1
      constexpr bool
d180 5
a184 7
	return __pos < this->_M_len
	     ? *(this->_M_str + __pos)
	     : (__throw_out_of_range_fmt(__N("basic_string_view::at: __pos "
					     "(which is %zu) >= this->size() "
					     "(which is %zu)"),
					 __pos, this->size()),
		*this->_M_str);
d188 1
a188 1
      front() const
d196 1
a196 1
      back() const
d210 1
a210 1
      remove_prefix(size_type __n)
d218 1
a218 1
      remove_suffix(size_type __n)
d236 5
a240 9
	if (__pos > this->_M_len)
	  __throw_out_of_range_fmt(__N("basic_string_view::copy: __pos "
				       "(which is %zu) > this->size() "
				       "(which is %zu)"),
				   __pos, this->size());
	size_type __rlen{std::min(__n, size_type{this->_M_len  - __pos})};
	for (auto __begin = this->_M_str + __pos,
	     __end = __begin + __rlen; __begin != __end;)
	  *__str++ = *__begin++;
a243 3

      // [string.view.ops], string operations:

d245 1
a245 1
      substr(size_type __pos, size_type __n=npos) const
d247 3
a249 7
	return __pos <= this->_M_len
	     ? basic_string_view{this->_M_str + __pos,
				std::min(__n, size_type{this->_M_len  - __pos})}
	     : (__throw_out_of_range_fmt(__N("basic_string_view::substr: __pos "
					     "(which is %zu) > this->size() "
					     "(which is %zu)"),
				     __pos, this->size()), basic_string_view{});
d255 2
a256 2
	int __ret = traits_type::compare(this->_M_str, __str._M_str,
					 std::min(this->_M_len, __str._M_len));
d269 3
a271 1
      { return this->substr(__pos1, __n1).compare(__str.substr(__pos2, __n2)); }
d283 1
a283 1
	      const _CharT* __str, size_type __n2) const
d294 1
a294 1
      find(_CharT __c, size_type __pos=0) const noexcept;
d300 1
a300 1
      find(const _CharT* __str, size_type __pos=0) const noexcept
d326 1
a326 1
      find_first_of(const _CharT* __str, size_type __pos, size_type __n) const;
d342 2
a343 1
      find_last_of(const _CharT* __str, size_type __pos, size_type __n) const;
d359 1
a359 1
			size_type __pos, size_type __n) const;
d378 1
a378 1
		       size_type __pos, size_type __n) const;
d389 1
a389 1
      _M_check(size_type __pos, const char* __s) const
d400 1
a400 1
      _M_limit(size_type __pos, size_type __off) const _GLIBCXX_NOEXCEPT
d411 6
a416 5
	return difference_type{__n1 - __n2} > std::numeric_limits<int>::max()
	     ? std::numeric_limits<int>::max()
	     : difference_type{__n1 - __n2} < std::numeric_limits<int>::min()
	     ? std::numeric_limits<int>::min()
	     : static_cast<int>(difference_type{__n1 - __n2});
a421 1
_GLIBCXX_END_NAMESPACE_VERSION
a426 1
_GLIBCXX_BEGIN_NAMESPACE_VERSION
a431 1
_GLIBCXX_END_NAMESPACE_VERSION
a433 2
_GLIBCXX_BEGIN_NAMESPACE_VERSION

a623 1
_GLIBCXX_END_NAMESPACE_VERSION
d629 2
a630 2
_GLIBCXX_BEGIN_NAMESPACE_VERSION

d650 1
a650 2

_GLIBCXX_END_NAMESPACE_VERSION
d654 1
@


1.1.1.4
log
@re-import GCC 8.4.0.
@
text
@d3 1
a3 1
// Copyright (C) 2013-2018 Free Software Foundation, Inc.
d99 1
a99 1
      constexpr basic_string_view(const _CharT* __str) noexcept
d104 3
a106 3
      constexpr
      basic_string_view(const _CharT* __str, size_type __len) noexcept
      : _M_len{__len}, _M_str{__str}
d163 1
a163 1
      [[nodiscard]] constexpr bool
d180 7
a186 5
	if (__pos >= _M_len)
	  __throw_out_of_range_fmt(__N("basic_string_view::at: __pos "
				       "(which is %zu) >= this->size() "
				       "(which is %zu)"), __pos, this->size());
	return *(this->_M_str + __pos);
d190 1
a190 1
      front() const noexcept
d198 1
a198 1
      back() const noexcept
d212 1
a212 1
      remove_prefix(size_type __n) noexcept
d220 1
a220 1
      remove_suffix(size_type __n) noexcept
d238 9
a246 5
	__pos = _M_check(__pos, "basic_string_view::copy");
	const size_type __rlen = std::min(__n, _M_len - __pos);
	// _GLIBCXX_RESOLVE_LIB_DEFECTS
	// 2777. basic_string_view::copy should use char_traits::copy
	traits_type::copy(__str, data() + __pos, __rlen);
d250 3
d254 1
a254 1
      substr(size_type __pos = 0, size_type __n = npos) const noexcept(false)
d256 7
a262 3
	__pos = _M_check(__pos, "basic_string_view::substr");
	const size_type __rlen = std::min(__n, _M_len - __pos);
	return basic_string_view{_M_str + __pos, __rlen};
d268 2
a269 2
	const size_type __rlen = std::min(this->_M_len, __str._M_len);
	int __ret = traits_type::compare(this->_M_str, __str._M_str, __rlen);
d282 1
a282 3
      {
	return this->substr(__pos1, __n1).compare(__str.substr(__pos2, __n2));
      }
d294 1
a294 1
	      const _CharT* __str, size_type __n2) const noexcept(false)
d305 1
a305 1
      find(_CharT __c, size_type __pos = 0) const noexcept;
d311 1
a311 1
      find(const _CharT* __str, size_type __pos = 0) const noexcept
d337 1
a337 1
      find_first_of(const _CharT* __str, size_type __pos, size_type __n) const noexcept;
d353 1
a353 2
      find_last_of(const _CharT* __str, size_type __pos,
		   size_type __n) const noexcept;
d369 1
a369 1
			size_type __pos, size_type __n) const noexcept;
d388 1
a388 1
		       size_type __pos, size_type __n) const noexcept;
d399 1
a399 1
      _M_check(size_type __pos, const char* __s) const noexcept(false)
d410 1
a410 1
      _M_limit(size_type __pos, size_type __off) const noexcept
d421 5
a425 6
	const difference_type __diff = __n1 - __n2;
	if (__diff > std::numeric_limits<int>::max())
	  return std::numeric_limits<int>::max();
	if (__diff < std::numeric_limits<int>::min())
	  return std::numeric_limits<int>::min();
	return static_cast<int>(__diff);
d431 1
d437 1
d443 1
d446 2
d638 1
d644 2
a645 2
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wliteral-suffix"
d665 2
a666 1
#pragma GCC diagnostic pop
a669 1
_GLIBCXX_END_NAMESPACE_VERSION
@


1.1.1.5
log
@initial import of GCC 9.3.0.  changes include:

- live patching support
- shell completion help
- generally better diagnostic output (less verbose/more useful)
- diagnostics and optimisation choices can be emitted in json
- asan memory usage reduction
- many general, and specific to switch, inter-procedure,
  profile and link-time optimisations.  from the release notes:
  "Overall compile time of Firefox 66 and LibreOffice 6.2.3 on
  an 8-core machine was reduced by about 5% compared to GCC 8.3"
- OpenMP 5.0 support
- better spell-guesser
- partial experimental support for c2x and c++2a
- c++17 is no longer experimental
- arm AAPCS GCC 6-8 structure passing bug fixed, may cause
  incompatibility (restored compat with GCC 5 and earlier.)
- openrisc support
@
text
@d3 1
a3 1
// Copyright (C) 2013-2019 Free Software Foundation, Inc.
a51 19
  // Helper for basic_string and basic_string_view members.
  constexpr size_t
  __sv_check(size_t __size, size_t __pos, const char* __s)
  {
    if (__pos > __size)
      __throw_out_of_range_fmt(__N("%s: __pos (which is %zu) > __size "
				   "(which is %zu)"), __s, __pos, __size);
    return __pos;
  }

  // Helper for basic_string members.
  // NB: __sv_limit doesn't check for a bad __pos value.
  constexpr size_t
  __sv_limit(size_t __size, size_t __pos, size_t __off) noexcept
  {
   const bool __testoff =  __off < __size - __pos;
   return __testoff ? __off : __size - __pos;
  }

a72 4
      static_assert(!is_array_v<_CharT>);
      static_assert(is_trivial_v<_CharT> && is_standard_layout_v<_CharT>);
      static_assert(is_same_v<_CharT, typename _Traits::char_type>);

d76 8
a83 8
      using traits_type		= _Traits;
      using value_type		= _CharT;
      using pointer		= value_type*;
      using const_pointer	= const value_type*;
      using reference		= value_type&;
      using const_reference	= const value_type&;
      using const_iterator	= const value_type*;
      using iterator		= const_iterator;
d85 3
a87 3
      using reverse_iterator	= const_reverse_iterator;
      using size_type		= size_t;
      using difference_type	= ptrdiff_t;
d90 1
a90 1
      // [string.view.cons], construction and assignment
d99 2
a100 3
      __attribute__((__nonnull__)) constexpr
      basic_string_view(const _CharT* __str) noexcept
      : _M_len{traits_type::length(__str)},
d112 1
a112 1
      // [string.view.iterators], iterator support
d169 1
a169 1
      constexpr const_reference
d177 1
a177 1
      constexpr const_reference
d187 1
a187 1
      constexpr const_reference
d195 1
a195 1
      constexpr const_reference
d203 1
a203 1
      constexpr const_pointer
d229 1
d236 1
a236 1
	__pos = std::__sv_check(size(), __pos, "basic_string_view::copy");
d247 1
a247 1
	__pos = std::__sv_check(size(), __pos, "basic_string_view::substr");
d273 1
a273 1
      __attribute__((__nonnull__)) constexpr int
d277 1
a277 1
      __attribute__((__nonnull__)) constexpr int
a288 31
#if __cplusplus > 201703L
      constexpr bool
      starts_with(basic_string_view __x) const noexcept
      { return this->substr(0, __x.size()) == __x; }

      constexpr bool
      starts_with(_CharT __x) const noexcept
      { return !this->empty() && traits_type::eq(this->front(), __x); }

      constexpr bool
      starts_with(const _CharT* __x) const noexcept
      { return this->starts_with(basic_string_view(__x)); }

      constexpr bool
      ends_with(basic_string_view __x) const noexcept
      {
	return this->size() >= __x.size()
	    && this->compare(this->size() - __x.size(), npos, __x) == 0;
      }

      constexpr bool
      ends_with(_CharT __x) const noexcept
      { return !this->empty() && traits_type::eq(this->back(), __x); }

      constexpr bool
      ends_with(const _CharT* __x) const noexcept
      { return this->ends_with(basic_string_view(__x)); }
#endif // C++20

      // [string.view.find], searching

d299 1
a299 1
      __attribute__((__nonnull__)) constexpr size_type
d313 1
a313 1
      __attribute__((__nonnull__)) constexpr size_type
d326 1
a326 2
      find_first_of(const _CharT* __str, size_type __pos,
		    size_type __n) const noexcept;
d328 1
a328 1
      __attribute__((__nonnull__)) constexpr size_type
d345 1
a345 1
      __attribute__((__nonnull__)) constexpr size_type
d361 1
a361 1
      __attribute__((__nonnull__)) constexpr size_type
d380 1
a380 1
      __attribute__((__nonnull__)) constexpr size_type
d388 18
d556 1
a556 3
#ifdef _GLIBCXX_USE_CHAR8_T
  using u8string_view = basic_string_view<char8_t>;
#endif
d559 1
d582 1
a582 1
    : public __hash_base<size_t, wstring_view>
d595 1
a595 15
#ifdef _GLIBCXX_USE_CHAR8_T
  template<>
    struct hash<u8string_view>
    : public __hash_base<size_t, u8string_view>
    {
      size_t
      operator()(const u8string_view& __str) const noexcept
      { return std::_Hash_impl::hash(__str.data(), __str.length()); }
    };

  template<>
    struct __is_fast_hash<hash<u8string_view>> : std::false_type
    { };
#endif

d623 1
d641 1
a641 6
#ifdef _GLIBCXX_USE_CHAR8_T
    inline constexpr basic_string_view<char8_t>
    operator""sv(const char8_t* __str, size_t __len) noexcept
    { return basic_string_view<char8_t>{__str, __len}; }
#endif

d649 1
a649 1

@


1.1.1.6
log
@initial import of GCC 10.3.0.  main changes include:

caveats:
- ABI issue between c++14 and c++17 fixed
- profile mode is removed from libstdc++
- -fno-common is now the default

new features:
- new flags -fallocation-dce, -fprofile-partial-training,
  -fprofile-reproducible, -fprofile-prefix-path, and -fanalyzer
- many new compile and link time optimisations
- enhanced drive optimisations
- openacc 2.6 support
- openmp 5.0 features
- new warnings: -Wstring-compare and -Wzero-length-bounds
- extended warnings: -Warray-bounds, -Wformat-overflow,
  -Wrestrict, -Wreturn-local-addr, -Wstringop-overflow,
  -Warith-conversion, -Wmismatched-tags, and -Wredundant-tags
- some likely C2X features implemented
- more C++20 implemented
- many new arm & intel CPUs known

hundreds of reported bugs are fixed.  full list of changes
can be found at:

   https://gcc.gnu.org/gcc-10/changes.html
@
text
@d3 1
a3 1
// Copyright (C) 2013-2020 Free Software Foundation, Inc.
d40 1
a44 2
#include <bits/ostream_insert.h>
#include <ext/numeric_traits.h>
d50 1
a50 4
# define __cpp_lib_string_view 201803L
#if __cplusplus > 201703L
# define __cpp_lib_constexpr_string_view 201811L
#endif
a132 10
#if __cplusplus > 201703L && __cpp_lib_concepts
      template<contiguous_iterator _It, sized_sentinel_for<_It> _End>
	requires same_as<iter_value_t<_It>, _CharT>
	  && (!convertible_to<_End, size_type>)
	constexpr
	basic_string_view(_It __first, _End __last)
	: _M_len(__last - __first), _M_str(std::to_address(__first))
	{ }
#endif

d196 2
a197 1
	__glibcxx_assert(__pos < this->_M_len);
d214 2
a215 1
	__glibcxx_assert(this->_M_len > 0);
d222 2
a223 1
	__glibcxx_assert(this->_M_len > 0);
a254 1
      _GLIBCXX20_CONSTEXPR
a312 1
#define __cpp_lib_starts_ends_with 201711L
d449 4
a452 4
	if (__diff > __gnu_cxx::__int_traits<int>::__max)
	  return __gnu_cxx::__int_traits<int>::__max;
	if (__diff < __gnu_cxx::__int_traits<int>::__min)
	  return __gnu_cxx::__int_traits<int>::__min;
a459 5
#if __cplusplus > 201703L && __cpp_lib_concepts && __cpp_deduction_guides
  template<contiguous_iterator _It, sized_sentinel_for<_It> _End>
    basic_string_view(_It, _End) -> basic_string_view<iter_value_t<_It>>;
#endif

d462 8
a469 4
  // Several of these functions use type_identity_t to create a non-deduced
  // context, so that only one argument participates in template argument
  // deduction and the other argument gets implicitly converted to the deduced
  // type (see N3766).
d480 1
a480 2
               __type_identity_t<basic_string_view<_CharT, _Traits>> __y)
    noexcept
a482 16
#if __cpp_lib_three_way_comparison
  template<typename _CharT, typename _Traits>
    constexpr auto
    operator<=>(basic_string_view<_CharT, _Traits> __x,
		basic_string_view<_CharT, _Traits> __y) noexcept
    -> decltype(__detail::__char_traits_cmp_cat<_Traits>(0))
    { return __detail::__char_traits_cmp_cat<_Traits>(__x.compare(__y)); }

  template<typename _CharT, typename _Traits>
    constexpr auto
    operator<=>(basic_string_view<_CharT, _Traits> __x,
		__type_identity_t<basic_string_view<_CharT, _Traits>> __y)
    noexcept
    -> decltype(__detail::__char_traits_cmp_cat<_Traits>(0))
    { return __detail::__char_traits_cmp_cat<_Traits>(__x.compare(__y)); }
#else
d485 1
a485 1
    operator==(__type_identity_t<basic_string_view<_CharT, _Traits>> __x,
d498 1
a498 2
               __type_identity_t<basic_string_view<_CharT, _Traits>> __y)
    noexcept
d503 1
a503 1
    operator!=(__type_identity_t<basic_string_view<_CharT, _Traits>> __x,
d516 1
a516 2
               __type_identity_t<basic_string_view<_CharT, _Traits>> __y)
    noexcept
d521 1
a521 1
    operator< (__type_identity_t<basic_string_view<_CharT, _Traits>> __x,
d534 1
a534 2
               __type_identity_t<basic_string_view<_CharT, _Traits>> __y)
    noexcept
d539 1
a539 1
    operator> (__type_identity_t<basic_string_view<_CharT, _Traits>> __x,
d552 1
a552 2
               __type_identity_t<basic_string_view<_CharT, _Traits>> __y)
    noexcept
d557 1
a557 1
    operator<=(__type_identity_t<basic_string_view<_CharT, _Traits>> __x,
d570 1
a570 2
               __type_identity_t<basic_string_view<_CharT, _Traits>> __y)
    noexcept
d575 1
a575 1
    operator>=(__type_identity_t<basic_string_view<_CharT, _Traits>> __x,
a577 1
#endif // three-way comparison
a709 14
#if __cpp_lib_concepts
  namespace ranges
  {
    // Opt-in to borrowed_range concept
    template<typename _CharT, typename _Traits>
      inline constexpr bool
	enable_borrowed_range<basic_string_view<_CharT, _Traits>> = true;

    // Opt-in to view concept
    template<typename _CharT, typename _Traits>
      inline constexpr bool
	enable_view<basic_string_view<_CharT, _Traits>> = true;
  }
#endif
@


1.1.1.7
log
@initial import of GCC 10.4.0 sources.

mostly a large list of PRs fixed (210 total), plus one x86-64
specific change related to MMX and 64 bit integer return.

https://gcc.gnu.org/gcc-10/changes.html links to the full list
of PRs fixed.
@
text
@d25 1
a25 1
/** @@file include/string_view
d341 2
a342 4
	const auto __len = this->size();
	const auto __xlen = __x.size();
	return __len >= __xlen
	  && traits_type::compare(end() - __xlen, __x.data(), __xlen) == 0;
@


1.1.1.8
log
@initial import of GCC 12.3.0.

major changes in GCC 11 included:

- The default mode for C++ is now -std=gnu++17 instead of -std=gnu++14.
- When building GCC itself, the host compiler must now support C++11,
  rather than C++98.
- Some short options of the gcov tool have been renamed: -i to -j and
  -j to -H.
- ThreadSanitizer improvements.
- Introduce Hardware-assisted AddressSanitizer support.
- For targets that produce DWARF debugging information GCC now defaults
  to DWARF version 5. This can produce up to 25% more compact debug
  information compared to earlier versions.
- Many optimisations.
- The existing malloc attribute has been extended so that it can be
  used to identify allocator/deallocator API pairs. A pair of new
  -Wmismatched-dealloc and -Wmismatched-new-delete warnings are added.
- Other new warnings:
  -Wsizeof-array-div, enabled by -Wall, warns about divisions of two
    sizeof operators when the first one is applied to an array and the
    divisor does not equal the size of the array element.
  -Wstringop-overread, enabled by default, warns about calls to string
    functions reading past the end of the arrays passed to them as
    arguments.
  -Wtsan, enabled by default, warns about unsupported features in
    ThreadSanitizer (currently std::atomic_thread_fence).
- Enchanced warnings:
  -Wfree-nonheap-object detects many more instances of calls to
    deallocation functions with pointers not returned from a dynamic
    memory allocation function.
  -Wmaybe-uninitialized diagnoses passing pointers or references to
    uninitialized memory to functions taking const-qualified arguments.
  -Wuninitialized detects reads from uninitialized dynamically
    allocated memory.
  -Warray-parameter warns about functions with inconsistent array forms.
  -Wvla-parameter warns about functions with inconsistent VLA forms.
- Several new features from the upcoming C2X revision of the ISO C
  standard are supported with -std=c2x and -std=gnu2x.
- Several C++20 features have been implemented.
- The C++ front end has experimental support for some of the upcoming
  C++23 draft.
- Several new C++ warnings.
- Enhanced Arm, AArch64, x86, and RISC-V CPU support.
- The implementation of how program state is tracked within
  -fanalyzer has been completely rewritten with many enhancements.

see https://gcc.gnu.org/gcc-11/changes.html for a full list.

major changes in GCC 12 include:

- An ABI incompatibility between C and C++ when passing or returning
  by value certain aggregates containing zero width bit-fields has
  been discovered on various targets. x86-64, ARM and AArch64
  will always ignore them (so there is a C ABI incompatibility
  between GCC 11 and earlier with GCC 12 or later), PowerPC64 ELFv2
  always take them into account (so there is a C++ ABI
  incompatibility, GCC 4.4 and earlier compatible with GCC 12 or
  later, incompatible with GCC 4.5 through GCC 11). RISC-V has
  changed the handling of these already starting with GCC 10. As
  the ABI requires, MIPS takes them into account handling function
  return values so there is a C++ ABI incompatibility with GCC 4.5
  through 11.
- STABS: Support for emitting the STABS debugging format is
  deprecated and will be removed in the next release. All ports now
  default to emit DWARF (version 2 or later) debugging info or are
  obsoleted.
- Vectorization is enabled at -O2 which is now equivalent to the
  original -O2 -ftree-vectorize -fvect-cost-model=very-cheap.
- GCC now supports the ShadowCallStack sanitizer.
- Support for __builtin_shufflevector compatible with the clang
  language extension was added.
- Support for attribute unavailable was added.
- Support for __builtin_dynamic_object_size compatible with the
  clang language extension was added.
- New warnings:
  -Wbidi-chars warns about potentially misleading UTF-8
    bidirectional control characters.
  -Warray-compare warns about comparisons between two operands of
    array type.
- Some new features from the upcoming C2X revision of the ISO C
  standard are supported with -std=c2x and -std=gnu2x.
- Several C++23 features have been implemented.
- Many C++ enhancements across warnings and -f options.

see https://gcc.gnu.org/gcc-12/changes.html for a full list.
@
text
@d3 1
a3 1
// Copyright (C) 2013-2022 Free Software Foundation, Inc.
a41 1
#include <bits/functexcept.h>
a44 1
#include <bits/stl_algobase.h>
a46 4
#if __cplusplus >= 202002L
# include <bits/ranges_base.h>
#endif

d137 1
a137 1
#if __cplusplus >= 202002L && __cpp_lib_concepts
a142 1
	noexcept(noexcept(__last - __first))
d145 1
a145 23

#if __cplusplus > 202002L
      template<typename _Range, typename _DRange = remove_cvref_t<_Range>>
	requires (!is_same_v<_DRange, basic_string_view>)
	  && ranges::contiguous_range<_Range>
	  && ranges::sized_range<_Range>
	  && is_same_v<ranges::range_value_t<_Range>, _CharT>
	  && (!is_convertible_v<_Range, const _CharT*>)
	  && (!requires (_DRange& __d) {
		__d.operator ::std::basic_string_view<_CharT, _Traits>();
	      })
	  && (!requires { typename _DRange::traits_type; }
	      || is_same_v<typename _DRange::traits_type, _Traits>)
	constexpr explicit
	basic_string_view(_Range&& __r)
	noexcept(noexcept(ranges::size(__r)) && noexcept(ranges::data(__r)))
	: _M_len(ranges::size(__r)), _M_str(ranges::data(__r))
	{ }

      basic_string_view(nullptr_t) = delete;
#endif // C++23
#endif // C++20

a355 15
#if __cplusplus > 202002L
#define __cpp_lib_string_contains 202011L
      constexpr bool
      contains(basic_string_view __x) const noexcept
      { return this->find(__x) != npos; }

      constexpr bool
      contains(_CharT __x) const noexcept
      { return this->find(__x) != npos; }

      constexpr bool
      contains(const _CharT* __x) const noexcept
      { return this->find(__x) != npos; }
#endif // C++23

a462 1
	using __limits = __gnu_cxx::__int_traits<int>;
d464 4
a467 4
	if (__diff > __limits::__max)
	  return __limits::__max;
	if (__diff < __limits::__min)
	  return __limits::__min;
a477 6

#if __cplusplus > 202002L
  template<ranges::contiguous_range _Range>
    basic_string_view(_Range&&)
      -> basic_string_view<ranges::range_value_t<_Range>>;
#endif
d629 1
d631 1
d656 1
d670 1
d725 1
d729 1
@


1.1.1.8.2.1
log
@Sync with HEAD.
@
text
@d163 2
d283 1
a283 4
      {
	__glibcxx_assert(this->_M_len >= __n);
	this->_M_len -= __n;
      }
@


1.1.1.8.2.2
log
@Sync with HEAD
@
text
@d302 1
a302 1
	const size_type __rlen = std::min<size_t>(__n, _M_len - __pos);
d313 1
a313 1
	const size_type __rlen = std::min<size_t>(__n, _M_len - __pos);
@


1.1.1.9
log
@import GCC 12.4.0.

this includes at least 85 GCC PRs fixed, 2 C, 17 C++, 16 libstdc++-v3,
at least 13 target-specific (x86, arm64, riscv mostly), and at least
24 optimisation PRs.
@
text
@d163 2
d283 1
a283 4
      {
	__glibcxx_assert(this->_M_len >= __n);
	this->_M_len -= __n;
      }
@


1.1.1.10
log
@initial import of GCC 12.5.0.

this is the final GCC 12 release, and fixes at least 241 specific bugs
in the GCC bugzilla:

   https://gcc.gnu.org/bugzilla/buglist.cgi?bug_status=RESOLVED&resolution=FIXED&target_milestone=12.5

though many are in components we don't ship in base (ada, fortran, etc.)
@
text
@d302 1
a302 1
	const size_type __rlen = std::min<size_t>(__n, _M_len - __pos);
d313 1
a313 1
	const size_type __rlen = std::min<size_t>(__n, _M_len - __pos);
@


1.1.1.11
log
@initial import of GCC 14.3.0.

major changes in GCC 13:
- improved sanitizer
- zstd debug info compression
- LTO improvements
- SARIF based diagnostic support
- new warnings: -Wxor-used-as-pow, -Wenum-int-mismatch, -Wself-move,
  -Wdangling-reference
- many new -Wanalyzer* specific warnings
- enhanced warnings: -Wpessimizing-move, -Wredundant-move
- new attributes to mark file descriptors, c++23 "assume"
- several C23 features added
- several C++23 features added
- many new features for Arm, x86, RISC-V

major changes in GCC 14:
- more strict C99 or newer support
- ia64* marked deprecated (but seemingly still in GCC 15.)
- several new hardening features
- support for "hardbool", which can have user supplied values of true/false
- explicit support for stack scrubbing upon function exit
- better auto-vectorisation support
- added clang-compatible __has_feature and __has_extension
- more C23, including -std=c23
- several C++26 features added
- better diagnostics in C++ templates
- new warnings: -Wnrvo, Welaborated-enum-base
- many new features for Arm, x86, RISC-V
- possible ABI breaking change for SPARC64 and small structures with arrays
  of floats.
@
text
@d3 1
a3 1
// Copyright (C) 2013-2024 Free Software Foundation, Inc.
a37 8
#define __glibcxx_want_constexpr_char_traits
#define __glibcxx_want_constexpr_string_view
#define __glibcxx_want_freestanding_string_view
#define __glibcxx_want_string_view
#define __glibcxx_want_starts_ends_with
#define __glibcxx_want_string_contains
#include <bits/version.h>

d40 1
d45 1
a52 5
#if _GLIBCXX_HOSTED
# include <iosfwd>
# include <bits/ostream_insert.h>
#endif

d57 5
d132 1
a132 2
      [[__gnu__::__nonnull__]]
      constexpr
d173 1
a178 1
      [[nodiscard]]
a182 1
      [[nodiscard]]
a186 1
      [[nodiscard]]
a190 1
      [[nodiscard]]
a194 1
      [[nodiscard]]
a198 1
      [[nodiscard]]
a202 1
      [[nodiscard]]
a206 1
      [[nodiscard]]
a212 1
      [[nodiscard]]
a216 1
      [[nodiscard]]
a220 1
      [[nodiscard]]
d228 1
a228 2
      [[nodiscard]]
      constexpr bool
a233 1
      [[nodiscard]]
a240 1
      [[nodiscard]]
a250 1
      [[nodiscard]]
a257 1
      [[nodiscard]]
a264 1
      [[nodiscard]]
a308 1
      [[nodiscard]]
a316 1
      [[nodiscard]]
a326 1
      [[nodiscard]]
a330 1
      [[nodiscard]]
d338 1
a338 2
      [[nodiscard, __gnu__::__nonnull__]]
      constexpr int
d342 1
a342 2
      [[nodiscard, __gnu__::__nonnull__]]
      constexpr int
a345 1
      [[nodiscard]]
d354 2
a355 2
#ifdef __cpp_lib_starts_ends_with // C++ >= 20
      [[nodiscard]]
d358 1
a358 4
      {
	return _M_len >= __x._M_len
	  && traits_type::compare(_M_str, __x._M_str, __x._M_len) == 0;
      }
a359 1
      [[nodiscard]]
a363 1
      [[nodiscard, __gnu__::__nonnull__]]
a367 1
      [[nodiscard]]
a376 1
      [[nodiscard]]
a380 1
      [[nodiscard, __gnu__::__nonnull__]]
d384 1
a384 1
#endif // __cpp_lib_starts_ends_with
d387 1
a387 6
#if _GLIBCXX_HOSTED && !defined(__cpp_lib_string_contains)
      // This FTM is not freestanding as it also implies matching <string>
      // support, and <string> is omitted from the freestanding subset.
# error "libstdc++ bug: string_contains not defined when it should be"
#endif // HOSTED
      [[nodiscard]]
a391 1
      [[nodiscard]]
a395 1
      [[nodiscard, __gnu__::__nonnull__]]
a402 1
      [[nodiscard]]
a406 1
      [[nodiscard]]
a409 1
      [[nodiscard]]
d413 1
a413 2
      [[nodiscard, __gnu__::__nonnull__]]
      constexpr size_type
a416 1
      [[nodiscard]]
a420 1
      [[nodiscard]]
a423 1
      [[nodiscard]]
d427 1
a427 2
      [[nodiscard, __gnu__::__nonnull__]]
      constexpr size_type
a430 1
      [[nodiscard]]
a434 1
      [[nodiscard]]
a438 1
      [[nodiscard]]
d443 1
a443 2
      [[nodiscard, __gnu__::__nonnull__]]
      constexpr size_type
a446 1
      [[nodiscard]]
a451 1
      [[nodiscard]]
a455 1
      [[nodiscard]]
d460 1
a460 2
      [[nodiscard, __gnu__::__nonnull__]]
      constexpr size_type
a463 1
      [[nodiscard]]
a468 1
      [[nodiscard]]
a471 1
      [[nodiscard]]
d476 1
a476 2
      [[nodiscard, __gnu__::__nonnull__]]
      constexpr size_type
a482 1
      [[nodiscard]]
a487 1
      [[nodiscard]]
a490 1
      [[nodiscard]]
d495 1
a495 2
      [[nodiscard, __gnu__::__nonnull__]]
      constexpr size_type
a538 1
#if __cpp_lib_three_way_comparison
a539 1
    [[nodiscard]]
d542 7
a548 1
	       type_identity_t<basic_string_view<_CharT, _Traits>> __y)
d552 8
a560 1
    [[nodiscard]]
a568 16
    [[nodiscard]]
    constexpr bool
    operator==(basic_string_view<_CharT, _Traits> __x,
	       __type_identity_t<basic_string_view<_CharT, _Traits>> __y)
    noexcept
    { return __x.size() == __y.size() && __x.compare(__y) == 0; }

  template<typename _CharT, typename _Traits>
    [[nodiscard]]
    constexpr bool
    operator==(basic_string_view<_CharT, _Traits> __x,
	       basic_string_view<_CharT, _Traits> __y) noexcept
    { return __x.size() == __y.size() && __x.compare(__y) == 0; }

  template<typename _CharT, typename _Traits>
    [[nodiscard]]
a574 1
    [[nodiscard]]
a580 1
    [[nodiscard]]
a587 1
    [[nodiscard]]
a593 1
    [[nodiscard]]
a599 1
    [[nodiscard]]
a606 1
    [[nodiscard]]
a612 1
    [[nodiscard]]
a618 1
    [[nodiscard]]
a625 1
    [[nodiscard]]
a631 1
    [[nodiscard]]
a637 1
    [[nodiscard]]
a644 1
    [[nodiscard]]
a650 1
    [[nodiscard]]
a656 1
    [[nodiscard]]
a663 1
    [[nodiscard]]
a669 1
#if _GLIBCXX_HOSTED
d676 1
a676 1
#endif // HOSTED
a696 1
      [[nodiscard]]
a709 1
      [[nodiscard]]
a724 1
      [[nodiscard]]
a738 1
      [[nodiscard]]
a752 1
      [[nodiscard]]
@


1.1.1.1.4.1
log
@file string_view was added on branch phil-wifi on 2019-06-10 21:54:58 +0000
@
text
@d1 676
@


1.1.1.1.4.2
log
@Sync with HEAD
@
text
@a0 676
// Components for manipulating non-owning sequences of characters -*- C++ -*-

// Copyright (C) 2013-2017 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library.  This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.

// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// Under Section 7 of GPL version 3, you are granted additional
// permissions described in the GCC Runtime Library Exception, version
// 3.1, as published by the Free Software Foundation.

// You should have received a copy of the GNU General Public License and
// a copy of the GCC Runtime Library Exception along with this program;
// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
// <http://www.gnu.org/licenses/>.

/** @@file string_view
 *  This is a Standard C++ Library header.
 */

//
// N3762 basic_string_view library
//

#ifndef _GLIBCXX_STRING_VIEW
#define _GLIBCXX_STRING_VIEW 1

#pragma GCC system_header

#if __cplusplus >= 201703L

#include <limits>
#include <iosfwd>
#include <bits/char_traits.h>
#include <bits/functional_hash.h>
#include <bits/range_access.h>

namespace std _GLIBCXX_VISIBILITY(default)
{
_GLIBCXX_BEGIN_NAMESPACE_VERSION

#define __cpp_lib_string_view 201603

  /**
   *  @@class basic_string_view <string_view>
   *  @@brief  A non-owning reference to a string.
   *
   *  @@ingroup strings
   *  @@ingroup sequences
   *
   *  @@tparam _CharT  Type of character
   *  @@tparam _Traits  Traits for character type, defaults to
   *                   char_traits<_CharT>.
   *
   *  A basic_string_view looks like this:
   *
   *  @@code
   *    _CharT*    _M_str
   *    size_t     _M_len
   *  @@endcode
   */
  template<typename _CharT, typename _Traits = std::char_traits<_CharT>>
    class basic_string_view
    {
    public:

      // types
      using traits_type = _Traits;
      using value_type = _CharT;
      using pointer = const _CharT*;
      using const_pointer = const _CharT*;
      using reference = const _CharT&;
      using const_reference = const _CharT&;
      using const_iterator = const _CharT*;
      using iterator = const_iterator;
      using const_reverse_iterator = std::reverse_iterator<const_iterator>;
      using reverse_iterator = const_reverse_iterator;
      using size_type = size_t;
      using difference_type = ptrdiff_t;
      static constexpr size_type npos = size_type(-1);

      // [string.view.cons], construct/copy

      constexpr
      basic_string_view() noexcept
      : _M_len{0}, _M_str{nullptr}
      { }

      constexpr basic_string_view(const basic_string_view&) noexcept = default;

      constexpr basic_string_view(const _CharT* __str)
      : _M_len{__str == nullptr ? 0 : traits_type::length(__str)},
	_M_str{__str}
      { }

      constexpr basic_string_view(const _CharT* __str, size_type __len)
      : _M_len{__len},
        _M_str{__str}
      { }

      constexpr basic_string_view&
      operator=(const basic_string_view&) noexcept = default;

      // [string.view.iterators], iterators

      constexpr const_iterator
      begin() const noexcept
      { return this->_M_str; }

      constexpr const_iterator
      end() const noexcept
      { return this->_M_str + this->_M_len; }

      constexpr const_iterator
      cbegin() const noexcept
      { return this->_M_str; }

      constexpr const_iterator
      cend() const noexcept
      { return this->_M_str + this->_M_len; }

      constexpr const_reverse_iterator
      rbegin() const noexcept
      { return const_reverse_iterator(this->end()); }

      constexpr const_reverse_iterator
      rend() const noexcept
      { return const_reverse_iterator(this->begin()); }

      constexpr const_reverse_iterator
      crbegin() const noexcept
      { return const_reverse_iterator(this->end()); }

      constexpr const_reverse_iterator
      crend() const noexcept
      { return const_reverse_iterator(this->begin()); }

      // [string.view.capacity], capacity

      constexpr size_type
      size() const noexcept
      { return this->_M_len; }

      constexpr size_type
      length() const noexcept
      { return _M_len; }

      constexpr size_type
      max_size() const noexcept
      {
	return (npos - sizeof(size_type) - sizeof(void*))
		/ sizeof(value_type) / 4;
      }

      constexpr bool
      empty() const noexcept
      { return this->_M_len == 0; }

      // [string.view.access], element access

      constexpr const _CharT&
      operator[](size_type __pos) const noexcept
      {
	// TODO: Assert to restore in a way compatible with the constexpr.
	// __glibcxx_assert(__pos < this->_M_len);
	return *(this->_M_str + __pos);
      }

      constexpr const _CharT&
      at(size_type __pos) const
      {
	return __pos < this->_M_len
	     ? *(this->_M_str + __pos)
	     : (__throw_out_of_range_fmt(__N("basic_string_view::at: __pos "
					     "(which is %zu) >= this->size() "
					     "(which is %zu)"),
					 __pos, this->size()),
		*this->_M_str);
      }

      constexpr const _CharT&
      front() const
      {
	// TODO: Assert to restore in a way compatible with the constexpr.
	// __glibcxx_assert(this->_M_len > 0);
	return *this->_M_str;
      }

      constexpr const _CharT&
      back() const
      {
	// TODO: Assert to restore in a way compatible with the constexpr.
	// __glibcxx_assert(this->_M_len > 0);
	return *(this->_M_str + this->_M_len - 1);
      }

      constexpr const _CharT*
      data() const noexcept
      { return this->_M_str; }

      // [string.view.modifiers], modifiers:

      constexpr void
      remove_prefix(size_type __n)
      {
	__glibcxx_assert(this->_M_len >= __n);
	this->_M_str += __n;
	this->_M_len -= __n;
      }

      constexpr void
      remove_suffix(size_type __n)
      { this->_M_len -= __n; }

      constexpr void
      swap(basic_string_view& __sv) noexcept
      {
	auto __tmp = *this;
	*this = __sv;
	__sv = __tmp;
      }


      // [string.view.ops], string operations:

      size_type
      copy(_CharT* __str, size_type __n, size_type __pos = 0) const
      {
	__glibcxx_requires_string_len(__str, __n);
	if (__pos > this->_M_len)
	  __throw_out_of_range_fmt(__N("basic_string_view::copy: __pos "
				       "(which is %zu) > this->size() "
				       "(which is %zu)"),
				   __pos, this->size());
	size_type __rlen{std::min(__n, size_type{this->_M_len  - __pos})};
	for (auto __begin = this->_M_str + __pos,
	     __end = __begin + __rlen; __begin != __end;)
	  *__str++ = *__begin++;
	return __rlen;
      }


      // [string.view.ops], string operations:

      constexpr basic_string_view
      substr(size_type __pos, size_type __n=npos) const
      {
	return __pos <= this->_M_len
	     ? basic_string_view{this->_M_str + __pos,
				std::min(__n, size_type{this->_M_len  - __pos})}
	     : (__throw_out_of_range_fmt(__N("basic_string_view::substr: __pos "
					     "(which is %zu) > this->size() "
					     "(which is %zu)"),
				     __pos, this->size()), basic_string_view{});
      }

      constexpr int
      compare(basic_string_view __str) const noexcept
      {
	int __ret = traits_type::compare(this->_M_str, __str._M_str,
					 std::min(this->_M_len, __str._M_len));
	if (__ret == 0)
	  __ret = _S_compare(this->_M_len, __str._M_len);
	return __ret;
      }

      constexpr int
      compare(size_type __pos1, size_type __n1, basic_string_view __str) const
      { return this->substr(__pos1, __n1).compare(__str); }

      constexpr int
      compare(size_type __pos1, size_type __n1,
	      basic_string_view __str, size_type __pos2, size_type __n2) const
      { return this->substr(__pos1, __n1).compare(__str.substr(__pos2, __n2)); }

      constexpr int
      compare(const _CharT* __str) const noexcept
      { return this->compare(basic_string_view{__str}); }

      constexpr int
      compare(size_type __pos1, size_type __n1, const _CharT* __str) const
      { return this->substr(__pos1, __n1).compare(basic_string_view{__str}); }

      constexpr int
      compare(size_type __pos1, size_type __n1,
	      const _CharT* __str, size_type __n2) const
      {
	return this->substr(__pos1, __n1)
		   .compare(basic_string_view(__str, __n2));
      }

      constexpr size_type
      find(basic_string_view __str, size_type __pos = 0) const noexcept
      { return this->find(__str._M_str, __pos, __str._M_len); }

      constexpr size_type
      find(_CharT __c, size_type __pos=0) const noexcept;

      constexpr size_type
      find(const _CharT* __str, size_type __pos, size_type __n) const noexcept;

      constexpr size_type
      find(const _CharT* __str, size_type __pos=0) const noexcept
      { return this->find(__str, __pos, traits_type::length(__str)); }

      constexpr size_type
      rfind(basic_string_view __str, size_type __pos = npos) const noexcept
      { return this->rfind(__str._M_str, __pos, __str._M_len); }

      constexpr size_type
      rfind(_CharT __c, size_type __pos = npos) const noexcept;

      constexpr size_type
      rfind(const _CharT* __str, size_type __pos, size_type __n) const noexcept;

      constexpr size_type
      rfind(const _CharT* __str, size_type __pos = npos) const noexcept
      { return this->rfind(__str, __pos, traits_type::length(__str)); }

      constexpr size_type
      find_first_of(basic_string_view __str, size_type __pos = 0) const noexcept
      { return this->find_first_of(__str._M_str, __pos, __str._M_len); }

      constexpr size_type
      find_first_of(_CharT __c, size_type __pos = 0) const noexcept
      { return this->find(__c, __pos); }

      constexpr size_type
      find_first_of(const _CharT* __str, size_type __pos, size_type __n) const;

      constexpr size_type
      find_first_of(const _CharT* __str, size_type __pos = 0) const noexcept
      { return this->find_first_of(__str, __pos, traits_type::length(__str)); }

      constexpr size_type
      find_last_of(basic_string_view __str,
		   size_type __pos = npos) const noexcept
      { return this->find_last_of(__str._M_str, __pos, __str._M_len); }

      constexpr size_type
      find_last_of(_CharT __c, size_type __pos=npos) const noexcept
      { return this->rfind(__c, __pos); }

      constexpr size_type
      find_last_of(const _CharT* __str, size_type __pos, size_type __n) const;

      constexpr size_type
      find_last_of(const _CharT* __str, size_type __pos = npos) const noexcept
      { return this->find_last_of(__str, __pos, traits_type::length(__str)); }

      constexpr size_type
      find_first_not_of(basic_string_view __str,
			size_type __pos = 0) const noexcept
      { return this->find_first_not_of(__str._M_str, __pos, __str._M_len); }

      constexpr size_type
      find_first_not_of(_CharT __c, size_type __pos = 0) const noexcept;

      constexpr size_type
      find_first_not_of(const _CharT* __str,
			size_type __pos, size_type __n) const;

      constexpr size_type
      find_first_not_of(const _CharT* __str, size_type __pos = 0) const noexcept
      {
	return this->find_first_not_of(__str, __pos,
				       traits_type::length(__str));
      }

      constexpr size_type
      find_last_not_of(basic_string_view __str,
		       size_type __pos = npos) const noexcept
      { return this->find_last_not_of(__str._M_str, __pos, __str._M_len); }

      constexpr size_type
      find_last_not_of(_CharT __c, size_type __pos = npos) const noexcept;

      constexpr size_type
      find_last_not_of(const _CharT* __str,
		       size_type __pos, size_type __n) const;

      constexpr size_type
      find_last_not_of(const _CharT* __str,
		       size_type __pos = npos) const noexcept
      {
	return this->find_last_not_of(__str, __pos,
				      traits_type::length(__str));
      }

      constexpr size_type
      _M_check(size_type __pos, const char* __s) const
      {
	if (__pos > this->size())
	  __throw_out_of_range_fmt(__N("%s: __pos (which is %zu) > "
				       "this->size() (which is %zu)"),
				   __s, __pos, this->size());
	return __pos;
      }

      // NB: _M_limit doesn't check for a bad __pos value.
      constexpr size_type
      _M_limit(size_type __pos, size_type __off) const _GLIBCXX_NOEXCEPT
      {
	const bool __testoff =  __off < this->size() - __pos;
	return __testoff ? __off : this->size() - __pos;
      }
      
    private:

      static constexpr int
      _S_compare(size_type __n1, size_type __n2) noexcept
      {
	return difference_type{__n1 - __n2} > std::numeric_limits<int>::max()
	     ? std::numeric_limits<int>::max()
	     : difference_type{__n1 - __n2} < std::numeric_limits<int>::min()
	     ? std::numeric_limits<int>::min()
	     : static_cast<int>(difference_type{__n1 - __n2});
      }

      size_t	    _M_len;
      const _CharT* _M_str;
    };
_GLIBCXX_END_NAMESPACE_VERSION

  // [string.view.comparison], non-member basic_string_view comparison function

  namespace __detail
  {
_GLIBCXX_BEGIN_NAMESPACE_VERSION
    // Identity transform to create a non-deduced context, so that only one
    // argument participates in template argument deduction and the other
    // argument gets implicitly converted to the deduced type. See n3766.html.
    template<typename _Tp>
      using __idt = common_type_t<_Tp>;
_GLIBCXX_END_NAMESPACE_VERSION
  }

_GLIBCXX_BEGIN_NAMESPACE_VERSION

  template<typename _CharT, typename _Traits>
    constexpr bool
    operator==(basic_string_view<_CharT, _Traits> __x,
               basic_string_view<_CharT, _Traits> __y) noexcept
    { return __x.size() == __y.size() && __x.compare(__y) == 0; }

  template<typename _CharT, typename _Traits>
    constexpr bool
    operator==(basic_string_view<_CharT, _Traits> __x,
               __detail::__idt<basic_string_view<_CharT, _Traits>> __y) noexcept
    { return __x.size() == __y.size() && __x.compare(__y) == 0; }

  template<typename _CharT, typename _Traits>
    constexpr bool
    operator==(__detail::__idt<basic_string_view<_CharT, _Traits>> __x,
               basic_string_view<_CharT, _Traits> __y) noexcept
    { return __x.size() == __y.size() && __x.compare(__y) == 0; }

  template<typename _CharT, typename _Traits>
    constexpr bool
    operator!=(basic_string_view<_CharT, _Traits> __x,
               basic_string_view<_CharT, _Traits> __y) noexcept
    { return !(__x == __y); }

  template<typename _CharT, typename _Traits>
    constexpr bool
    operator!=(basic_string_view<_CharT, _Traits> __x,
               __detail::__idt<basic_string_view<_CharT, _Traits>> __y) noexcept
    { return !(__x == __y); }

  template<typename _CharT, typename _Traits>
    constexpr bool
    operator!=(__detail::__idt<basic_string_view<_CharT, _Traits>> __x,
               basic_string_view<_CharT, _Traits> __y) noexcept
    { return !(__x == __y); }

  template<typename _CharT, typename _Traits>
    constexpr bool
    operator< (basic_string_view<_CharT, _Traits> __x,
               basic_string_view<_CharT, _Traits> __y) noexcept
    { return __x.compare(__y) < 0; }

  template<typename _CharT, typename _Traits>
    constexpr bool
    operator< (basic_string_view<_CharT, _Traits> __x,
               __detail::__idt<basic_string_view<_CharT, _Traits>> __y) noexcept
    { return __x.compare(__y) < 0; }

  template<typename _CharT, typename _Traits>
    constexpr bool
    operator< (__detail::__idt<basic_string_view<_CharT, _Traits>> __x,
               basic_string_view<_CharT, _Traits> __y) noexcept
    { return __x.compare(__y) < 0; }

  template<typename _CharT, typename _Traits>
    constexpr bool
    operator> (basic_string_view<_CharT, _Traits> __x,
               basic_string_view<_CharT, _Traits> __y) noexcept
    { return __x.compare(__y) > 0; }

  template<typename _CharT, typename _Traits>
    constexpr bool
    operator> (basic_string_view<_CharT, _Traits> __x,
               __detail::__idt<basic_string_view<_CharT, _Traits>> __y) noexcept
    { return __x.compare(__y) > 0; }

  template<typename _CharT, typename _Traits>
    constexpr bool
    operator> (__detail::__idt<basic_string_view<_CharT, _Traits>> __x,
               basic_string_view<_CharT, _Traits> __y) noexcept
    { return __x.compare(__y) > 0; }

  template<typename _CharT, typename _Traits>
    constexpr bool
    operator<=(basic_string_view<_CharT, _Traits> __x,
               basic_string_view<_CharT, _Traits> __y) noexcept
    { return __x.compare(__y) <= 0; }

  template<typename _CharT, typename _Traits>
    constexpr bool
    operator<=(basic_string_view<_CharT, _Traits> __x,
               __detail::__idt<basic_string_view<_CharT, _Traits>> __y) noexcept
    { return __x.compare(__y) <= 0; }

  template<typename _CharT, typename _Traits>
    constexpr bool
    operator<=(__detail::__idt<basic_string_view<_CharT, _Traits>> __x,
               basic_string_view<_CharT, _Traits> __y) noexcept
    { return __x.compare(__y) <= 0; }

  template<typename _CharT, typename _Traits>
    constexpr bool
    operator>=(basic_string_view<_CharT, _Traits> __x,
               basic_string_view<_CharT, _Traits> __y) noexcept
    { return __x.compare(__y) >= 0; }

  template<typename _CharT, typename _Traits>
    constexpr bool
    operator>=(basic_string_view<_CharT, _Traits> __x,
               __detail::__idt<basic_string_view<_CharT, _Traits>> __y) noexcept
    { return __x.compare(__y) >= 0; }

  template<typename _CharT, typename _Traits>
    constexpr bool
    operator>=(__detail::__idt<basic_string_view<_CharT, _Traits>> __x,
               basic_string_view<_CharT, _Traits> __y) noexcept
    { return __x.compare(__y) >= 0; }

  // [string.view.io], Inserters and extractors
  template<typename _CharT, typename _Traits>
    inline basic_ostream<_CharT, _Traits>&
    operator<<(basic_ostream<_CharT, _Traits>& __os,
	       basic_string_view<_CharT,_Traits> __str)
    { return __ostream_insert(__os, __str.data(), __str.size()); }


  // basic_string_view typedef names

  using string_view = basic_string_view<char>;
#ifdef _GLIBCXX_USE_WCHAR_T
  using wstring_view = basic_string_view<wchar_t>;
#endif
#ifdef _GLIBCXX_USE_C99_STDINT_TR1
  using u16string_view = basic_string_view<char16_t>;
  using u32string_view = basic_string_view<char32_t>;
#endif

  // [string.view.hash], hash support:

  template<typename _Tp>
    struct hash;

  template<>
    struct hash<string_view>
    : public __hash_base<size_t, string_view>
    {
      size_t
      operator()(const string_view& __str) const noexcept
      { return std::_Hash_impl::hash(__str.data(), __str.length()); }
    };

  template<>
    struct __is_fast_hash<hash<string_view>> : std::false_type
    { };

#ifdef _GLIBCXX_USE_WCHAR_T
  template<>
    struct hash<wstring_view>
    : public __hash_base<size_t, wstring>
    {
      size_t
      operator()(const wstring_view& __s) const noexcept
      { return std::_Hash_impl::hash(__s.data(),
                                     __s.length() * sizeof(wchar_t)); }
    };

  template<>
    struct __is_fast_hash<hash<wstring_view>> : std::false_type
    { };
#endif

#ifdef _GLIBCXX_USE_C99_STDINT_TR1
  template<>
    struct hash<u16string_view>
    : public __hash_base<size_t, u16string_view>
    {
      size_t
      operator()(const u16string_view& __s) const noexcept
      { return std::_Hash_impl::hash(__s.data(),
                                     __s.length() * sizeof(char16_t)); }
    };

  template<>
    struct __is_fast_hash<hash<u16string_view>> : std::false_type
    { };

  template<>
    struct hash<u32string_view>
    : public __hash_base<size_t, u32string_view>
    {
      size_t
      operator()(const u32string_view& __s) const noexcept
      { return std::_Hash_impl::hash(__s.data(),
                                     __s.length() * sizeof(char32_t)); }
    };

  template<>
    struct __is_fast_hash<hash<u32string_view>> : std::false_type
    { };
#endif
_GLIBCXX_END_NAMESPACE_VERSION

  inline namespace literals
  {
  inline namespace string_view_literals
  {
_GLIBCXX_BEGIN_NAMESPACE_VERSION

    inline constexpr basic_string_view<char>
    operator""sv(const char* __str, size_t __len) noexcept
    { return basic_string_view<char>{__str, __len}; }

#ifdef _GLIBCXX_USE_WCHAR_T
    inline constexpr basic_string_view<wchar_t>
    operator""sv(const wchar_t* __str, size_t __len) noexcept
    { return basic_string_view<wchar_t>{__str, __len}; }
#endif

#ifdef _GLIBCXX_USE_C99_STDINT_TR1
    inline constexpr basic_string_view<char16_t>
    operator""sv(const char16_t* __str, size_t __len) noexcept
    { return basic_string_view<char16_t>{__str, __len}; }

    inline constexpr basic_string_view<char32_t>
    operator""sv(const char32_t* __str, size_t __len) noexcept
    { return basic_string_view<char32_t>{__str, __len}; }
#endif

_GLIBCXX_END_NAMESPACE_VERSION
  } // namespace string_literals
  } // namespace literals

} // namespace std

#include <bits/string_view.tcc>

#endif // __cplusplus <= 201402L

#endif // _GLIBCXX_EXPERIMENTAL_STRING_VIEW
@


1.1.1.1.4.3
log
@Mostly merge changes from HEAD upto 20200411
@
text
@d3 1
a3 1
// Copyright (C) 2013-2018 Free Software Foundation, Inc.
d99 1
a99 1
      constexpr basic_string_view(const _CharT* __str) noexcept
d104 3
a106 3
      constexpr
      basic_string_view(const _CharT* __str, size_type __len) noexcept
      : _M_len{__len}, _M_str{__str}
d163 1
a163 1
      [[nodiscard]] constexpr bool
d180 7
a186 5
	if (__pos >= _M_len)
	  __throw_out_of_range_fmt(__N("basic_string_view::at: __pos "
				       "(which is %zu) >= this->size() "
				       "(which is %zu)"), __pos, this->size());
	return *(this->_M_str + __pos);
d190 1
a190 1
      front() const noexcept
d198 1
a198 1
      back() const noexcept
d212 1
a212 1
      remove_prefix(size_type __n) noexcept
d220 1
a220 1
      remove_suffix(size_type __n) noexcept
d238 9
a246 5
	__pos = _M_check(__pos, "basic_string_view::copy");
	const size_type __rlen = std::min(__n, _M_len - __pos);
	// _GLIBCXX_RESOLVE_LIB_DEFECTS
	// 2777. basic_string_view::copy should use char_traits::copy
	traits_type::copy(__str, data() + __pos, __rlen);
d250 3
d254 1
a254 1
      substr(size_type __pos = 0, size_type __n = npos) const noexcept(false)
d256 7
a262 3
	__pos = _M_check(__pos, "basic_string_view::substr");
	const size_type __rlen = std::min(__n, _M_len - __pos);
	return basic_string_view{_M_str + __pos, __rlen};
d268 2
a269 2
	const size_type __rlen = std::min(this->_M_len, __str._M_len);
	int __ret = traits_type::compare(this->_M_str, __str._M_str, __rlen);
d282 1
a282 3
      {
	return this->substr(__pos1, __n1).compare(__str.substr(__pos2, __n2));
      }
d294 1
a294 1
	      const _CharT* __str, size_type __n2) const noexcept(false)
d305 1
a305 1
      find(_CharT __c, size_type __pos = 0) const noexcept;
d311 1
a311 1
      find(const _CharT* __str, size_type __pos = 0) const noexcept
d337 1
a337 1
      find_first_of(const _CharT* __str, size_type __pos, size_type __n) const noexcept;
d353 1
a353 2
      find_last_of(const _CharT* __str, size_type __pos,
		   size_type __n) const noexcept;
d369 1
a369 1
			size_type __pos, size_type __n) const noexcept;
d388 1
a388 1
		       size_type __pos, size_type __n) const noexcept;
d399 1
a399 1
      _M_check(size_type __pos, const char* __s) const noexcept(false)
d410 1
a410 1
      _M_limit(size_type __pos, size_type __off) const noexcept
d421 5
a425 6
	const difference_type __diff = __n1 - __n2;
	if (__diff > std::numeric_limits<int>::max())
	  return std::numeric_limits<int>::max();
	if (__diff < std::numeric_limits<int>::min())
	  return std::numeric_limits<int>::min();
	return static_cast<int>(__diff);
d431 1
d437 1
d443 1
d446 2
d638 1
d644 2
a645 2
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wliteral-suffix"
d665 2
a666 1
#pragma GCC diagnostic pop
a669 1
_GLIBCXX_END_NAMESPACE_VERSION
@


1.1.1.1.2.1
log
@file string_view was added on branch pgoyette-compat on 2019-01-26 21:59:39 +0000
@
text
@d1 676
@


1.1.1.1.2.2
log
@Sync with HEAD
@
text
@a0 676
// Components for manipulating non-owning sequences of characters -*- C++ -*-

// Copyright (C) 2013-2017 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library.  This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.

// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// Under Section 7 of GPL version 3, you are granted additional
// permissions described in the GCC Runtime Library Exception, version
// 3.1, as published by the Free Software Foundation.

// You should have received a copy of the GNU General Public License and
// a copy of the GCC Runtime Library Exception along with this program;
// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
// <http://www.gnu.org/licenses/>.

/** @@file string_view
 *  This is a Standard C++ Library header.
 */

//
// N3762 basic_string_view library
//

#ifndef _GLIBCXX_STRING_VIEW
#define _GLIBCXX_STRING_VIEW 1

#pragma GCC system_header

#if __cplusplus >= 201703L

#include <limits>
#include <iosfwd>
#include <bits/char_traits.h>
#include <bits/functional_hash.h>
#include <bits/range_access.h>

namespace std _GLIBCXX_VISIBILITY(default)
{
_GLIBCXX_BEGIN_NAMESPACE_VERSION

#define __cpp_lib_string_view 201603

  /**
   *  @@class basic_string_view <string_view>
   *  @@brief  A non-owning reference to a string.
   *
   *  @@ingroup strings
   *  @@ingroup sequences
   *
   *  @@tparam _CharT  Type of character
   *  @@tparam _Traits  Traits for character type, defaults to
   *                   char_traits<_CharT>.
   *
   *  A basic_string_view looks like this:
   *
   *  @@code
   *    _CharT*    _M_str
   *    size_t     _M_len
   *  @@endcode
   */
  template<typename _CharT, typename _Traits = std::char_traits<_CharT>>
    class basic_string_view
    {
    public:

      // types
      using traits_type = _Traits;
      using value_type = _CharT;
      using pointer = const _CharT*;
      using const_pointer = const _CharT*;
      using reference = const _CharT&;
      using const_reference = const _CharT&;
      using const_iterator = const _CharT*;
      using iterator = const_iterator;
      using const_reverse_iterator = std::reverse_iterator<const_iterator>;
      using reverse_iterator = const_reverse_iterator;
      using size_type = size_t;
      using difference_type = ptrdiff_t;
      static constexpr size_type npos = size_type(-1);

      // [string.view.cons], construct/copy

      constexpr
      basic_string_view() noexcept
      : _M_len{0}, _M_str{nullptr}
      { }

      constexpr basic_string_view(const basic_string_view&) noexcept = default;

      constexpr basic_string_view(const _CharT* __str)
      : _M_len{__str == nullptr ? 0 : traits_type::length(__str)},
	_M_str{__str}
      { }

      constexpr basic_string_view(const _CharT* __str, size_type __len)
      : _M_len{__len},
        _M_str{__str}
      { }

      constexpr basic_string_view&
      operator=(const basic_string_view&) noexcept = default;

      // [string.view.iterators], iterators

      constexpr const_iterator
      begin() const noexcept
      { return this->_M_str; }

      constexpr const_iterator
      end() const noexcept
      { return this->_M_str + this->_M_len; }

      constexpr const_iterator
      cbegin() const noexcept
      { return this->_M_str; }

      constexpr const_iterator
      cend() const noexcept
      { return this->_M_str + this->_M_len; }

      constexpr const_reverse_iterator
      rbegin() const noexcept
      { return const_reverse_iterator(this->end()); }

      constexpr const_reverse_iterator
      rend() const noexcept
      { return const_reverse_iterator(this->begin()); }

      constexpr const_reverse_iterator
      crbegin() const noexcept
      { return const_reverse_iterator(this->end()); }

      constexpr const_reverse_iterator
      crend() const noexcept
      { return const_reverse_iterator(this->begin()); }

      // [string.view.capacity], capacity

      constexpr size_type
      size() const noexcept
      { return this->_M_len; }

      constexpr size_type
      length() const noexcept
      { return _M_len; }

      constexpr size_type
      max_size() const noexcept
      {
	return (npos - sizeof(size_type) - sizeof(void*))
		/ sizeof(value_type) / 4;
      }

      constexpr bool
      empty() const noexcept
      { return this->_M_len == 0; }

      // [string.view.access], element access

      constexpr const _CharT&
      operator[](size_type __pos) const noexcept
      {
	// TODO: Assert to restore in a way compatible with the constexpr.
	// __glibcxx_assert(__pos < this->_M_len);
	return *(this->_M_str + __pos);
      }

      constexpr const _CharT&
      at(size_type __pos) const
      {
	return __pos < this->_M_len
	     ? *(this->_M_str + __pos)
	     : (__throw_out_of_range_fmt(__N("basic_string_view::at: __pos "
					     "(which is %zu) >= this->size() "
					     "(which is %zu)"),
					 __pos, this->size()),
		*this->_M_str);
      }

      constexpr const _CharT&
      front() const
      {
	// TODO: Assert to restore in a way compatible with the constexpr.
	// __glibcxx_assert(this->_M_len > 0);
	return *this->_M_str;
      }

      constexpr const _CharT&
      back() const
      {
	// TODO: Assert to restore in a way compatible with the constexpr.
	// __glibcxx_assert(this->_M_len > 0);
	return *(this->_M_str + this->_M_len - 1);
      }

      constexpr const _CharT*
      data() const noexcept
      { return this->_M_str; }

      // [string.view.modifiers], modifiers:

      constexpr void
      remove_prefix(size_type __n)
      {
	__glibcxx_assert(this->_M_len >= __n);
	this->_M_str += __n;
	this->_M_len -= __n;
      }

      constexpr void
      remove_suffix(size_type __n)
      { this->_M_len -= __n; }

      constexpr void
      swap(basic_string_view& __sv) noexcept
      {
	auto __tmp = *this;
	*this = __sv;
	__sv = __tmp;
      }


      // [string.view.ops], string operations:

      size_type
      copy(_CharT* __str, size_type __n, size_type __pos = 0) const
      {
	__glibcxx_requires_string_len(__str, __n);
	if (__pos > this->_M_len)
	  __throw_out_of_range_fmt(__N("basic_string_view::copy: __pos "
				       "(which is %zu) > this->size() "
				       "(which is %zu)"),
				   __pos, this->size());
	size_type __rlen{std::min(__n, size_type{this->_M_len  - __pos})};
	for (auto __begin = this->_M_str + __pos,
	     __end = __begin + __rlen; __begin != __end;)
	  *__str++ = *__begin++;
	return __rlen;
      }


      // [string.view.ops], string operations:

      constexpr basic_string_view
      substr(size_type __pos, size_type __n=npos) const
      {
	return __pos <= this->_M_len
	     ? basic_string_view{this->_M_str + __pos,
				std::min(__n, size_type{this->_M_len  - __pos})}
	     : (__throw_out_of_range_fmt(__N("basic_string_view::substr: __pos "
					     "(which is %zu) > this->size() "
					     "(which is %zu)"),
				     __pos, this->size()), basic_string_view{});
      }

      constexpr int
      compare(basic_string_view __str) const noexcept
      {
	int __ret = traits_type::compare(this->_M_str, __str._M_str,
					 std::min(this->_M_len, __str._M_len));
	if (__ret == 0)
	  __ret = _S_compare(this->_M_len, __str._M_len);
	return __ret;
      }

      constexpr int
      compare(size_type __pos1, size_type __n1, basic_string_view __str) const
      { return this->substr(__pos1, __n1).compare(__str); }

      constexpr int
      compare(size_type __pos1, size_type __n1,
	      basic_string_view __str, size_type __pos2, size_type __n2) const
      { return this->substr(__pos1, __n1).compare(__str.substr(__pos2, __n2)); }

      constexpr int
      compare(const _CharT* __str) const noexcept
      { return this->compare(basic_string_view{__str}); }

      constexpr int
      compare(size_type __pos1, size_type __n1, const _CharT* __str) const
      { return this->substr(__pos1, __n1).compare(basic_string_view{__str}); }

      constexpr int
      compare(size_type __pos1, size_type __n1,
	      const _CharT* __str, size_type __n2) const
      {
	return this->substr(__pos1, __n1)
		   .compare(basic_string_view(__str, __n2));
      }

      constexpr size_type
      find(basic_string_view __str, size_type __pos = 0) const noexcept
      { return this->find(__str._M_str, __pos, __str._M_len); }

      constexpr size_type
      find(_CharT __c, size_type __pos=0) const noexcept;

      constexpr size_type
      find(const _CharT* __str, size_type __pos, size_type __n) const noexcept;

      constexpr size_type
      find(const _CharT* __str, size_type __pos=0) const noexcept
      { return this->find(__str, __pos, traits_type::length(__str)); }

      constexpr size_type
      rfind(basic_string_view __str, size_type __pos = npos) const noexcept
      { return this->rfind(__str._M_str, __pos, __str._M_len); }

      constexpr size_type
      rfind(_CharT __c, size_type __pos = npos) const noexcept;

      constexpr size_type
      rfind(const _CharT* __str, size_type __pos, size_type __n) const noexcept;

      constexpr size_type
      rfind(const _CharT* __str, size_type __pos = npos) const noexcept
      { return this->rfind(__str, __pos, traits_type::length(__str)); }

      constexpr size_type
      find_first_of(basic_string_view __str, size_type __pos = 0) const noexcept
      { return this->find_first_of(__str._M_str, __pos, __str._M_len); }

      constexpr size_type
      find_first_of(_CharT __c, size_type __pos = 0) const noexcept
      { return this->find(__c, __pos); }

      constexpr size_type
      find_first_of(const _CharT* __str, size_type __pos, size_type __n) const;

      constexpr size_type
      find_first_of(const _CharT* __str, size_type __pos = 0) const noexcept
      { return this->find_first_of(__str, __pos, traits_type::length(__str)); }

      constexpr size_type
      find_last_of(basic_string_view __str,
		   size_type __pos = npos) const noexcept
      { return this->find_last_of(__str._M_str, __pos, __str._M_len); }

      constexpr size_type
      find_last_of(_CharT __c, size_type __pos=npos) const noexcept
      { return this->rfind(__c, __pos); }

      constexpr size_type
      find_last_of(const _CharT* __str, size_type __pos, size_type __n) const;

      constexpr size_type
      find_last_of(const _CharT* __str, size_type __pos = npos) const noexcept
      { return this->find_last_of(__str, __pos, traits_type::length(__str)); }

      constexpr size_type
      find_first_not_of(basic_string_view __str,
			size_type __pos = 0) const noexcept
      { return this->find_first_not_of(__str._M_str, __pos, __str._M_len); }

      constexpr size_type
      find_first_not_of(_CharT __c, size_type __pos = 0) const noexcept;

      constexpr size_type
      find_first_not_of(const _CharT* __str,
			size_type __pos, size_type __n) const;

      constexpr size_type
      find_first_not_of(const _CharT* __str, size_type __pos = 0) const noexcept
      {
	return this->find_first_not_of(__str, __pos,
				       traits_type::length(__str));
      }

      constexpr size_type
      find_last_not_of(basic_string_view __str,
		       size_type __pos = npos) const noexcept
      { return this->find_last_not_of(__str._M_str, __pos, __str._M_len); }

      constexpr size_type
      find_last_not_of(_CharT __c, size_type __pos = npos) const noexcept;

      constexpr size_type
      find_last_not_of(const _CharT* __str,
		       size_type __pos, size_type __n) const;

      constexpr size_type
      find_last_not_of(const _CharT* __str,
		       size_type __pos = npos) const noexcept
      {
	return this->find_last_not_of(__str, __pos,
				      traits_type::length(__str));
      }

      constexpr size_type
      _M_check(size_type __pos, const char* __s) const
      {
	if (__pos > this->size())
	  __throw_out_of_range_fmt(__N("%s: __pos (which is %zu) > "
				       "this->size() (which is %zu)"),
				   __s, __pos, this->size());
	return __pos;
      }

      // NB: _M_limit doesn't check for a bad __pos value.
      constexpr size_type
      _M_limit(size_type __pos, size_type __off) const _GLIBCXX_NOEXCEPT
      {
	const bool __testoff =  __off < this->size() - __pos;
	return __testoff ? __off : this->size() - __pos;
      }
      
    private:

      static constexpr int
      _S_compare(size_type __n1, size_type __n2) noexcept
      {
	return difference_type{__n1 - __n2} > std::numeric_limits<int>::max()
	     ? std::numeric_limits<int>::max()
	     : difference_type{__n1 - __n2} < std::numeric_limits<int>::min()
	     ? std::numeric_limits<int>::min()
	     : static_cast<int>(difference_type{__n1 - __n2});
      }

      size_t	    _M_len;
      const _CharT* _M_str;
    };
_GLIBCXX_END_NAMESPACE_VERSION

  // [string.view.comparison], non-member basic_string_view comparison function

  namespace __detail
  {
_GLIBCXX_BEGIN_NAMESPACE_VERSION
    // Identity transform to create a non-deduced context, so that only one
    // argument participates in template argument deduction and the other
    // argument gets implicitly converted to the deduced type. See n3766.html.
    template<typename _Tp>
      using __idt = common_type_t<_Tp>;
_GLIBCXX_END_NAMESPACE_VERSION
  }

_GLIBCXX_BEGIN_NAMESPACE_VERSION

  template<typename _CharT, typename _Traits>
    constexpr bool
    operator==(basic_string_view<_CharT, _Traits> __x,
               basic_string_view<_CharT, _Traits> __y) noexcept
    { return __x.size() == __y.size() && __x.compare(__y) == 0; }

  template<typename _CharT, typename _Traits>
    constexpr bool
    operator==(basic_string_view<_CharT, _Traits> __x,
               __detail::__idt<basic_string_view<_CharT, _Traits>> __y) noexcept
    { return __x.size() == __y.size() && __x.compare(__y) == 0; }

  template<typename _CharT, typename _Traits>
    constexpr bool
    operator==(__detail::__idt<basic_string_view<_CharT, _Traits>> __x,
               basic_string_view<_CharT, _Traits> __y) noexcept
    { return __x.size() == __y.size() && __x.compare(__y) == 0; }

  template<typename _CharT, typename _Traits>
    constexpr bool
    operator!=(basic_string_view<_CharT, _Traits> __x,
               basic_string_view<_CharT, _Traits> __y) noexcept
    { return !(__x == __y); }

  template<typename _CharT, typename _Traits>
    constexpr bool
    operator!=(basic_string_view<_CharT, _Traits> __x,
               __detail::__idt<basic_string_view<_CharT, _Traits>> __y) noexcept
    { return !(__x == __y); }

  template<typename _CharT, typename _Traits>
    constexpr bool
    operator!=(__detail::__idt<basic_string_view<_CharT, _Traits>> __x,
               basic_string_view<_CharT, _Traits> __y) noexcept
    { return !(__x == __y); }

  template<typename _CharT, typename _Traits>
    constexpr bool
    operator< (basic_string_view<_CharT, _Traits> __x,
               basic_string_view<_CharT, _Traits> __y) noexcept
    { return __x.compare(__y) < 0; }

  template<typename _CharT, typename _Traits>
    constexpr bool
    operator< (basic_string_view<_CharT, _Traits> __x,
               __detail::__idt<basic_string_view<_CharT, _Traits>> __y) noexcept
    { return __x.compare(__y) < 0; }

  template<typename _CharT, typename _Traits>
    constexpr bool
    operator< (__detail::__idt<basic_string_view<_CharT, _Traits>> __x,
               basic_string_view<_CharT, _Traits> __y) noexcept
    { return __x.compare(__y) < 0; }

  template<typename _CharT, typename _Traits>
    constexpr bool
    operator> (basic_string_view<_CharT, _Traits> __x,
               basic_string_view<_CharT, _Traits> __y) noexcept
    { return __x.compare(__y) > 0; }

  template<typename _CharT, typename _Traits>
    constexpr bool
    operator> (basic_string_view<_CharT, _Traits> __x,
               __detail::__idt<basic_string_view<_CharT, _Traits>> __y) noexcept
    { return __x.compare(__y) > 0; }

  template<typename _CharT, typename _Traits>
    constexpr bool
    operator> (__detail::__idt<basic_string_view<_CharT, _Traits>> __x,
               basic_string_view<_CharT, _Traits> __y) noexcept
    { return __x.compare(__y) > 0; }

  template<typename _CharT, typename _Traits>
    constexpr bool
    operator<=(basic_string_view<_CharT, _Traits> __x,
               basic_string_view<_CharT, _Traits> __y) noexcept
    { return __x.compare(__y) <= 0; }

  template<typename _CharT, typename _Traits>
    constexpr bool
    operator<=(basic_string_view<_CharT, _Traits> __x,
               __detail::__idt<basic_string_view<_CharT, _Traits>> __y) noexcept
    { return __x.compare(__y) <= 0; }

  template<typename _CharT, typename _Traits>
    constexpr bool
    operator<=(__detail::__idt<basic_string_view<_CharT, _Traits>> __x,
               basic_string_view<_CharT, _Traits> __y) noexcept
    { return __x.compare(__y) <= 0; }

  template<typename _CharT, typename _Traits>
    constexpr bool
    operator>=(basic_string_view<_CharT, _Traits> __x,
               basic_string_view<_CharT, _Traits> __y) noexcept
    { return __x.compare(__y) >= 0; }

  template<typename _CharT, typename _Traits>
    constexpr bool
    operator>=(basic_string_view<_CharT, _Traits> __x,
               __detail::__idt<basic_string_view<_CharT, _Traits>> __y) noexcept
    { return __x.compare(__y) >= 0; }

  template<typename _CharT, typename _Traits>
    constexpr bool
    operator>=(__detail::__idt<basic_string_view<_CharT, _Traits>> __x,
               basic_string_view<_CharT, _Traits> __y) noexcept
    { return __x.compare(__y) >= 0; }

  // [string.view.io], Inserters and extractors
  template<typename _CharT, typename _Traits>
    inline basic_ostream<_CharT, _Traits>&
    operator<<(basic_ostream<_CharT, _Traits>& __os,
	       basic_string_view<_CharT,_Traits> __str)
    { return __ostream_insert(__os, __str.data(), __str.size()); }


  // basic_string_view typedef names

  using string_view = basic_string_view<char>;
#ifdef _GLIBCXX_USE_WCHAR_T
  using wstring_view = basic_string_view<wchar_t>;
#endif
#ifdef _GLIBCXX_USE_C99_STDINT_TR1
  using u16string_view = basic_string_view<char16_t>;
  using u32string_view = basic_string_view<char32_t>;
#endif

  // [string.view.hash], hash support:

  template<typename _Tp>
    struct hash;

  template<>
    struct hash<string_view>
    : public __hash_base<size_t, string_view>
    {
      size_t
      operator()(const string_view& __str) const noexcept
      { return std::_Hash_impl::hash(__str.data(), __str.length()); }
    };

  template<>
    struct __is_fast_hash<hash<string_view>> : std::false_type
    { };

#ifdef _GLIBCXX_USE_WCHAR_T
  template<>
    struct hash<wstring_view>
    : public __hash_base<size_t, wstring>
    {
      size_t
      operator()(const wstring_view& __s) const noexcept
      { return std::_Hash_impl::hash(__s.data(),
                                     __s.length() * sizeof(wchar_t)); }
    };

  template<>
    struct __is_fast_hash<hash<wstring_view>> : std::false_type
    { };
#endif

#ifdef _GLIBCXX_USE_C99_STDINT_TR1
  template<>
    struct hash<u16string_view>
    : public __hash_base<size_t, u16string_view>
    {
      size_t
      operator()(const u16string_view& __s) const noexcept
      { return std::_Hash_impl::hash(__s.data(),
                                     __s.length() * sizeof(char16_t)); }
    };

  template<>
    struct __is_fast_hash<hash<u16string_view>> : std::false_type
    { };

  template<>
    struct hash<u32string_view>
    : public __hash_base<size_t, u32string_view>
    {
      size_t
      operator()(const u32string_view& __s) const noexcept
      { return std::_Hash_impl::hash(__s.data(),
                                     __s.length() * sizeof(char32_t)); }
    };

  template<>
    struct __is_fast_hash<hash<u32string_view>> : std::false_type
    { };
#endif
_GLIBCXX_END_NAMESPACE_VERSION

  inline namespace literals
  {
  inline namespace string_view_literals
  {
_GLIBCXX_BEGIN_NAMESPACE_VERSION

    inline constexpr basic_string_view<char>
    operator""sv(const char* __str, size_t __len) noexcept
    { return basic_string_view<char>{__str, __len}; }

#ifdef _GLIBCXX_USE_WCHAR_T
    inline constexpr basic_string_view<wchar_t>
    operator""sv(const wchar_t* __str, size_t __len) noexcept
    { return basic_string_view<wchar_t>{__str, __len}; }
#endif

#ifdef _GLIBCXX_USE_C99_STDINT_TR1
    inline constexpr basic_string_view<char16_t>
    operator""sv(const char16_t* __str, size_t __len) noexcept
    { return basic_string_view<char16_t>{__str, __len}; }

    inline constexpr basic_string_view<char32_t>
    operator""sv(const char32_t* __str, size_t __len) noexcept
    { return basic_string_view<char32_t>{__str, __len}; }
#endif

_GLIBCXX_END_NAMESPACE_VERSION
  } // namespace string_literals
  } // namespace literals

} // namespace std

#include <bits/string_view.tcc>

#endif // __cplusplus <= 201402L

#endif // _GLIBCXX_EXPERIMENTAL_STRING_VIEW
@


