xref: /freebsd/contrib/llvm-project/libcxx/include/string (revision 5ffd83dbcc34f10e07f6d3e968ae6365869615f4)
10b57cec5SDimitry Andric// -*- C++ -*-
20b57cec5SDimitry Andric//===--------------------------- string -----------------------------------===//
30b57cec5SDimitry Andric//
40b57cec5SDimitry Andric// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
50b57cec5SDimitry Andric// See https://llvm.org/LICENSE.txt for license information.
60b57cec5SDimitry Andric// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
70b57cec5SDimitry Andric//
80b57cec5SDimitry Andric//===----------------------------------------------------------------------===//
90b57cec5SDimitry Andric
100b57cec5SDimitry Andric#ifndef _LIBCPP_STRING
110b57cec5SDimitry Andric#define _LIBCPP_STRING
120b57cec5SDimitry Andric
130b57cec5SDimitry Andric/*
140b57cec5SDimitry Andric    string synopsis
150b57cec5SDimitry Andric
160b57cec5SDimitry Andricnamespace std
170b57cec5SDimitry Andric{
180b57cec5SDimitry Andric
190b57cec5SDimitry Andrictemplate <class stateT>
200b57cec5SDimitry Andricclass fpos
210b57cec5SDimitry Andric{
220b57cec5SDimitry Andricprivate:
230b57cec5SDimitry Andric    stateT st;
240b57cec5SDimitry Andricpublic:
250b57cec5SDimitry Andric    fpos(streamoff = streamoff());
260b57cec5SDimitry Andric
270b57cec5SDimitry Andric    operator streamoff() const;
280b57cec5SDimitry Andric
290b57cec5SDimitry Andric    stateT state() const;
300b57cec5SDimitry Andric    void state(stateT);
310b57cec5SDimitry Andric
320b57cec5SDimitry Andric    fpos& operator+=(streamoff);
330b57cec5SDimitry Andric    fpos  operator+ (streamoff) const;
340b57cec5SDimitry Andric    fpos& operator-=(streamoff);
350b57cec5SDimitry Andric    fpos  operator- (streamoff) const;
360b57cec5SDimitry Andric};
370b57cec5SDimitry Andric
380b57cec5SDimitry Andrictemplate <class stateT> streamoff operator-(const fpos<stateT>& x, const fpos<stateT>& y);
390b57cec5SDimitry Andric
400b57cec5SDimitry Andrictemplate <class stateT> bool operator==(const fpos<stateT>& x, const fpos<stateT>& y);
410b57cec5SDimitry Andrictemplate <class stateT> bool operator!=(const fpos<stateT>& x, const fpos<stateT>& y);
420b57cec5SDimitry Andric
430b57cec5SDimitry Andrictemplate <class charT>
440b57cec5SDimitry Andricstruct char_traits
450b57cec5SDimitry Andric{
460b57cec5SDimitry Andric    typedef charT     char_type;
470b57cec5SDimitry Andric    typedef ...       int_type;
480b57cec5SDimitry Andric    typedef streamoff off_type;
490b57cec5SDimitry Andric    typedef streampos pos_type;
500b57cec5SDimitry Andric    typedef mbstate_t state_type;
510b57cec5SDimitry Andric
520b57cec5SDimitry Andric    static void assign(char_type& c1, const char_type& c2) noexcept;
530b57cec5SDimitry Andric    static constexpr bool eq(char_type c1, char_type c2) noexcept;
540b57cec5SDimitry Andric    static constexpr bool lt(char_type c1, char_type c2) noexcept;
550b57cec5SDimitry Andric
560b57cec5SDimitry Andric    static int              compare(const char_type* s1, const char_type* s2, size_t n);
570b57cec5SDimitry Andric    static size_t           length(const char_type* s);
580b57cec5SDimitry Andric    static const char_type* find(const char_type* s, size_t n, const char_type& a);
590b57cec5SDimitry Andric    static char_type*       move(char_type* s1, const char_type* s2, size_t n);
600b57cec5SDimitry Andric    static char_type*       copy(char_type* s1, const char_type* s2, size_t n);
610b57cec5SDimitry Andric    static char_type*       assign(char_type* s, size_t n, char_type a);
620b57cec5SDimitry Andric
630b57cec5SDimitry Andric    static constexpr int_type  not_eof(int_type c) noexcept;
640b57cec5SDimitry Andric    static constexpr char_type to_char_type(int_type c) noexcept;
650b57cec5SDimitry Andric    static constexpr int_type  to_int_type(char_type c) noexcept;
660b57cec5SDimitry Andric    static constexpr bool      eq_int_type(int_type c1, int_type c2) noexcept;
670b57cec5SDimitry Andric    static constexpr int_type  eof() noexcept;
680b57cec5SDimitry Andric};
690b57cec5SDimitry Andric
700b57cec5SDimitry Andrictemplate <> struct char_traits<char>;
710b57cec5SDimitry Andrictemplate <> struct char_traits<wchar_t>;
720b57cec5SDimitry Andric
730b57cec5SDimitry Andrictemplate<class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> >
740b57cec5SDimitry Andricclass basic_string
750b57cec5SDimitry Andric{
760b57cec5SDimitry Andricpublic:
770b57cec5SDimitry Andric// types:
780b57cec5SDimitry Andric    typedef traits traits_type;
790b57cec5SDimitry Andric    typedef typename traits_type::char_type value_type;
800b57cec5SDimitry Andric    typedef Allocator allocator_type;
810b57cec5SDimitry Andric    typedef typename allocator_type::size_type size_type;
820b57cec5SDimitry Andric    typedef typename allocator_type::difference_type difference_type;
830b57cec5SDimitry Andric    typedef typename allocator_type::reference reference;
840b57cec5SDimitry Andric    typedef typename allocator_type::const_reference const_reference;
850b57cec5SDimitry Andric    typedef typename allocator_type::pointer pointer;
860b57cec5SDimitry Andric    typedef typename allocator_type::const_pointer const_pointer;
870b57cec5SDimitry Andric    typedef implementation-defined iterator;
880b57cec5SDimitry Andric    typedef implementation-defined const_iterator;
890b57cec5SDimitry Andric    typedef std::reverse_iterator<iterator> reverse_iterator;
900b57cec5SDimitry Andric    typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
910b57cec5SDimitry Andric
920b57cec5SDimitry Andric    static const size_type npos = -1;
930b57cec5SDimitry Andric
940b57cec5SDimitry Andric    basic_string()
950b57cec5SDimitry Andric        noexcept(is_nothrow_default_constructible<allocator_type>::value);
960b57cec5SDimitry Andric    explicit basic_string(const allocator_type& a);
970b57cec5SDimitry Andric    basic_string(const basic_string& str);
980b57cec5SDimitry Andric    basic_string(basic_string&& str)
990b57cec5SDimitry Andric        noexcept(is_nothrow_move_constructible<allocator_type>::value);
1000b57cec5SDimitry Andric    basic_string(const basic_string& str, size_type pos,
1010b57cec5SDimitry Andric                 const allocator_type& a = allocator_type());
1020b57cec5SDimitry Andric    basic_string(const basic_string& str, size_type pos, size_type n,
1030b57cec5SDimitry Andric                 const Allocator& a = Allocator());
1040b57cec5SDimitry Andric    template<class T>
1050b57cec5SDimitry Andric        basic_string(const T& t, size_type pos, size_type n, const Allocator& a = Allocator()); // C++17
1060b57cec5SDimitry Andric    template <class T>
1070b57cec5SDimitry Andric        explicit basic_string(const T& t, const Allocator& a = Allocator()); // C++17
1080b57cec5SDimitry Andric    basic_string(const value_type* s, const allocator_type& a = allocator_type());
1090b57cec5SDimitry Andric    basic_string(const value_type* s, size_type n, const allocator_type& a = allocator_type());
1100b57cec5SDimitry Andric    basic_string(size_type n, value_type c, const allocator_type& a = allocator_type());
1110b57cec5SDimitry Andric    template<class InputIterator>
1120b57cec5SDimitry Andric        basic_string(InputIterator begin, InputIterator end,
1130b57cec5SDimitry Andric                     const allocator_type& a = allocator_type());
1140b57cec5SDimitry Andric    basic_string(initializer_list<value_type>, const Allocator& = Allocator());
1150b57cec5SDimitry Andric    basic_string(const basic_string&, const Allocator&);
1160b57cec5SDimitry Andric    basic_string(basic_string&&, const Allocator&);
1170b57cec5SDimitry Andric
1180b57cec5SDimitry Andric    ~basic_string();
1190b57cec5SDimitry Andric
1200b57cec5SDimitry Andric    operator basic_string_view<charT, traits>() const noexcept;
1210b57cec5SDimitry Andric
1220b57cec5SDimitry Andric    basic_string& operator=(const basic_string& str);
1230b57cec5SDimitry Andric    template <class T>
1240b57cec5SDimitry Andric        basic_string& operator=(const T& t); // C++17
1250b57cec5SDimitry Andric    basic_string& operator=(basic_string&& str)
1260b57cec5SDimitry Andric        noexcept(
1270b57cec5SDimitry Andric             allocator_type::propagate_on_container_move_assignment::value ||
1280b57cec5SDimitry Andric             allocator_type::is_always_equal::value ); // C++17
1290b57cec5SDimitry Andric    basic_string& operator=(const value_type* s);
1300b57cec5SDimitry Andric    basic_string& operator=(value_type c);
1310b57cec5SDimitry Andric    basic_string& operator=(initializer_list<value_type>);
1320b57cec5SDimitry Andric
1330b57cec5SDimitry Andric    iterator       begin() noexcept;
1340b57cec5SDimitry Andric    const_iterator begin() const noexcept;
1350b57cec5SDimitry Andric    iterator       end() noexcept;
1360b57cec5SDimitry Andric    const_iterator end() const noexcept;
1370b57cec5SDimitry Andric
1380b57cec5SDimitry Andric    reverse_iterator       rbegin() noexcept;
1390b57cec5SDimitry Andric    const_reverse_iterator rbegin() const noexcept;
1400b57cec5SDimitry Andric    reverse_iterator       rend() noexcept;
1410b57cec5SDimitry Andric    const_reverse_iterator rend() const noexcept;
1420b57cec5SDimitry Andric
1430b57cec5SDimitry Andric    const_iterator         cbegin() const noexcept;
1440b57cec5SDimitry Andric    const_iterator         cend() const noexcept;
1450b57cec5SDimitry Andric    const_reverse_iterator crbegin() const noexcept;
1460b57cec5SDimitry Andric    const_reverse_iterator crend() const noexcept;
1470b57cec5SDimitry Andric
1480b57cec5SDimitry Andric    size_type size() const noexcept;
1490b57cec5SDimitry Andric    size_type length() const noexcept;
1500b57cec5SDimitry Andric    size_type max_size() const noexcept;
1510b57cec5SDimitry Andric    size_type capacity() const noexcept;
1520b57cec5SDimitry Andric
1530b57cec5SDimitry Andric    void resize(size_type n, value_type c);
1540b57cec5SDimitry Andric    void resize(size_type n);
1550b57cec5SDimitry Andric
1560b57cec5SDimitry Andric    void reserve(size_type res_arg = 0);
1570b57cec5SDimitry Andric    void shrink_to_fit();
1580b57cec5SDimitry Andric    void clear() noexcept;
1590b57cec5SDimitry Andric    bool empty() const noexcept;
1600b57cec5SDimitry Andric
1610b57cec5SDimitry Andric    const_reference operator[](size_type pos) const;
1620b57cec5SDimitry Andric    reference       operator[](size_type pos);
1630b57cec5SDimitry Andric
1640b57cec5SDimitry Andric    const_reference at(size_type n) const;
1650b57cec5SDimitry Andric    reference       at(size_type n);
1660b57cec5SDimitry Andric
1670b57cec5SDimitry Andric    basic_string& operator+=(const basic_string& str);
1680b57cec5SDimitry Andric    template <class T>
1690b57cec5SDimitry Andric        basic_string& operator+=(const T& t);              // C++17
1700b57cec5SDimitry Andric    basic_string& operator+=(const value_type* s);
1710b57cec5SDimitry Andric    basic_string& operator+=(value_type c);
1720b57cec5SDimitry Andric    basic_string& operator+=(initializer_list<value_type>);
1730b57cec5SDimitry Andric
1740b57cec5SDimitry Andric    basic_string& append(const basic_string& str);
1750b57cec5SDimitry Andric    template <class T>
1760b57cec5SDimitry Andric        basic_string& append(const T& t);                 // C++17
1770b57cec5SDimitry Andric    basic_string& append(const basic_string& str, size_type pos, size_type n=npos); //C++14
1780b57cec5SDimitry Andric    template <class T>
1790b57cec5SDimitry Andric        basic_string& append(const T& t, size_type pos, size_type n=npos); // C++17
1800b57cec5SDimitry Andric    basic_string& append(const value_type* s, size_type n);
1810b57cec5SDimitry Andric    basic_string& append(const value_type* s);
1820b57cec5SDimitry Andric    basic_string& append(size_type n, value_type c);
1830b57cec5SDimitry Andric    template<class InputIterator>
1840b57cec5SDimitry Andric        basic_string& append(InputIterator first, InputIterator last);
1850b57cec5SDimitry Andric    basic_string& append(initializer_list<value_type>);
1860b57cec5SDimitry Andric
1870b57cec5SDimitry Andric    void push_back(value_type c);
1880b57cec5SDimitry Andric    void pop_back();
1890b57cec5SDimitry Andric    reference       front();
1900b57cec5SDimitry Andric    const_reference front() const;
1910b57cec5SDimitry Andric    reference       back();
1920b57cec5SDimitry Andric    const_reference back() const;
1930b57cec5SDimitry Andric
1940b57cec5SDimitry Andric    basic_string& assign(const basic_string& str);
1950b57cec5SDimitry Andric    template <class T>
1960b57cec5SDimitry Andric        basic_string& assign(const T& t);  // C++17
1970b57cec5SDimitry Andric    basic_string& assign(basic_string&& str);
1980b57cec5SDimitry Andric    basic_string& assign(const basic_string& str, size_type pos, size_type n=npos); // C++14
1990b57cec5SDimitry Andric    template <class T>
2000b57cec5SDimitry Andric        basic_string& assign(const T& t, size_type pos, size_type n=npos); // C++17
2010b57cec5SDimitry Andric    basic_string& assign(const value_type* s, size_type n);
2020b57cec5SDimitry Andric    basic_string& assign(const value_type* s);
2030b57cec5SDimitry Andric    basic_string& assign(size_type n, value_type c);
2040b57cec5SDimitry Andric    template<class InputIterator>
2050b57cec5SDimitry Andric        basic_string& assign(InputIterator first, InputIterator last);
2060b57cec5SDimitry Andric    basic_string& assign(initializer_list<value_type>);
2070b57cec5SDimitry Andric
2080b57cec5SDimitry Andric    basic_string& insert(size_type pos1, const basic_string& str);
2090b57cec5SDimitry Andric    template <class T>
2100b57cec5SDimitry Andric        basic_string& insert(size_type pos1, const T& t);
2110b57cec5SDimitry Andric    basic_string& insert(size_type pos1, const basic_string& str,
2120b57cec5SDimitry Andric                         size_type pos2, size_type n);
2130b57cec5SDimitry Andric    template <class T>
2140b57cec5SDimitry Andric        basic_string& insert(size_type pos1, const T& t, size_type pos2, size_type n); // C++17
2150b57cec5SDimitry Andric    basic_string& insert(size_type pos, const value_type* s, size_type n=npos); //C++14
2160b57cec5SDimitry Andric    basic_string& insert(size_type pos, const value_type* s);
2170b57cec5SDimitry Andric    basic_string& insert(size_type pos, size_type n, value_type c);
2180b57cec5SDimitry Andric    iterator      insert(const_iterator p, value_type c);
2190b57cec5SDimitry Andric    iterator      insert(const_iterator p, size_type n, value_type c);
2200b57cec5SDimitry Andric    template<class InputIterator>
2210b57cec5SDimitry Andric        iterator insert(const_iterator p, InputIterator first, InputIterator last);
2220b57cec5SDimitry Andric    iterator      insert(const_iterator p, initializer_list<value_type>);
2230b57cec5SDimitry Andric
2240b57cec5SDimitry Andric    basic_string& erase(size_type pos = 0, size_type n = npos);
2250b57cec5SDimitry Andric    iterator      erase(const_iterator position);
2260b57cec5SDimitry Andric    iterator      erase(const_iterator first, const_iterator last);
2270b57cec5SDimitry Andric
2280b57cec5SDimitry Andric    basic_string& replace(size_type pos1, size_type n1, const basic_string& str);
2290b57cec5SDimitry Andric    template <class T>
2300b57cec5SDimitry Andric    basic_string& replace(size_type pos1, size_type n1, const T& t);  // C++17
2310b57cec5SDimitry Andric    basic_string& replace(size_type pos1, size_type n1, const basic_string& str,
2320b57cec5SDimitry Andric                          size_type pos2, size_type n2=npos); // C++14
2330b57cec5SDimitry Andric    template <class T>
2340b57cec5SDimitry Andric        basic_string& replace(size_type pos1, size_type n1, const T& t,
2350b57cec5SDimitry Andric                              size_type pos2, size_type n); // C++17
2360b57cec5SDimitry Andric    basic_string& replace(size_type pos, size_type n1, const value_type* s, size_type n2);
2370b57cec5SDimitry Andric    basic_string& replace(size_type pos, size_type n1, const value_type* s);
2380b57cec5SDimitry Andric    basic_string& replace(size_type pos, size_type n1, size_type n2, value_type c);
2390b57cec5SDimitry Andric    basic_string& replace(const_iterator i1, const_iterator i2, const basic_string& str);
2400b57cec5SDimitry Andric    template <class T>
2410b57cec5SDimitry Andric        basic_string& replace(const_iterator i1, const_iterator i2, const T& t);  // C++17
2420b57cec5SDimitry Andric    basic_string& replace(const_iterator i1, const_iterator i2, const value_type* s, size_type n);
2430b57cec5SDimitry Andric    basic_string& replace(const_iterator i1, const_iterator i2, const value_type* s);
2440b57cec5SDimitry Andric    basic_string& replace(const_iterator i1, const_iterator i2, size_type n, value_type c);
2450b57cec5SDimitry Andric    template<class InputIterator>
2460b57cec5SDimitry Andric        basic_string& replace(const_iterator i1, const_iterator i2, InputIterator j1, InputIterator j2);
2470b57cec5SDimitry Andric    basic_string& replace(const_iterator i1, const_iterator i2, initializer_list<value_type>);
2480b57cec5SDimitry Andric
2490b57cec5SDimitry Andric    size_type copy(value_type* s, size_type n, size_type pos = 0) const;
2500b57cec5SDimitry Andric    basic_string substr(size_type pos = 0, size_type n = npos) const;
2510b57cec5SDimitry Andric
2520b57cec5SDimitry Andric    void swap(basic_string& str)
2530b57cec5SDimitry Andric        noexcept(allocator_traits<allocator_type>::propagate_on_container_swap::value ||
2540b57cec5SDimitry Andric                 allocator_traits<allocator_type>::is_always_equal::value);  // C++17
2550b57cec5SDimitry Andric
2560b57cec5SDimitry Andric    const value_type* c_str() const noexcept;
2570b57cec5SDimitry Andric    const value_type* data() const noexcept;
2580b57cec5SDimitry Andric          value_type* data()       noexcept;   // C++17
2590b57cec5SDimitry Andric
2600b57cec5SDimitry Andric    allocator_type get_allocator() const noexcept;
2610b57cec5SDimitry Andric
2620b57cec5SDimitry Andric    size_type find(const basic_string& str, size_type pos = 0) const noexcept;
2630b57cec5SDimitry Andric    template <class T>
2640b57cec5SDimitry Andric        size_type find(const T& t, size_type pos = 0) const;  // C++17
2650b57cec5SDimitry Andric    size_type find(const value_type* s, size_type pos, size_type n) const noexcept;
2660b57cec5SDimitry Andric    size_type find(const value_type* s, size_type pos = 0) const noexcept;
2670b57cec5SDimitry Andric    size_type find(value_type c, size_type pos = 0) const noexcept;
2680b57cec5SDimitry Andric
2690b57cec5SDimitry Andric    size_type rfind(const basic_string& str, size_type pos = npos) const noexcept;
2700b57cec5SDimitry Andric    template <class T>
2710b57cec5SDimitry Andric        size_type rfind(const T& t, size_type pos = npos) const;  // C++17
2720b57cec5SDimitry Andric    size_type rfind(const value_type* s, size_type pos, size_type n) const noexcept;
2730b57cec5SDimitry Andric    size_type rfind(const value_type* s, size_type pos = npos) const noexcept;
2740b57cec5SDimitry Andric    size_type rfind(value_type c, size_type pos = npos) const noexcept;
2750b57cec5SDimitry Andric
2760b57cec5SDimitry Andric    size_type find_first_of(const basic_string& str, size_type pos = 0) const noexcept;
2770b57cec5SDimitry Andric    template <class T>
2780b57cec5SDimitry Andric        size_type find_first_of(const T& t, size_type pos = 0) const; // C++17
2790b57cec5SDimitry Andric    size_type find_first_of(const value_type* s, size_type pos, size_type n) const noexcept;
2800b57cec5SDimitry Andric    size_type find_first_of(const value_type* s, size_type pos = 0) const noexcept;
2810b57cec5SDimitry Andric    size_type find_first_of(value_type c, size_type pos = 0) const noexcept;
2820b57cec5SDimitry Andric
2830b57cec5SDimitry Andric    size_type find_last_of(const basic_string& str, size_type pos = npos) const noexcept;
2840b57cec5SDimitry Andric    template <class T>
2850b57cec5SDimitry Andric        size_type find_last_of(const T& t, size_type pos = npos) const noexcept;  // C++17
2860b57cec5SDimitry Andric    size_type find_last_of(const value_type* s, size_type pos, size_type n) const noexcept;
2870b57cec5SDimitry Andric    size_type find_last_of(const value_type* s, size_type pos = npos) const noexcept;
2880b57cec5SDimitry Andric    size_type find_last_of(value_type c, size_type pos = npos) const noexcept;
2890b57cec5SDimitry Andric
2900b57cec5SDimitry Andric    size_type find_first_not_of(const basic_string& str, size_type pos = 0) const noexcept;
2910b57cec5SDimitry Andric    template <class T>
2920b57cec5SDimitry Andric        size_type find_first_not_of(const T& t, size_type pos = 0) const; // C++17
2930b57cec5SDimitry Andric    size_type find_first_not_of(const value_type* s, size_type pos, size_type n) const noexcept;
2940b57cec5SDimitry Andric    size_type find_first_not_of(const value_type* s, size_type pos = 0) const noexcept;
2950b57cec5SDimitry Andric    size_type find_first_not_of(value_type c, size_type pos = 0) const noexcept;
2960b57cec5SDimitry Andric
2970b57cec5SDimitry Andric    size_type find_last_not_of(const basic_string& str, size_type pos = npos) const noexcept;
2980b57cec5SDimitry Andric    template <class T>
2990b57cec5SDimitry Andric        size_type find_last_not_of(const T& t, size_type pos = npos) const; // C++17
3000b57cec5SDimitry Andric    size_type find_last_not_of(const value_type* s, size_type pos, size_type n) const noexcept;
3010b57cec5SDimitry Andric    size_type find_last_not_of(const value_type* s, size_type pos = npos) const noexcept;
3020b57cec5SDimitry Andric    size_type find_last_not_of(value_type c, size_type pos = npos) const noexcept;
3030b57cec5SDimitry Andric
3040b57cec5SDimitry Andric    int compare(const basic_string& str) const noexcept;
3050b57cec5SDimitry Andric    template <class T>
3060b57cec5SDimitry Andric        int compare(const T& t) const noexcept;  // C++17
3070b57cec5SDimitry Andric    int compare(size_type pos1, size_type n1, const basic_string& str) const;
3080b57cec5SDimitry Andric    template <class T>
3090b57cec5SDimitry Andric        int compare(size_type pos1, size_type n1, const T& t) const;  // C++17
3100b57cec5SDimitry Andric    int compare(size_type pos1, size_type n1, const basic_string& str,
3110b57cec5SDimitry Andric                size_type pos2, size_type n2=npos) const; // C++14
3120b57cec5SDimitry Andric    template <class T>
3130b57cec5SDimitry Andric        int compare(size_type pos1, size_type n1, const T& t,
3140b57cec5SDimitry Andric                    size_type pos2, size_type n2=npos) const; // C++17
3150b57cec5SDimitry Andric    int compare(const value_type* s) const noexcept;
3160b57cec5SDimitry Andric    int compare(size_type pos1, size_type n1, const value_type* s) const;
3170b57cec5SDimitry Andric    int compare(size_type pos1, size_type n1, const value_type* s, size_type n2) const;
3180b57cec5SDimitry Andric
3190b57cec5SDimitry Andric    bool starts_with(basic_string_view<charT, traits> sv) const noexcept; // C++2a
3200b57cec5SDimitry Andric    bool starts_with(charT c) const noexcept;                             // C++2a
3210b57cec5SDimitry Andric    bool starts_with(const charT* s) const;                               // C++2a
3220b57cec5SDimitry Andric    bool ends_with(basic_string_view<charT, traits> sv) const noexcept;   // C++2a
3230b57cec5SDimitry Andric    bool ends_with(charT c) const noexcept;                               // C++2a
3240b57cec5SDimitry Andric    bool ends_with(const charT* s) const;                                 // C++2a
3250b57cec5SDimitry Andric
3260b57cec5SDimitry Andric    bool __invariants() const;
3270b57cec5SDimitry Andric};
3280b57cec5SDimitry Andric
3290b57cec5SDimitry Andrictemplate<class InputIterator,
3300b57cec5SDimitry Andric         class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>>
3310b57cec5SDimitry Andricbasic_string(InputIterator, InputIterator, Allocator = Allocator())
3320b57cec5SDimitry Andric   -> basic_string<typename iterator_traits<InputIterator>::value_type,
3330b57cec5SDimitry Andric                  char_traits<typename iterator_traits<InputIterator>::value_type>,
3340b57cec5SDimitry Andric                  Allocator>;   // C++17
3350b57cec5SDimitry Andric
3360b57cec5SDimitry Andrictemplate<class charT, class traits, class Allocator>
3370b57cec5SDimitry Andricbasic_string<charT, traits, Allocator>
3380b57cec5SDimitry Andricoperator+(const basic_string<charT, traits, Allocator>& lhs,
3390b57cec5SDimitry Andric          const basic_string<charT, traits, Allocator>& rhs);
3400b57cec5SDimitry Andric
3410b57cec5SDimitry Andrictemplate<class charT, class traits, class Allocator>
3420b57cec5SDimitry Andricbasic_string<charT, traits, Allocator>
3430b57cec5SDimitry Andricoperator+(const charT* lhs , const basic_string<charT,traits,Allocator>&rhs);
3440b57cec5SDimitry Andric
3450b57cec5SDimitry Andrictemplate<class charT, class traits, class Allocator>
3460b57cec5SDimitry Andricbasic_string<charT, traits, Allocator>
3470b57cec5SDimitry Andricoperator+(charT lhs, const basic_string<charT,traits,Allocator>& rhs);
3480b57cec5SDimitry Andric
3490b57cec5SDimitry Andrictemplate<class charT, class traits, class Allocator>
3500b57cec5SDimitry Andricbasic_string<charT, traits, Allocator>
3510b57cec5SDimitry Andricoperator+(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs);
3520b57cec5SDimitry Andric
3530b57cec5SDimitry Andrictemplate<class charT, class traits, class Allocator>
3540b57cec5SDimitry Andricbasic_string<charT, traits, Allocator>
3550b57cec5SDimitry Andricoperator+(const basic_string<charT, traits, Allocator>& lhs, charT rhs);
3560b57cec5SDimitry Andric
3570b57cec5SDimitry Andrictemplate<class charT, class traits, class Allocator>
3580b57cec5SDimitry Andricbool operator==(const basic_string<charT, traits, Allocator>& lhs,
3590b57cec5SDimitry Andric                const basic_string<charT, traits, Allocator>& rhs) noexcept;
3600b57cec5SDimitry Andric
3610b57cec5SDimitry Andrictemplate<class charT, class traits, class Allocator>
3620b57cec5SDimitry Andricbool operator==(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
3630b57cec5SDimitry Andric
3640b57cec5SDimitry Andrictemplate<class charT, class traits, class Allocator>
3650b57cec5SDimitry Andricbool operator==(const basic_string<charT,traits,Allocator>& lhs, const charT* rhs) noexcept;
3660b57cec5SDimitry Andric
3670b57cec5SDimitry Andrictemplate<class charT, class traits, class Allocator>
3680b57cec5SDimitry Andricbool operator!=(const basic_string<charT,traits,Allocator>& lhs,
3690b57cec5SDimitry Andric                const basic_string<charT, traits, Allocator>& rhs) noexcept;
3700b57cec5SDimitry Andric
3710b57cec5SDimitry Andrictemplate<class charT, class traits, class Allocator>
3720b57cec5SDimitry Andricbool operator!=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
3730b57cec5SDimitry Andric
3740b57cec5SDimitry Andrictemplate<class charT, class traits, class Allocator>
3750b57cec5SDimitry Andricbool operator!=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
3760b57cec5SDimitry Andric
3770b57cec5SDimitry Andrictemplate<class charT, class traits, class Allocator>
3780b57cec5SDimitry Andricbool operator< (const basic_string<charT, traits, Allocator>& lhs,
3790b57cec5SDimitry Andric                const basic_string<charT, traits, Allocator>& rhs) noexcept;
3800b57cec5SDimitry Andric
3810b57cec5SDimitry Andrictemplate<class charT, class traits, class Allocator>
3820b57cec5SDimitry Andricbool operator< (const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
3830b57cec5SDimitry Andric
3840b57cec5SDimitry Andrictemplate<class charT, class traits, class Allocator>
3850b57cec5SDimitry Andricbool operator< (const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
3860b57cec5SDimitry Andric
3870b57cec5SDimitry Andrictemplate<class charT, class traits, class Allocator>
3880b57cec5SDimitry Andricbool operator> (const basic_string<charT, traits, Allocator>& lhs,
3890b57cec5SDimitry Andric                const basic_string<charT, traits, Allocator>& rhs) noexcept;
3900b57cec5SDimitry Andric
3910b57cec5SDimitry Andrictemplate<class charT, class traits, class Allocator>
3920b57cec5SDimitry Andricbool operator> (const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
3930b57cec5SDimitry Andric
3940b57cec5SDimitry Andrictemplate<class charT, class traits, class Allocator>
3950b57cec5SDimitry Andricbool operator> (const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
3960b57cec5SDimitry Andric
3970b57cec5SDimitry Andrictemplate<class charT, class traits, class Allocator>
3980b57cec5SDimitry Andricbool operator<=(const basic_string<charT, traits, Allocator>& lhs,
3990b57cec5SDimitry Andric                const basic_string<charT, traits, Allocator>& rhs) noexcept;
4000b57cec5SDimitry Andric
4010b57cec5SDimitry Andrictemplate<class charT, class traits, class Allocator>
4020b57cec5SDimitry Andricbool operator<=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
4030b57cec5SDimitry Andric
4040b57cec5SDimitry Andrictemplate<class charT, class traits, class Allocator>
4050b57cec5SDimitry Andricbool operator<=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
4060b57cec5SDimitry Andric
4070b57cec5SDimitry Andrictemplate<class charT, class traits, class Allocator>
4080b57cec5SDimitry Andricbool operator>=(const basic_string<charT, traits, Allocator>& lhs,
4090b57cec5SDimitry Andric                const basic_string<charT, traits, Allocator>& rhs) noexcept;
4100b57cec5SDimitry Andric
4110b57cec5SDimitry Andrictemplate<class charT, class traits, class Allocator>
4120b57cec5SDimitry Andricbool operator>=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
4130b57cec5SDimitry Andric
4140b57cec5SDimitry Andrictemplate<class charT, class traits, class Allocator>
4150b57cec5SDimitry Andricbool operator>=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
4160b57cec5SDimitry Andric
4170b57cec5SDimitry Andrictemplate<class charT, class traits, class Allocator>
4180b57cec5SDimitry Andricvoid swap(basic_string<charT, traits, Allocator>& lhs,
4190b57cec5SDimitry Andric          basic_string<charT, traits, Allocator>& rhs)
4200b57cec5SDimitry Andric            noexcept(noexcept(lhs.swap(rhs)));
4210b57cec5SDimitry Andric
4220b57cec5SDimitry Andrictemplate<class charT, class traits, class Allocator>
4230b57cec5SDimitry Andricbasic_istream<charT, traits>&
4240b57cec5SDimitry Andricoperator>>(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str);
4250b57cec5SDimitry Andric
4260b57cec5SDimitry Andrictemplate<class charT, class traits, class Allocator>
4270b57cec5SDimitry Andricbasic_ostream<charT, traits>&
4280b57cec5SDimitry Andricoperator<<(basic_ostream<charT, traits>& os, const basic_string<charT, traits, Allocator>& str);
4290b57cec5SDimitry Andric
4300b57cec5SDimitry Andrictemplate<class charT, class traits, class Allocator>
4310b57cec5SDimitry Andricbasic_istream<charT, traits>&
4320b57cec5SDimitry Andricgetline(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str,
4330b57cec5SDimitry Andric        charT delim);
4340b57cec5SDimitry Andric
4350b57cec5SDimitry Andrictemplate<class charT, class traits, class Allocator>
4360b57cec5SDimitry Andricbasic_istream<charT, traits>&
4370b57cec5SDimitry Andricgetline(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str);
4380b57cec5SDimitry Andric
4390b57cec5SDimitry Andrictemplate<class charT, class traits, class Allocator, class U>
440*5ffd83dbSDimitry Andrictypename basic_string<charT, traits, Allocator>::size_type
441*5ffd83dbSDimitry Andricerase(basic_string<charT, traits, Allocator>& c, const U& value);    // C++20
4420b57cec5SDimitry Andrictemplate<class charT, class traits, class Allocator, class Predicate>
443*5ffd83dbSDimitry Andrictypename basic_string<charT, traits, Allocator>::size_type
444*5ffd83dbSDimitry Andricerase_if(basic_string<charT, traits, Allocator>& c, Predicate pred); // C++20
4450b57cec5SDimitry Andric
4460b57cec5SDimitry Andrictypedef basic_string<char>    string;
4470b57cec5SDimitry Andrictypedef basic_string<wchar_t> wstring;
4480b57cec5SDimitry Andrictypedef basic_string<char16_t> u16string;
4490b57cec5SDimitry Andrictypedef basic_string<char32_t> u32string;
4500b57cec5SDimitry Andric
4510b57cec5SDimitry Andricint                stoi  (const string& str, size_t* idx = 0, int base = 10);
4520b57cec5SDimitry Andriclong               stol  (const string& str, size_t* idx = 0, int base = 10);
4530b57cec5SDimitry Andricunsigned long      stoul (const string& str, size_t* idx = 0, int base = 10);
4540b57cec5SDimitry Andriclong long          stoll (const string& str, size_t* idx = 0, int base = 10);
4550b57cec5SDimitry Andricunsigned long long stoull(const string& str, size_t* idx = 0, int base = 10);
4560b57cec5SDimitry Andric
4570b57cec5SDimitry Andricfloat       stof (const string& str, size_t* idx = 0);
4580b57cec5SDimitry Andricdouble      stod (const string& str, size_t* idx = 0);
4590b57cec5SDimitry Andriclong double stold(const string& str, size_t* idx = 0);
4600b57cec5SDimitry Andric
4610b57cec5SDimitry Andricstring to_string(int val);
4620b57cec5SDimitry Andricstring to_string(unsigned val);
4630b57cec5SDimitry Andricstring to_string(long val);
4640b57cec5SDimitry Andricstring to_string(unsigned long val);
4650b57cec5SDimitry Andricstring to_string(long long val);
4660b57cec5SDimitry Andricstring to_string(unsigned long long val);
4670b57cec5SDimitry Andricstring to_string(float val);
4680b57cec5SDimitry Andricstring to_string(double val);
4690b57cec5SDimitry Andricstring to_string(long double val);
4700b57cec5SDimitry Andric
4710b57cec5SDimitry Andricint                stoi  (const wstring& str, size_t* idx = 0, int base = 10);
4720b57cec5SDimitry Andriclong               stol  (const wstring& str, size_t* idx = 0, int base = 10);
4730b57cec5SDimitry Andricunsigned long      stoul (const wstring& str, size_t* idx = 0, int base = 10);
4740b57cec5SDimitry Andriclong long          stoll (const wstring& str, size_t* idx = 0, int base = 10);
4750b57cec5SDimitry Andricunsigned long long stoull(const wstring& str, size_t* idx = 0, int base = 10);
4760b57cec5SDimitry Andric
4770b57cec5SDimitry Andricfloat       stof (const wstring& str, size_t* idx = 0);
4780b57cec5SDimitry Andricdouble      stod (const wstring& str, size_t* idx = 0);
4790b57cec5SDimitry Andriclong double stold(const wstring& str, size_t* idx = 0);
4800b57cec5SDimitry Andric
4810b57cec5SDimitry Andricwstring to_wstring(int val);
4820b57cec5SDimitry Andricwstring to_wstring(unsigned val);
4830b57cec5SDimitry Andricwstring to_wstring(long val);
4840b57cec5SDimitry Andricwstring to_wstring(unsigned long val);
4850b57cec5SDimitry Andricwstring to_wstring(long long val);
4860b57cec5SDimitry Andricwstring to_wstring(unsigned long long val);
4870b57cec5SDimitry Andricwstring to_wstring(float val);
4880b57cec5SDimitry Andricwstring to_wstring(double val);
4890b57cec5SDimitry Andricwstring to_wstring(long double val);
4900b57cec5SDimitry Andric
4910b57cec5SDimitry Andrictemplate <> struct hash<string>;
4920b57cec5SDimitry Andrictemplate <> struct hash<u16string>;
4930b57cec5SDimitry Andrictemplate <> struct hash<u32string>;
4940b57cec5SDimitry Andrictemplate <> struct hash<wstring>;
4950b57cec5SDimitry Andric
4960b57cec5SDimitry Andricbasic_string<char>     operator "" s( const char *str,     size_t len ); // C++14
4970b57cec5SDimitry Andricbasic_string<wchar_t>  operator "" s( const wchar_t *str,  size_t len ); // C++14
4980b57cec5SDimitry Andricbasic_string<char16_t> operator "" s( const char16_t *str, size_t len ); // C++14
4990b57cec5SDimitry Andricbasic_string<char32_t> operator "" s( const char32_t *str, size_t len ); // C++14
5000b57cec5SDimitry Andric
5010b57cec5SDimitry Andric}  // std
5020b57cec5SDimitry Andric
5030b57cec5SDimitry Andric*/
5040b57cec5SDimitry Andric
5050b57cec5SDimitry Andric#include <__config>
5060b57cec5SDimitry Andric#include <string_view>
5070b57cec5SDimitry Andric#include <iosfwd>
5080b57cec5SDimitry Andric#include <cstring>
5090b57cec5SDimitry Andric#include <cstdio>  // For EOF.
5100b57cec5SDimitry Andric#include <cwchar>
5110b57cec5SDimitry Andric#include <algorithm>
5120b57cec5SDimitry Andric#include <iterator>
5130b57cec5SDimitry Andric#include <utility>
5140b57cec5SDimitry Andric#include <memory>
5150b57cec5SDimitry Andric#include <stdexcept>
5160b57cec5SDimitry Andric#include <type_traits>
5170b57cec5SDimitry Andric#include <initializer_list>
5180b57cec5SDimitry Andric#include <__functional_base>
5190b57cec5SDimitry Andric#include <version>
5200b57cec5SDimitry Andric#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
5210b57cec5SDimitry Andric#include <cstdint>
5220b57cec5SDimitry Andric#endif
5230b57cec5SDimitry Andric
5240b57cec5SDimitry Andric#include <__debug>
5250b57cec5SDimitry Andric
5260b57cec5SDimitry Andric#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
5270b57cec5SDimitry Andric#pragma GCC system_header
5280b57cec5SDimitry Andric#endif
5290b57cec5SDimitry Andric
5300b57cec5SDimitry Andric_LIBCPP_PUSH_MACROS
5310b57cec5SDimitry Andric#include <__undef_macros>
5320b57cec5SDimitry Andric
5330b57cec5SDimitry Andric
5340b57cec5SDimitry Andric_LIBCPP_BEGIN_NAMESPACE_STD
5350b57cec5SDimitry Andric
5360b57cec5SDimitry Andric// fpos
5370b57cec5SDimitry Andric
5380b57cec5SDimitry Andrictemplate <class _StateT>
5390b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS fpos
5400b57cec5SDimitry Andric{
5410b57cec5SDimitry Andricprivate:
5420b57cec5SDimitry Andric    _StateT __st_;
5430b57cec5SDimitry Andric    streamoff __off_;
5440b57cec5SDimitry Andricpublic:
5450b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY fpos(streamoff __off = streamoff()) : __st_(), __off_(__off) {}
5460b57cec5SDimitry Andric
5470b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY operator streamoff() const {return __off_;}
5480b57cec5SDimitry Andric
5490b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _StateT state() const {return __st_;}
5500b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY void state(_StateT __st) {__st_ = __st;}
5510b57cec5SDimitry Andric
5520b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY fpos& operator+=(streamoff __off) {__off_ += __off; return *this;}
5530b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY fpos  operator+ (streamoff __off) const {fpos __t(*this); __t += __off; return __t;}
5540b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY fpos& operator-=(streamoff __off) {__off_ -= __off; return *this;}
5550b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY fpos  operator- (streamoff __off) const {fpos __t(*this); __t -= __off; return __t;}
5560b57cec5SDimitry Andric};
5570b57cec5SDimitry Andric
5580b57cec5SDimitry Andrictemplate <class _StateT>
5590b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
5600b57cec5SDimitry Andricstreamoff operator-(const fpos<_StateT>& __x, const fpos<_StateT>& __y)
5610b57cec5SDimitry Andric    {return streamoff(__x) - streamoff(__y);}
5620b57cec5SDimitry Andric
5630b57cec5SDimitry Andrictemplate <class _StateT>
5640b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
5650b57cec5SDimitry Andricbool operator==(const fpos<_StateT>& __x, const fpos<_StateT>& __y)
5660b57cec5SDimitry Andric    {return streamoff(__x) == streamoff(__y);}
5670b57cec5SDimitry Andric
5680b57cec5SDimitry Andrictemplate <class _StateT>
5690b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
5700b57cec5SDimitry Andricbool operator!=(const fpos<_StateT>& __x, const fpos<_StateT>& __y)
5710b57cec5SDimitry Andric    {return streamoff(__x) != streamoff(__y);}
5720b57cec5SDimitry Andric
5730b57cec5SDimitry Andric// basic_string
5740b57cec5SDimitry Andric
5750b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
5760b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>
5770b57cec5SDimitry Andricoperator+(const basic_string<_CharT, _Traits, _Allocator>& __x,
5780b57cec5SDimitry Andric          const basic_string<_CharT, _Traits, _Allocator>& __y);
5790b57cec5SDimitry Andric
5800b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
5810b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>
5820b57cec5SDimitry Andricoperator+(const _CharT* __x, const basic_string<_CharT,_Traits,_Allocator>& __y);
5830b57cec5SDimitry Andric
5840b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
5850b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>
5860b57cec5SDimitry Andricoperator+(_CharT __x, const basic_string<_CharT,_Traits,_Allocator>& __y);
5870b57cec5SDimitry Andric
5880b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
5890b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
5900b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>
5910b57cec5SDimitry Andricoperator+(const basic_string<_CharT, _Traits, _Allocator>& __x, const _CharT* __y);
5920b57cec5SDimitry Andric
5930b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
5940b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>
5950b57cec5SDimitry Andricoperator+(const basic_string<_CharT, _Traits, _Allocator>& __x, _CharT __y);
5960b57cec5SDimitry Andric
5970b57cec5SDimitry Andric_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS string operator+<char, char_traits<char>, allocator<char> >(char const*, string const&))
5980b57cec5SDimitry Andric
5990b57cec5SDimitry Andrictemplate <bool>
6000b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS __basic_string_common
6010b57cec5SDimitry Andric{
6020b57cec5SDimitry Andricprotected:
6030b57cec5SDimitry Andric    _LIBCPP_NORETURN void __throw_length_error() const;
6040b57cec5SDimitry Andric    _LIBCPP_NORETURN void __throw_out_of_range() const;
6050b57cec5SDimitry Andric};
6060b57cec5SDimitry Andric
6070b57cec5SDimitry Andrictemplate <bool __b>
6080b57cec5SDimitry Andricvoid
6090b57cec5SDimitry Andric__basic_string_common<__b>::__throw_length_error() const
6100b57cec5SDimitry Andric{
6110b57cec5SDimitry Andric    _VSTD::__throw_length_error("basic_string");
6120b57cec5SDimitry Andric}
6130b57cec5SDimitry Andric
6140b57cec5SDimitry Andrictemplate <bool __b>
6150b57cec5SDimitry Andricvoid
6160b57cec5SDimitry Andric__basic_string_common<__b>::__throw_out_of_range() const
6170b57cec5SDimitry Andric{
6180b57cec5SDimitry Andric    _VSTD::__throw_out_of_range("basic_string");
6190b57cec5SDimitry Andric}
6200b57cec5SDimitry Andric
6210b57cec5SDimitry Andric_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __basic_string_common<true>)
6220b57cec5SDimitry Andric
6230b57cec5SDimitry Andric#ifdef _LIBCPP_NO_EXCEPTIONS
6240b57cec5SDimitry Andrictemplate <class _Iter>
6250b57cec5SDimitry Andricstruct __libcpp_string_gets_noexcept_iterator_impl : public true_type {};
6260b57cec5SDimitry Andric#elif defined(_LIBCPP_HAS_NO_NOEXCEPT)
6270b57cec5SDimitry Andrictemplate <class _Iter>
6280b57cec5SDimitry Andricstruct __libcpp_string_gets_noexcept_iterator_impl : public false_type {};
6290b57cec5SDimitry Andric#else
630480093f4SDimitry Andrictemplate <class _Iter, bool = __is_cpp17_forward_iterator<_Iter>::value>
6310b57cec5SDimitry Andricstruct __libcpp_string_gets_noexcept_iterator_impl : public _LIBCPP_BOOL_CONSTANT((
6320b57cec5SDimitry Andric    noexcept(++(declval<_Iter&>())) &&
6330b57cec5SDimitry Andric    is_nothrow_assignable<_Iter&, _Iter>::value &&
6340b57cec5SDimitry Andric    noexcept(declval<_Iter>() == declval<_Iter>()) &&
6350b57cec5SDimitry Andric    noexcept(*declval<_Iter>())
6360b57cec5SDimitry Andric)) {};
6370b57cec5SDimitry Andric
6380b57cec5SDimitry Andrictemplate <class _Iter>
6390b57cec5SDimitry Andricstruct __libcpp_string_gets_noexcept_iterator_impl<_Iter, false> : public false_type {};
6400b57cec5SDimitry Andric#endif
6410b57cec5SDimitry Andric
6420b57cec5SDimitry Andric
6430b57cec5SDimitry Andrictemplate <class _Iter>
6440b57cec5SDimitry Andricstruct __libcpp_string_gets_noexcept_iterator
6450b57cec5SDimitry Andric    : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value || __libcpp_string_gets_noexcept_iterator_impl<_Iter>::value) {};
6460b57cec5SDimitry Andric
6470b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Tp>
648*5ffd83dbSDimitry Andricstruct __can_be_converted_to_string_view : public _BoolConstant<
649*5ffd83dbSDimitry Andric      is_convertible<const _Tp&, basic_string_view<_CharT, _Traits> >::value &&
650*5ffd83dbSDimitry Andric     !is_convertible<const _Tp&, const _CharT*>::value
651*5ffd83dbSDimitry Andric    > {};
6520b57cec5SDimitry Andric
6530b57cec5SDimitry Andric#ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
6540b57cec5SDimitry Andric
6550b57cec5SDimitry Andrictemplate <class _CharT, size_t = sizeof(_CharT)>
6560b57cec5SDimitry Andricstruct __padding
6570b57cec5SDimitry Andric{
6580b57cec5SDimitry Andric    unsigned char __xx[sizeof(_CharT)-1];
6590b57cec5SDimitry Andric};
6600b57cec5SDimitry Andric
6610b57cec5SDimitry Andrictemplate <class _CharT>
6620b57cec5SDimitry Andricstruct __padding<_CharT, 1>
6630b57cec5SDimitry Andric{
6640b57cec5SDimitry Andric};
6650b57cec5SDimitry Andric
6660b57cec5SDimitry Andric#endif  // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
6670b57cec5SDimitry Andric
6680b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
6690b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS basic_string
6700b57cec5SDimitry Andric    : private __basic_string_common<true>
6710b57cec5SDimitry Andric{
6720b57cec5SDimitry Andricpublic:
6730b57cec5SDimitry Andric    typedef basic_string                                 __self;
6740b57cec5SDimitry Andric    typedef basic_string_view<_CharT, _Traits>           __self_view;
6750b57cec5SDimitry Andric    typedef _Traits                                      traits_type;
6760b57cec5SDimitry Andric    typedef _CharT                                       value_type;
6770b57cec5SDimitry Andric    typedef _Allocator                                   allocator_type;
6780b57cec5SDimitry Andric    typedef allocator_traits<allocator_type>             __alloc_traits;
6790b57cec5SDimitry Andric    typedef typename __alloc_traits::size_type           size_type;
6800b57cec5SDimitry Andric    typedef typename __alloc_traits::difference_type     difference_type;
6810b57cec5SDimitry Andric    typedef value_type&                                  reference;
6820b57cec5SDimitry Andric    typedef const value_type&                            const_reference;
6830b57cec5SDimitry Andric    typedef typename __alloc_traits::pointer             pointer;
6840b57cec5SDimitry Andric    typedef typename __alloc_traits::const_pointer       const_pointer;
6850b57cec5SDimitry Andric
6860b57cec5SDimitry Andric    static_assert((!is_array<value_type>::value), "Character type of basic_string must not be an array");
6870b57cec5SDimitry Andric    static_assert(( is_standard_layout<value_type>::value), "Character type of basic_string must be standard-layout");
6880b57cec5SDimitry Andric    static_assert(( is_trivial<value_type>::value), "Character type of basic_string must be trivial");
6890b57cec5SDimitry Andric    static_assert(( is_same<_CharT, typename traits_type::char_type>::value),
6900b57cec5SDimitry Andric                  "traits_type::char_type must be the same type as CharT");
6910b57cec5SDimitry Andric    static_assert(( is_same<typename allocator_type::value_type, value_type>::value),
6920b57cec5SDimitry Andric                  "Allocator::value_type must be same type as value_type");
6930b57cec5SDimitry Andric
6940b57cec5SDimitry Andric    typedef __wrap_iter<pointer>                         iterator;
6950b57cec5SDimitry Andric    typedef __wrap_iter<const_pointer>                   const_iterator;
6960b57cec5SDimitry Andric    typedef _VSTD::reverse_iterator<iterator>             reverse_iterator;
6970b57cec5SDimitry Andric    typedef _VSTD::reverse_iterator<const_iterator>       const_reverse_iterator;
6980b57cec5SDimitry Andric
6990b57cec5SDimitry Andricprivate:
7000b57cec5SDimitry Andric
7010b57cec5SDimitry Andric#ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
7020b57cec5SDimitry Andric
7030b57cec5SDimitry Andric    struct __long
7040b57cec5SDimitry Andric    {
7050b57cec5SDimitry Andric        pointer   __data_;
7060b57cec5SDimitry Andric        size_type __size_;
7070b57cec5SDimitry Andric        size_type __cap_;
7080b57cec5SDimitry Andric    };
7090b57cec5SDimitry Andric
7100b57cec5SDimitry Andric#ifdef _LIBCPP_BIG_ENDIAN
7110b57cec5SDimitry Andric    static const size_type __short_mask = 0x01;
7120b57cec5SDimitry Andric    static const size_type __long_mask  = 0x1ul;
7130b57cec5SDimitry Andric#else  // _LIBCPP_BIG_ENDIAN
7140b57cec5SDimitry Andric    static const size_type __short_mask = 0x80;
7150b57cec5SDimitry Andric    static const size_type __long_mask  = ~(size_type(~0) >> 1);
7160b57cec5SDimitry Andric#endif  // _LIBCPP_BIG_ENDIAN
7170b57cec5SDimitry Andric
7180b57cec5SDimitry Andric    enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ?
7190b57cec5SDimitry Andric                      (sizeof(__long) - 1)/sizeof(value_type) : 2};
7200b57cec5SDimitry Andric
7210b57cec5SDimitry Andric    struct __short
7220b57cec5SDimitry Andric    {
7230b57cec5SDimitry Andric        value_type __data_[__min_cap];
7240b57cec5SDimitry Andric        struct
7250b57cec5SDimitry Andric            : __padding<value_type>
7260b57cec5SDimitry Andric        {
7270b57cec5SDimitry Andric            unsigned char __size_;
7280b57cec5SDimitry Andric        };
7290b57cec5SDimitry Andric    };
7300b57cec5SDimitry Andric
7310b57cec5SDimitry Andric#else
7320b57cec5SDimitry Andric
7330b57cec5SDimitry Andric    struct __long
7340b57cec5SDimitry Andric    {
7350b57cec5SDimitry Andric        size_type __cap_;
7360b57cec5SDimitry Andric        size_type __size_;
7370b57cec5SDimitry Andric        pointer   __data_;
7380b57cec5SDimitry Andric    };
7390b57cec5SDimitry Andric
7400b57cec5SDimitry Andric#ifdef _LIBCPP_BIG_ENDIAN
7410b57cec5SDimitry Andric    static const size_type __short_mask = 0x80;
7420b57cec5SDimitry Andric    static const size_type __long_mask  = ~(size_type(~0) >> 1);
7430b57cec5SDimitry Andric#else  // _LIBCPP_BIG_ENDIAN
7440b57cec5SDimitry Andric    static const size_type __short_mask = 0x01;
7450b57cec5SDimitry Andric    static const size_type __long_mask  = 0x1ul;
7460b57cec5SDimitry Andric#endif  // _LIBCPP_BIG_ENDIAN
7470b57cec5SDimitry Andric
7480b57cec5SDimitry Andric    enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ?
7490b57cec5SDimitry Andric                      (sizeof(__long) - 1)/sizeof(value_type) : 2};
7500b57cec5SDimitry Andric
7510b57cec5SDimitry Andric    struct __short
7520b57cec5SDimitry Andric    {
7530b57cec5SDimitry Andric        union
7540b57cec5SDimitry Andric        {
7550b57cec5SDimitry Andric            unsigned char __size_;
7560b57cec5SDimitry Andric            value_type __lx;
7570b57cec5SDimitry Andric        };
7580b57cec5SDimitry Andric        value_type __data_[__min_cap];
7590b57cec5SDimitry Andric    };
7600b57cec5SDimitry Andric
7610b57cec5SDimitry Andric#endif  // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
7620b57cec5SDimitry Andric
7630b57cec5SDimitry Andric    union __ulx{__long __lx; __short __lxx;};
7640b57cec5SDimitry Andric
7650b57cec5SDimitry Andric    enum {__n_words = sizeof(__ulx) / sizeof(size_type)};
7660b57cec5SDimitry Andric
7670b57cec5SDimitry Andric    struct __raw
7680b57cec5SDimitry Andric    {
7690b57cec5SDimitry Andric        size_type __words[__n_words];
7700b57cec5SDimitry Andric    };
7710b57cec5SDimitry Andric
7720b57cec5SDimitry Andric    struct __rep
7730b57cec5SDimitry Andric    {
7740b57cec5SDimitry Andric        union
7750b57cec5SDimitry Andric        {
7760b57cec5SDimitry Andric            __long  __l;
7770b57cec5SDimitry Andric            __short __s;
7780b57cec5SDimitry Andric            __raw   __r;
7790b57cec5SDimitry Andric        };
7800b57cec5SDimitry Andric    };
7810b57cec5SDimitry Andric
7820b57cec5SDimitry Andric    __compressed_pair<__rep, allocator_type> __r_;
7830b57cec5SDimitry Andric
7840b57cec5SDimitry Andricpublic:
785*5ffd83dbSDimitry Andric    _LIBCPP_FUNC_VIS
7860b57cec5SDimitry Andric    static const size_type npos = -1;
7870b57cec5SDimitry Andric
7880b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY basic_string()
7890b57cec5SDimitry Andric        _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value);
7900b57cec5SDimitry Andric
7910b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY explicit basic_string(const allocator_type& __a)
7920b57cec5SDimitry Andric#if _LIBCPP_STD_VER <= 14
7930b57cec5SDimitry Andric        _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value);
7940b57cec5SDimitry Andric#else
7950b57cec5SDimitry Andric        _NOEXCEPT;
7960b57cec5SDimitry Andric#endif
7970b57cec5SDimitry Andric
7980b57cec5SDimitry Andric    basic_string(const basic_string& __str);
7990b57cec5SDimitry Andric    basic_string(const basic_string& __str, const allocator_type& __a);
8000b57cec5SDimitry Andric
8010b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
8020b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
8030b57cec5SDimitry Andric    basic_string(basic_string&& __str)
8040b57cec5SDimitry Andric#if _LIBCPP_STD_VER <= 14
8050b57cec5SDimitry Andric        _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
8060b57cec5SDimitry Andric#else
8070b57cec5SDimitry Andric        _NOEXCEPT;
8080b57cec5SDimitry Andric#endif
8090b57cec5SDimitry Andric
8100b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
8110b57cec5SDimitry Andric    basic_string(basic_string&& __str, const allocator_type& __a);
8120b57cec5SDimitry Andric#endif  // _LIBCPP_CXX03_LANG
8130b57cec5SDimitry Andric
814*5ffd83dbSDimitry Andric    template <class = _EnableIf<__is_allocator<_Allocator>::value, nullptr_t> >
8150b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
816480093f4SDimitry Andric    basic_string(const _CharT* __s) : __r_(__default_init_tag(), __default_init_tag()) {
8170b57cec5SDimitry Andric      _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*) detected nullptr");
8180b57cec5SDimitry Andric      __init(__s, traits_type::length(__s));
8190b57cec5SDimitry Andric#   if _LIBCPP_DEBUG_LEVEL >= 2
8200b57cec5SDimitry Andric      __get_db()->__insert_c(this);
8210b57cec5SDimitry Andric#   endif
8220b57cec5SDimitry Andric    }
8230b57cec5SDimitry Andric
824*5ffd83dbSDimitry Andric    template <class = _EnableIf<__is_allocator<_Allocator>::value, nullptr_t> >
8250b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY
8260b57cec5SDimitry Andric        basic_string(const _CharT* __s, const _Allocator& __a);
8270b57cec5SDimitry Andric
8280b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
8290b57cec5SDimitry Andric    basic_string(const _CharT* __s, size_type __n);
8300b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
8310b57cec5SDimitry Andric    basic_string(const _CharT* __s, size_type __n, const _Allocator& __a);
8320b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
8330b57cec5SDimitry Andric    basic_string(size_type __n, _CharT __c);
8340b57cec5SDimitry Andric
835*5ffd83dbSDimitry Andric    template <class = _EnableIf<__is_allocator<_Allocator>::value, nullptr_t> >
8360b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY
8370b57cec5SDimitry Andric        basic_string(size_type __n, _CharT __c, const _Allocator& __a);
8380b57cec5SDimitry Andric
8390b57cec5SDimitry Andric    basic_string(const basic_string& __str, size_type __pos, size_type __n,
8400b57cec5SDimitry Andric                 const _Allocator& __a = _Allocator());
8410b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
8420b57cec5SDimitry Andric    basic_string(const basic_string& __str, size_type __pos,
8430b57cec5SDimitry Andric                 const _Allocator& __a = _Allocator());
8440b57cec5SDimitry Andric
845*5ffd83dbSDimitry Andric    template<class _Tp, class = _EnableIf<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && !__is_same_uncvref<_Tp, basic_string>::value> >
8460b57cec5SDimitry Andric        _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
8470b57cec5SDimitry Andric        basic_string(const _Tp& __t, size_type __pos, size_type __n,
8480b57cec5SDimitry Andric                     const allocator_type& __a = allocator_type());
8490b57cec5SDimitry Andric
850*5ffd83dbSDimitry Andric    template<class _Tp, class = _EnableIf<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value &&
851*5ffd83dbSDimitry Andric                                          !__is_same_uncvref<_Tp, basic_string>::value> >
8520b57cec5SDimitry Andric        _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
8530b57cec5SDimitry Andric        explicit basic_string(const _Tp& __t);
8540b57cec5SDimitry Andric
855*5ffd83dbSDimitry Andric    template<class _Tp, class = _EnableIf<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && !__is_same_uncvref<_Tp, basic_string>::value> >
8560b57cec5SDimitry Andric        _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
8570b57cec5SDimitry Andric        explicit basic_string(const _Tp& __t, const allocator_type& __a);
8580b57cec5SDimitry Andric
859*5ffd83dbSDimitry Andric    template<class _InputIterator, class = _EnableIf<__is_cpp17_input_iterator<_InputIterator>::value> >
8600b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY
8610b57cec5SDimitry Andric        basic_string(_InputIterator __first, _InputIterator __last);
862*5ffd83dbSDimitry Andric    template<class _InputIterator, class = _EnableIf<__is_cpp17_input_iterator<_InputIterator>::value> >
8630b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY
8640b57cec5SDimitry Andric        basic_string(_InputIterator __first, _InputIterator __last, const allocator_type& __a);
8650b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
8660b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
8670b57cec5SDimitry Andric    basic_string(initializer_list<_CharT> __il);
8680b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
8690b57cec5SDimitry Andric    basic_string(initializer_list<_CharT> __il, const _Allocator& __a);
8700b57cec5SDimitry Andric#endif  // _LIBCPP_CXX03_LANG
8710b57cec5SDimitry Andric
8720b57cec5SDimitry Andric    inline ~basic_string();
8730b57cec5SDimitry Andric
8740b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
8750b57cec5SDimitry Andric    operator __self_view() const _NOEXCEPT { return __self_view(data(), size()); }
8760b57cec5SDimitry Andric
8770b57cec5SDimitry Andric    basic_string& operator=(const basic_string& __str);
8780b57cec5SDimitry Andric
879*5ffd83dbSDimitry Andric    template <class _Tp, class = _EnableIf<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && !__is_same_uncvref<_Tp, basic_string>::value> >
8800b57cec5SDimitry Andric    basic_string& operator=(const _Tp& __t)
8810b57cec5SDimitry Andric        {__self_view __sv = __t; return assign(__sv);}
8820b57cec5SDimitry Andric
8830b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
8840b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
8850b57cec5SDimitry Andric    basic_string& operator=(basic_string&& __str)
8860b57cec5SDimitry Andric        _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value));
8870b57cec5SDimitry Andric     _LIBCPP_INLINE_VISIBILITY
8880b57cec5SDimitry Andric    basic_string& operator=(initializer_list<value_type> __il) {return assign(__il.begin(), __il.size());}
8890b57cec5SDimitry Andric#endif
8900b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY basic_string& operator=(const value_type* __s) {return assign(__s);}
8910b57cec5SDimitry Andric    basic_string& operator=(value_type __c);
8920b57cec5SDimitry Andric
8930b57cec5SDimitry Andric#if _LIBCPP_DEBUG_LEVEL >= 2
8940b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
8950b57cec5SDimitry Andric    iterator begin() _NOEXCEPT
8960b57cec5SDimitry Andric        {return iterator(this, __get_pointer());}
8970b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
8980b57cec5SDimitry Andric    const_iterator begin() const _NOEXCEPT
8990b57cec5SDimitry Andric        {return const_iterator(this, __get_pointer());}
9000b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
9010b57cec5SDimitry Andric    iterator end() _NOEXCEPT
9020b57cec5SDimitry Andric        {return iterator(this, __get_pointer() + size());}
9030b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
9040b57cec5SDimitry Andric    const_iterator end() const _NOEXCEPT
9050b57cec5SDimitry Andric        {return const_iterator(this, __get_pointer() + size());}
9060b57cec5SDimitry Andric#else
9070b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
9080b57cec5SDimitry Andric    iterator begin() _NOEXCEPT
9090b57cec5SDimitry Andric        {return iterator(__get_pointer());}
9100b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
9110b57cec5SDimitry Andric    const_iterator begin() const _NOEXCEPT
9120b57cec5SDimitry Andric        {return const_iterator(__get_pointer());}
9130b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
9140b57cec5SDimitry Andric    iterator end() _NOEXCEPT
9150b57cec5SDimitry Andric        {return iterator(__get_pointer() + size());}
9160b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
9170b57cec5SDimitry Andric    const_iterator end() const _NOEXCEPT
9180b57cec5SDimitry Andric        {return const_iterator(__get_pointer() + size());}
9190b57cec5SDimitry Andric#endif  // _LIBCPP_DEBUG_LEVEL >= 2
9200b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
9210b57cec5SDimitry Andric    reverse_iterator rbegin() _NOEXCEPT
9220b57cec5SDimitry Andric        {return reverse_iterator(end());}
9230b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
9240b57cec5SDimitry Andric    const_reverse_iterator rbegin() const _NOEXCEPT
9250b57cec5SDimitry Andric        {return const_reverse_iterator(end());}
9260b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
9270b57cec5SDimitry Andric    reverse_iterator rend() _NOEXCEPT
9280b57cec5SDimitry Andric        {return reverse_iterator(begin());}
9290b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
9300b57cec5SDimitry Andric    const_reverse_iterator rend() const _NOEXCEPT
9310b57cec5SDimitry Andric        {return const_reverse_iterator(begin());}
9320b57cec5SDimitry Andric
9330b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
9340b57cec5SDimitry Andric    const_iterator cbegin() const _NOEXCEPT
9350b57cec5SDimitry Andric        {return begin();}
9360b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
9370b57cec5SDimitry Andric    const_iterator cend() const _NOEXCEPT
9380b57cec5SDimitry Andric        {return end();}
9390b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
9400b57cec5SDimitry Andric    const_reverse_iterator crbegin() const _NOEXCEPT
9410b57cec5SDimitry Andric        {return rbegin();}
9420b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
9430b57cec5SDimitry Andric    const_reverse_iterator crend() const _NOEXCEPT
9440b57cec5SDimitry Andric        {return rend();}
9450b57cec5SDimitry Andric
9460b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY size_type size() const _NOEXCEPT
9470b57cec5SDimitry Andric        {return __is_long() ? __get_long_size() : __get_short_size();}
9480b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY size_type length() const _NOEXCEPT {return size();}
9490b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT;
9500b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY size_type capacity() const _NOEXCEPT
9510b57cec5SDimitry Andric        {return (__is_long() ? __get_long_cap()
9520b57cec5SDimitry Andric                             : static_cast<size_type>(__min_cap)) - 1;}
9530b57cec5SDimitry Andric
9540b57cec5SDimitry Andric    void resize(size_type __n, value_type __c);
9550b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY void resize(size_type __n) {resize(__n, value_type());}
9560b57cec5SDimitry Andric
9570b57cec5SDimitry Andric    void reserve(size_type __res_arg);
9580b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY void __resize_default_init(size_type __n);
9590b57cec5SDimitry Andric
9600b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
9610b57cec5SDimitry Andric    void reserve() _NOEXCEPT {reserve(0);}
9620b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
9630b57cec5SDimitry Andric    void shrink_to_fit() _NOEXCEPT {reserve();}
9640b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
9650b57cec5SDimitry Andric    void clear() _NOEXCEPT;
9660b57cec5SDimitry Andric    _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
9670b57cec5SDimitry Andric    bool empty() const _NOEXCEPT {return size() == 0;}
9680b57cec5SDimitry Andric
9690b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __pos) const _NOEXCEPT;
9700b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY reference       operator[](size_type __pos)       _NOEXCEPT;
9710b57cec5SDimitry Andric
9720b57cec5SDimitry Andric    const_reference at(size_type __n) const;
9730b57cec5SDimitry Andric    reference       at(size_type __n);
9740b57cec5SDimitry Andric
9750b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(const basic_string& __str) {return append(__str);}
9760b57cec5SDimitry Andric
9770b57cec5SDimitry Andric    template <class _Tp>
9780b57cec5SDimitry Andric    _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
979*5ffd83dbSDimitry Andric    _EnableIf
9800b57cec5SDimitry Andric        <
981*5ffd83dbSDimitry Andric            __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value
982*5ffd83dbSDimitry Andric            && !__is_same_uncvref<_Tp, basic_string >::value,
9830b57cec5SDimitry Andric            basic_string&
984*5ffd83dbSDimitry Andric        >
9850b57cec5SDimitry Andric                                            operator+=(const _Tp& __t)            {__self_view __sv = __t; return append(__sv);}
9860b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(const value_type* __s)     {return append(__s);}
9870b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(value_type __c)            {push_back(__c); return *this;}
9880b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
9890b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(initializer_list<value_type> __il) {return append(__il);}
9900b57cec5SDimitry Andric#endif  // _LIBCPP_CXX03_LANG
9910b57cec5SDimitry Andric
9920b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
9930b57cec5SDimitry Andric    basic_string& append(const basic_string& __str);
9940b57cec5SDimitry Andric
9950b57cec5SDimitry Andric    template <class _Tp>
9960b57cec5SDimitry Andric    _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
997*5ffd83dbSDimitry Andric    _EnableIf<
998*5ffd83dbSDimitry Andric            __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value
999*5ffd83dbSDimitry Andric            && !__is_same_uncvref<_Tp, basic_string>::value,
10000b57cec5SDimitry Andric            basic_string&
1001*5ffd83dbSDimitry Andric        >
10020b57cec5SDimitry Andric                  append(const _Tp& __t) { __self_view __sv = __t; return append(__sv.data(), __sv.size()); }
10030b57cec5SDimitry Andric    basic_string& append(const basic_string& __str, size_type __pos, size_type __n=npos);
10040b57cec5SDimitry Andric
10050b57cec5SDimitry Andric    template <class _Tp>
10060b57cec5SDimitry Andric    _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1007*5ffd83dbSDimitry Andric    _EnableIf
10080b57cec5SDimitry Andric        <
1009*5ffd83dbSDimitry Andric            __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value
1010*5ffd83dbSDimitry Andric            && !__is_same_uncvref<_Tp, basic_string>::value,
10110b57cec5SDimitry Andric            basic_string&
1012*5ffd83dbSDimitry Andric        >
10130b57cec5SDimitry Andric                  append(const _Tp& __t, size_type __pos, size_type __n=npos);
10140b57cec5SDimitry Andric    basic_string& append(const value_type* __s, size_type __n);
10150b57cec5SDimitry Andric    basic_string& append(const value_type* __s);
10160b57cec5SDimitry Andric    basic_string& append(size_type __n, value_type __c);
10170b57cec5SDimitry Andric
10180b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
10190b57cec5SDimitry Andric    void __append_default_init(size_type __n);
10200b57cec5SDimitry Andric
10210b57cec5SDimitry Andric    template <class _ForwardIterator>
10220b57cec5SDimitry Andric    _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
10230b57cec5SDimitry Andric    basic_string& __append_forward_unsafe(_ForwardIterator, _ForwardIterator);
10240b57cec5SDimitry Andric    template<class _InputIterator>
10250b57cec5SDimitry Andric    _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1026*5ffd83dbSDimitry Andric    _EnableIf
10270b57cec5SDimitry Andric        <
1028480093f4SDimitry Andric            __is_exactly_cpp17_input_iterator<_InputIterator>::value
10290b57cec5SDimitry Andric                || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
10300b57cec5SDimitry Andric            basic_string&
1031*5ffd83dbSDimitry Andric        >
10320b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
10330b57cec5SDimitry Andric    append(_InputIterator __first, _InputIterator __last) {
10340b57cec5SDimitry Andric      const basic_string __temp (__first, __last, __alloc());
10350b57cec5SDimitry Andric      append(__temp.data(), __temp.size());
10360b57cec5SDimitry Andric      return *this;
10370b57cec5SDimitry Andric    }
10380b57cec5SDimitry Andric    template<class _ForwardIterator>
10390b57cec5SDimitry Andric    _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1040*5ffd83dbSDimitry Andric    _EnableIf
10410b57cec5SDimitry Andric        <
1042480093f4SDimitry Andric            __is_cpp17_forward_iterator<_ForwardIterator>::value
10430b57cec5SDimitry Andric                && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
10440b57cec5SDimitry Andric            basic_string&
1045*5ffd83dbSDimitry Andric        >
10460b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
10470b57cec5SDimitry Andric    append(_ForwardIterator __first, _ForwardIterator __last) {
10480b57cec5SDimitry Andric      return __append_forward_unsafe(__first, __last);
10490b57cec5SDimitry Andric    }
10500b57cec5SDimitry Andric
10510b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
10520b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
10530b57cec5SDimitry Andric    basic_string& append(initializer_list<value_type> __il) {return append(__il.begin(), __il.size());}
10540b57cec5SDimitry Andric#endif  // _LIBCPP_CXX03_LANG
10550b57cec5SDimitry Andric
10560b57cec5SDimitry Andric    void push_back(value_type __c);
10570b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
10580b57cec5SDimitry Andric    void pop_back();
10590b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY reference       front() _NOEXCEPT;
10600b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY const_reference front() const _NOEXCEPT;
10610b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY reference       back() _NOEXCEPT;
10620b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY const_reference back() const _NOEXCEPT;
10630b57cec5SDimitry Andric
10640b57cec5SDimitry Andric    template <class _Tp>
10650b57cec5SDimitry Andric    _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1066*5ffd83dbSDimitry Andric    _EnableIf
10670b57cec5SDimitry Andric        <
10680b57cec5SDimitry Andric            __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
10690b57cec5SDimitry Andric            basic_string&
1070*5ffd83dbSDimitry Andric        >
10710b57cec5SDimitry Andric                 assign(const _Tp & __t) { __self_view __sv = __t; return assign(__sv.data(), __sv.size()); }
10720b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
10730b57cec5SDimitry Andric    basic_string& assign(const basic_string& __str) { return *this = __str; }
10740b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
10750b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
10760b57cec5SDimitry Andric    basic_string& assign(basic_string&& __str)
10770b57cec5SDimitry Andric        _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value))
10780b57cec5SDimitry Andric        {*this = _VSTD::move(__str); return *this;}
10790b57cec5SDimitry Andric#endif
10800b57cec5SDimitry Andric    basic_string& assign(const basic_string& __str, size_type __pos, size_type __n=npos);
10810b57cec5SDimitry Andric    template <class _Tp>
10820b57cec5SDimitry Andric    _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1083*5ffd83dbSDimitry Andric    _EnableIf
10840b57cec5SDimitry Andric        <
1085*5ffd83dbSDimitry Andric            __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value
1086*5ffd83dbSDimitry Andric            && !__is_same_uncvref<_Tp, basic_string>::value,
10870b57cec5SDimitry Andric            basic_string&
1088*5ffd83dbSDimitry Andric        >
10890b57cec5SDimitry Andric                  assign(const _Tp & __t, size_type __pos, size_type __n=npos);
10900b57cec5SDimitry Andric    basic_string& assign(const value_type* __s, size_type __n);
10910b57cec5SDimitry Andric    basic_string& assign(const value_type* __s);
10920b57cec5SDimitry Andric    basic_string& assign(size_type __n, value_type __c);
10930b57cec5SDimitry Andric    template<class _InputIterator>
10940b57cec5SDimitry Andric    _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1095*5ffd83dbSDimitry Andric    _EnableIf
10960b57cec5SDimitry Andric        <
1097480093f4SDimitry Andric           __is_exactly_cpp17_input_iterator<_InputIterator>::value
10980b57cec5SDimitry Andric                || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
10990b57cec5SDimitry Andric            basic_string&
1100*5ffd83dbSDimitry Andric        >
11010b57cec5SDimitry Andric        assign(_InputIterator __first, _InputIterator __last);
11020b57cec5SDimitry Andric    template<class _ForwardIterator>
11030b57cec5SDimitry Andric    _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1104*5ffd83dbSDimitry Andric    _EnableIf
11050b57cec5SDimitry Andric        <
1106480093f4SDimitry Andric            __is_cpp17_forward_iterator<_ForwardIterator>::value
11070b57cec5SDimitry Andric                 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
11080b57cec5SDimitry Andric            basic_string&
1109*5ffd83dbSDimitry Andric        >
11100b57cec5SDimitry Andric        assign(_ForwardIterator __first, _ForwardIterator __last);
11110b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
11120b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
11130b57cec5SDimitry Andric    basic_string& assign(initializer_list<value_type> __il) {return assign(__il.begin(), __il.size());}
11140b57cec5SDimitry Andric#endif  // _LIBCPP_CXX03_LANG
11150b57cec5SDimitry Andric
11160b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
11170b57cec5SDimitry Andric    basic_string& insert(size_type __pos1, const basic_string& __str);
11180b57cec5SDimitry Andric
11190b57cec5SDimitry Andric    template <class _Tp>
11200b57cec5SDimitry Andric    _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1121*5ffd83dbSDimitry Andric    _EnableIf
11220b57cec5SDimitry Andric        <
11230b57cec5SDimitry Andric            __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
11240b57cec5SDimitry Andric            basic_string&
1125*5ffd83dbSDimitry Andric        >
11260b57cec5SDimitry Andric                 insert(size_type __pos1, const _Tp& __t)
11270b57cec5SDimitry Andric    { __self_view __sv = __t; return insert(__pos1, __sv.data(), __sv.size()); }
11280b57cec5SDimitry Andric
11290b57cec5SDimitry Andric    template <class _Tp>
11300b57cec5SDimitry Andric    _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1131*5ffd83dbSDimitry Andric    _EnableIf
11320b57cec5SDimitry Andric        <
1133*5ffd83dbSDimitry Andric            __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && !__is_same_uncvref<_Tp, basic_string>::value,
11340b57cec5SDimitry Andric            basic_string&
1135*5ffd83dbSDimitry Andric        >
11360b57cec5SDimitry Andric                  insert(size_type __pos1, const _Tp& __t, size_type __pos2, size_type __n=npos);
11370b57cec5SDimitry Andric    basic_string& insert(size_type __pos1, const basic_string& __str, size_type __pos2, size_type __n=npos);
11380b57cec5SDimitry Andric    basic_string& insert(size_type __pos, const value_type* __s, size_type __n);
11390b57cec5SDimitry Andric    basic_string& insert(size_type __pos, const value_type* __s);
11400b57cec5SDimitry Andric    basic_string& insert(size_type __pos, size_type __n, value_type __c);
11410b57cec5SDimitry Andric    iterator      insert(const_iterator __pos, value_type __c);
11420b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
11430b57cec5SDimitry Andric    iterator      insert(const_iterator __pos, size_type __n, value_type __c);
11440b57cec5SDimitry Andric    template<class _InputIterator>
11450b57cec5SDimitry Andric    _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1146*5ffd83dbSDimitry Andric    _EnableIf
11470b57cec5SDimitry Andric        <
1148480093f4SDimitry Andric           __is_exactly_cpp17_input_iterator<_InputIterator>::value
11490b57cec5SDimitry Andric                || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
11500b57cec5SDimitry Andric            iterator
1151*5ffd83dbSDimitry Andric        >
11520b57cec5SDimitry Andric        insert(const_iterator __pos, _InputIterator __first, _InputIterator __last);
11530b57cec5SDimitry Andric    template<class _ForwardIterator>
11540b57cec5SDimitry Andric    _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1155*5ffd83dbSDimitry Andric    _EnableIf
11560b57cec5SDimitry Andric        <
1157480093f4SDimitry Andric            __is_cpp17_forward_iterator<_ForwardIterator>::value
11580b57cec5SDimitry Andric                 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
11590b57cec5SDimitry Andric            iterator
1160*5ffd83dbSDimitry Andric        >
11610b57cec5SDimitry Andric        insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last);
11620b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
11630b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
11640b57cec5SDimitry Andric    iterator insert(const_iterator __pos, initializer_list<value_type> __il)
11650b57cec5SDimitry Andric                    {return insert(__pos, __il.begin(), __il.end());}
11660b57cec5SDimitry Andric#endif  // _LIBCPP_CXX03_LANG
11670b57cec5SDimitry Andric
11680b57cec5SDimitry Andric    basic_string& erase(size_type __pos = 0, size_type __n = npos);
11690b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
11700b57cec5SDimitry Andric    iterator      erase(const_iterator __pos);
11710b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
11720b57cec5SDimitry Andric    iterator      erase(const_iterator __first, const_iterator __last);
11730b57cec5SDimitry Andric
11740b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
11750b57cec5SDimitry Andric    basic_string& replace(size_type __pos1, size_type __n1, const basic_string& __str);
11760b57cec5SDimitry Andric
11770b57cec5SDimitry Andric    template <class _Tp>
11780b57cec5SDimitry Andric    _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1179*5ffd83dbSDimitry Andric    _EnableIf
11800b57cec5SDimitry Andric        <
11810b57cec5SDimitry Andric            __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
11820b57cec5SDimitry Andric            basic_string&
1183*5ffd83dbSDimitry Andric        >
11840b57cec5SDimitry Andric                  replace(size_type __pos1, size_type __n1, const _Tp& __t) { __self_view __sv = __t; return replace(__pos1, __n1, __sv.data(), __sv.size()); }
11850b57cec5SDimitry Andric    basic_string& replace(size_type __pos1, size_type __n1, const basic_string& __str, size_type __pos2, size_type __n2=npos);
11860b57cec5SDimitry Andric    template <class _Tp>
11870b57cec5SDimitry Andric    _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1188*5ffd83dbSDimitry Andric    _EnableIf
11890b57cec5SDimitry Andric        <
1190*5ffd83dbSDimitry Andric            __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value  && !__is_same_uncvref<_Tp, basic_string>::value,
11910b57cec5SDimitry Andric            basic_string&
1192*5ffd83dbSDimitry Andric        >
11930b57cec5SDimitry Andric                  replace(size_type __pos1, size_type __n1, const _Tp& __t, size_type __pos2, size_type __n2=npos);
11940b57cec5SDimitry Andric    basic_string& replace(size_type __pos, size_type __n1, const value_type* __s, size_type __n2);
11950b57cec5SDimitry Andric    basic_string& replace(size_type __pos, size_type __n1, const value_type* __s);
11960b57cec5SDimitry Andric    basic_string& replace(size_type __pos, size_type __n1, size_type __n2, value_type __c);
11970b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
11980b57cec5SDimitry Andric    basic_string& replace(const_iterator __i1, const_iterator __i2, const basic_string& __str);
11990b57cec5SDimitry Andric
12000b57cec5SDimitry Andric    template <class _Tp>
12010b57cec5SDimitry Andric    _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1202*5ffd83dbSDimitry Andric    _EnableIf
12030b57cec5SDimitry Andric        <
12040b57cec5SDimitry Andric            __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
12050b57cec5SDimitry Andric            basic_string&
1206*5ffd83dbSDimitry Andric        >
12070b57cec5SDimitry Andric                  replace(const_iterator __i1, const_iterator __i2, const _Tp& __t) { __self_view __sv = __t; return replace(__i1 - begin(), __i2 - __i1, __sv); }
12080b57cec5SDimitry Andric
12090b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
12100b57cec5SDimitry Andric    basic_string& replace(const_iterator __i1, const_iterator __i2, const value_type* __s, size_type __n);
12110b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
12120b57cec5SDimitry Andric    basic_string& replace(const_iterator __i1, const_iterator __i2, const value_type* __s);
12130b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
12140b57cec5SDimitry Andric    basic_string& replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c);
12150b57cec5SDimitry Andric    template<class _InputIterator>
12160b57cec5SDimitry Andric    _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1217*5ffd83dbSDimitry Andric    _EnableIf
12180b57cec5SDimitry Andric        <
1219480093f4SDimitry Andric            __is_cpp17_input_iterator<_InputIterator>::value,
12200b57cec5SDimitry Andric            basic_string&
1221*5ffd83dbSDimitry Andric        >
12220b57cec5SDimitry Andric        replace(const_iterator __i1, const_iterator __i2, _InputIterator __j1, _InputIterator __j2);
12230b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
12240b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
12250b57cec5SDimitry Andric    basic_string& replace(const_iterator __i1, const_iterator __i2, initializer_list<value_type> __il)
12260b57cec5SDimitry Andric        {return replace(__i1, __i2, __il.begin(), __il.end());}
12270b57cec5SDimitry Andric#endif  // _LIBCPP_CXX03_LANG
12280b57cec5SDimitry Andric
12290b57cec5SDimitry Andric    size_type copy(value_type* __s, size_type __n, size_type __pos = 0) const;
12300b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
12310b57cec5SDimitry Andric    basic_string substr(size_type __pos = 0, size_type __n = npos) const;
12320b57cec5SDimitry Andric
12330b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
12340b57cec5SDimitry Andric    void swap(basic_string& __str)
12350b57cec5SDimitry Andric#if _LIBCPP_STD_VER >= 14
12360b57cec5SDimitry Andric        _NOEXCEPT;
12370b57cec5SDimitry Andric#else
12380b57cec5SDimitry Andric        _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
12390b57cec5SDimitry Andric                    __is_nothrow_swappable<allocator_type>::value);
12400b57cec5SDimitry Andric#endif
12410b57cec5SDimitry Andric
12420b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
12430b57cec5SDimitry Andric    const value_type* c_str() const _NOEXCEPT {return data();}
12440b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
1245480093f4SDimitry Andric    const value_type* data() const _NOEXCEPT  {return _VSTD::__to_address(__get_pointer());}
12460b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 14 || defined(_LIBCPP_BUILDING_LIBRARY)
12470b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
1248480093f4SDimitry Andric    value_type* data()             _NOEXCEPT  {return _VSTD::__to_address(__get_pointer());}
12490b57cec5SDimitry Andric#endif
12500b57cec5SDimitry Andric
12510b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
12520b57cec5SDimitry Andric    allocator_type get_allocator() const _NOEXCEPT {return __alloc();}
12530b57cec5SDimitry Andric
12540b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
12550b57cec5SDimitry Andric    size_type find(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
12560b57cec5SDimitry Andric
12570b57cec5SDimitry Andric    template <class _Tp>
12580b57cec5SDimitry Andric    _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1259*5ffd83dbSDimitry Andric    _EnableIf
12600b57cec5SDimitry Andric        <
12610b57cec5SDimitry Andric            __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
12620b57cec5SDimitry Andric            size_type
1263*5ffd83dbSDimitry Andric        >
12640b57cec5SDimitry Andric              find(const _Tp& __t, size_type __pos = 0) const;
12650b57cec5SDimitry Andric    size_type find(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
12660b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
12670b57cec5SDimitry Andric    size_type find(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
12680b57cec5SDimitry Andric    size_type find(value_type __c, size_type __pos = 0) const _NOEXCEPT;
12690b57cec5SDimitry Andric
12700b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
12710b57cec5SDimitry Andric    size_type rfind(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
12720b57cec5SDimitry Andric
12730b57cec5SDimitry Andric    template <class _Tp>
12740b57cec5SDimitry Andric    _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1275*5ffd83dbSDimitry Andric    _EnableIf
12760b57cec5SDimitry Andric        <
12770b57cec5SDimitry Andric            __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
12780b57cec5SDimitry Andric            size_type
1279*5ffd83dbSDimitry Andric        >
12800b57cec5SDimitry Andric              rfind(const _Tp& __t, size_type __pos = npos) const;
12810b57cec5SDimitry Andric    size_type rfind(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
12820b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
12830b57cec5SDimitry Andric    size_type rfind(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
12840b57cec5SDimitry Andric    size_type rfind(value_type __c, size_type __pos = npos) const _NOEXCEPT;
12850b57cec5SDimitry Andric
12860b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
12870b57cec5SDimitry Andric    size_type find_first_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
12880b57cec5SDimitry Andric
12890b57cec5SDimitry Andric    template <class _Tp>
12900b57cec5SDimitry Andric    _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1291*5ffd83dbSDimitry Andric    _EnableIf
12920b57cec5SDimitry Andric        <
12930b57cec5SDimitry Andric            __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
12940b57cec5SDimitry Andric            size_type
1295*5ffd83dbSDimitry Andric        >
12960b57cec5SDimitry Andric              find_first_of(const _Tp& __t, size_type __pos = 0) const;
12970b57cec5SDimitry Andric    size_type find_first_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
12980b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
12990b57cec5SDimitry Andric    size_type find_first_of(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
13000b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
13010b57cec5SDimitry Andric    size_type find_first_of(value_type __c, size_type __pos = 0) const _NOEXCEPT;
13020b57cec5SDimitry Andric
13030b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
13040b57cec5SDimitry Andric    size_type find_last_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
13050b57cec5SDimitry Andric
13060b57cec5SDimitry Andric    template <class _Tp>
13070b57cec5SDimitry Andric    _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1308*5ffd83dbSDimitry Andric    _EnableIf
13090b57cec5SDimitry Andric        <
13100b57cec5SDimitry Andric            __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
13110b57cec5SDimitry Andric            size_type
1312*5ffd83dbSDimitry Andric        >
13130b57cec5SDimitry Andric              find_last_of(const _Tp& __t, size_type __pos = npos) const;
13140b57cec5SDimitry Andric    size_type find_last_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
13150b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
13160b57cec5SDimitry Andric    size_type find_last_of(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
13170b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
13180b57cec5SDimitry Andric    size_type find_last_of(value_type __c, size_type __pos = npos) const _NOEXCEPT;
13190b57cec5SDimitry Andric
13200b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
13210b57cec5SDimitry Andric    size_type find_first_not_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
13220b57cec5SDimitry Andric
13230b57cec5SDimitry Andric    template <class _Tp>
13240b57cec5SDimitry Andric    _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1325*5ffd83dbSDimitry Andric    _EnableIf
13260b57cec5SDimitry Andric        <
13270b57cec5SDimitry Andric            __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
13280b57cec5SDimitry Andric            size_type
1329*5ffd83dbSDimitry Andric        >
13300b57cec5SDimitry Andric              find_first_not_of(const _Tp &__t, size_type __pos = 0) const;
13310b57cec5SDimitry Andric    size_type find_first_not_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
13320b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
13330b57cec5SDimitry Andric    size_type find_first_not_of(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
13340b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
13350b57cec5SDimitry Andric    size_type find_first_not_of(value_type __c, size_type __pos = 0) const _NOEXCEPT;
13360b57cec5SDimitry Andric
13370b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
13380b57cec5SDimitry Andric    size_type find_last_not_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
13390b57cec5SDimitry Andric
13400b57cec5SDimitry Andric    template <class _Tp>
13410b57cec5SDimitry Andric    _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1342*5ffd83dbSDimitry Andric    _EnableIf
13430b57cec5SDimitry Andric        <
13440b57cec5SDimitry Andric            __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
13450b57cec5SDimitry Andric            size_type
1346*5ffd83dbSDimitry Andric        >
13470b57cec5SDimitry Andric              find_last_not_of(const _Tp& __t, size_type __pos = npos) const;
13480b57cec5SDimitry Andric    size_type find_last_not_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
13490b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
13500b57cec5SDimitry Andric    size_type find_last_not_of(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
13510b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
13520b57cec5SDimitry Andric    size_type find_last_not_of(value_type __c, size_type __pos = npos) const _NOEXCEPT;
13530b57cec5SDimitry Andric
13540b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
13550b57cec5SDimitry Andric    int compare(const basic_string& __str) const _NOEXCEPT;
13560b57cec5SDimitry Andric
13570b57cec5SDimitry Andric    template <class _Tp>
13580b57cec5SDimitry Andric    _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1359*5ffd83dbSDimitry Andric    _EnableIf
13600b57cec5SDimitry Andric        <
13610b57cec5SDimitry Andric            __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
13620b57cec5SDimitry Andric            int
1363*5ffd83dbSDimitry Andric        >
13640b57cec5SDimitry Andric        compare(const _Tp &__t) const;
13650b57cec5SDimitry Andric
13660b57cec5SDimitry Andric    template <class _Tp>
13670b57cec5SDimitry Andric    _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1368*5ffd83dbSDimitry Andric    _EnableIf
13690b57cec5SDimitry Andric        <
13700b57cec5SDimitry Andric            __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
13710b57cec5SDimitry Andric            int
1372*5ffd83dbSDimitry Andric        >
13730b57cec5SDimitry Andric         compare(size_type __pos1, size_type __n1, const _Tp& __t) const;
13740b57cec5SDimitry Andric
13750b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
13760b57cec5SDimitry Andric    int compare(size_type __pos1, size_type __n1, const basic_string& __str) const;
13770b57cec5SDimitry Andric    int compare(size_type __pos1, size_type __n1, const basic_string& __str, size_type __pos2, size_type __n2=npos) const;
13780b57cec5SDimitry Andric
13790b57cec5SDimitry Andric    template <class _Tp>
13800b57cec5SDimitry Andric    inline _LIBCPP_INLINE_VISIBILITY
1381*5ffd83dbSDimitry Andric        _EnableIf
13820b57cec5SDimitry Andric        <
1383*5ffd83dbSDimitry Andric            __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value  && !__is_same_uncvref<_Tp, basic_string>::value,
13840b57cec5SDimitry Andric            int
1385*5ffd83dbSDimitry Andric        >
13860b57cec5SDimitry Andric        compare(size_type __pos1, size_type __n1, const _Tp& __t, size_type __pos2, size_type __n2=npos) const;
13870b57cec5SDimitry Andric    int compare(const value_type* __s) const _NOEXCEPT;
13880b57cec5SDimitry Andric    int compare(size_type __pos1, size_type __n1, const value_type* __s) const;
13890b57cec5SDimitry Andric    int compare(size_type __pos1, size_type __n1, const value_type* __s, size_type __n2) const;
13900b57cec5SDimitry Andric
13910b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 17
13920b57cec5SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
13930b57cec5SDimitry Andric    bool starts_with(__self_view __sv) const _NOEXCEPT
13940b57cec5SDimitry Andric    { return __self_view(data(), size()).starts_with(__sv); }
13950b57cec5SDimitry Andric
13960b57cec5SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
13970b57cec5SDimitry Andric    bool starts_with(value_type __c) const _NOEXCEPT
13980b57cec5SDimitry Andric    { return !empty() && _Traits::eq(front(), __c); }
13990b57cec5SDimitry Andric
14000b57cec5SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
14010b57cec5SDimitry Andric    bool starts_with(const value_type* __s) const _NOEXCEPT
14020b57cec5SDimitry Andric    { return starts_with(__self_view(__s)); }
14030b57cec5SDimitry Andric
14040b57cec5SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
14050b57cec5SDimitry Andric    bool ends_with(__self_view __sv) const _NOEXCEPT
14060b57cec5SDimitry Andric    { return __self_view(data(), size()).ends_with( __sv); }
14070b57cec5SDimitry Andric
14080b57cec5SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
14090b57cec5SDimitry Andric    bool ends_with(value_type __c) const _NOEXCEPT
14100b57cec5SDimitry Andric    { return !empty() && _Traits::eq(back(), __c); }
14110b57cec5SDimitry Andric
14120b57cec5SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
14130b57cec5SDimitry Andric    bool ends_with(const value_type* __s) const _NOEXCEPT
14140b57cec5SDimitry Andric    { return ends_with(__self_view(__s)); }
14150b57cec5SDimitry Andric#endif
14160b57cec5SDimitry Andric
14170b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY bool __invariants() const;
14180b57cec5SDimitry Andric
14190b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY void __clear_and_shrink() _NOEXCEPT;
14200b57cec5SDimitry Andric
14210b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
14220b57cec5SDimitry Andric    bool __is_long() const _NOEXCEPT
14230b57cec5SDimitry Andric        {return bool(__r_.first().__s.__size_ & __short_mask);}
14240b57cec5SDimitry Andric
14250b57cec5SDimitry Andric#if _LIBCPP_DEBUG_LEVEL >= 2
14260b57cec5SDimitry Andric
14270b57cec5SDimitry Andric    bool __dereferenceable(const const_iterator* __i) const;
14280b57cec5SDimitry Andric    bool __decrementable(const const_iterator* __i) const;
14290b57cec5SDimitry Andric    bool __addable(const const_iterator* __i, ptrdiff_t __n) const;
14300b57cec5SDimitry Andric    bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const;
14310b57cec5SDimitry Andric
14320b57cec5SDimitry Andric#endif  // _LIBCPP_DEBUG_LEVEL >= 2
14330b57cec5SDimitry Andric
14340b57cec5SDimitry Andricprivate:
14350b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
14360b57cec5SDimitry Andric    allocator_type& __alloc() _NOEXCEPT
14370b57cec5SDimitry Andric        {return __r_.second();}
14380b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
14390b57cec5SDimitry Andric    const allocator_type& __alloc() const _NOEXCEPT
14400b57cec5SDimitry Andric        {return __r_.second();}
14410b57cec5SDimitry Andric
14420b57cec5SDimitry Andric#ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
14430b57cec5SDimitry Andric
14440b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
14450b57cec5SDimitry Andric    void __set_short_size(size_type __s) _NOEXCEPT
14460b57cec5SDimitry Andric#   ifdef _LIBCPP_BIG_ENDIAN
14470b57cec5SDimitry Andric        {__r_.first().__s.__size_ = (unsigned char)(__s << 1);}
14480b57cec5SDimitry Andric#   else
14490b57cec5SDimitry Andric        {__r_.first().__s.__size_ = (unsigned char)(__s);}
14500b57cec5SDimitry Andric#   endif
14510b57cec5SDimitry Andric
14520b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
14530b57cec5SDimitry Andric    size_type __get_short_size() const _NOEXCEPT
14540b57cec5SDimitry Andric#   ifdef _LIBCPP_BIG_ENDIAN
14550b57cec5SDimitry Andric        {return __r_.first().__s.__size_ >> 1;}
14560b57cec5SDimitry Andric#   else
14570b57cec5SDimitry Andric        {return __r_.first().__s.__size_;}
14580b57cec5SDimitry Andric#   endif
14590b57cec5SDimitry Andric
14600b57cec5SDimitry Andric#else  // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
14610b57cec5SDimitry Andric
14620b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
14630b57cec5SDimitry Andric    void __set_short_size(size_type __s) _NOEXCEPT
14640b57cec5SDimitry Andric#   ifdef _LIBCPP_BIG_ENDIAN
14650b57cec5SDimitry Andric        {__r_.first().__s.__size_ = (unsigned char)(__s);}
14660b57cec5SDimitry Andric#   else
14670b57cec5SDimitry Andric        {__r_.first().__s.__size_ = (unsigned char)(__s << 1);}
14680b57cec5SDimitry Andric#   endif
14690b57cec5SDimitry Andric
14700b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
14710b57cec5SDimitry Andric    size_type __get_short_size() const _NOEXCEPT
14720b57cec5SDimitry Andric#   ifdef _LIBCPP_BIG_ENDIAN
14730b57cec5SDimitry Andric        {return __r_.first().__s.__size_;}
14740b57cec5SDimitry Andric#   else
14750b57cec5SDimitry Andric        {return __r_.first().__s.__size_ >> 1;}
14760b57cec5SDimitry Andric#   endif
14770b57cec5SDimitry Andric
14780b57cec5SDimitry Andric#endif  // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
14790b57cec5SDimitry Andric
14800b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
14810b57cec5SDimitry Andric    void __set_long_size(size_type __s) _NOEXCEPT
14820b57cec5SDimitry Andric        {__r_.first().__l.__size_ = __s;}
14830b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
14840b57cec5SDimitry Andric    size_type __get_long_size() const _NOEXCEPT
14850b57cec5SDimitry Andric        {return __r_.first().__l.__size_;}
14860b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
14870b57cec5SDimitry Andric    void __set_size(size_type __s) _NOEXCEPT
14880b57cec5SDimitry Andric        {if (__is_long()) __set_long_size(__s); else __set_short_size(__s);}
14890b57cec5SDimitry Andric
14900b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
14910b57cec5SDimitry Andric    void __set_long_cap(size_type __s) _NOEXCEPT
14920b57cec5SDimitry Andric        {__r_.first().__l.__cap_  = __long_mask | __s;}
14930b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
14940b57cec5SDimitry Andric    size_type __get_long_cap() const _NOEXCEPT
14950b57cec5SDimitry Andric        {return __r_.first().__l.__cap_ & size_type(~__long_mask);}
14960b57cec5SDimitry Andric
14970b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
14980b57cec5SDimitry Andric    void __set_long_pointer(pointer __p) _NOEXCEPT
14990b57cec5SDimitry Andric        {__r_.first().__l.__data_ = __p;}
15000b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
15010b57cec5SDimitry Andric    pointer __get_long_pointer() _NOEXCEPT
15020b57cec5SDimitry Andric        {return __r_.first().__l.__data_;}
15030b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
15040b57cec5SDimitry Andric    const_pointer __get_long_pointer() const _NOEXCEPT
15050b57cec5SDimitry Andric        {return __r_.first().__l.__data_;}
15060b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
15070b57cec5SDimitry Andric    pointer __get_short_pointer() _NOEXCEPT
15080b57cec5SDimitry Andric        {return pointer_traits<pointer>::pointer_to(__r_.first().__s.__data_[0]);}
15090b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
15100b57cec5SDimitry Andric    const_pointer __get_short_pointer() const _NOEXCEPT
15110b57cec5SDimitry Andric        {return pointer_traits<const_pointer>::pointer_to(__r_.first().__s.__data_[0]);}
15120b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
15130b57cec5SDimitry Andric    pointer __get_pointer() _NOEXCEPT
15140b57cec5SDimitry Andric        {return __is_long() ? __get_long_pointer() : __get_short_pointer();}
15150b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
15160b57cec5SDimitry Andric    const_pointer __get_pointer() const _NOEXCEPT
15170b57cec5SDimitry Andric        {return __is_long() ? __get_long_pointer() : __get_short_pointer();}
15180b57cec5SDimitry Andric
15190b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
15200b57cec5SDimitry Andric    void __zero() _NOEXCEPT
15210b57cec5SDimitry Andric        {
15220b57cec5SDimitry Andric            size_type (&__a)[__n_words] = __r_.first().__r.__words;
15230b57cec5SDimitry Andric            for (unsigned __i = 0; __i < __n_words; ++__i)
15240b57cec5SDimitry Andric                __a[__i] = 0;
15250b57cec5SDimitry Andric        }
15260b57cec5SDimitry Andric
15270b57cec5SDimitry Andric    template <size_type __a> static
15280b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY
15290b57cec5SDimitry Andric        size_type __align_it(size_type __s) _NOEXCEPT
15300b57cec5SDimitry Andric            {return (__s + (__a-1)) & ~(__a-1);}
15310b57cec5SDimitry Andric    enum {__alignment = 16};
15320b57cec5SDimitry Andric    static _LIBCPP_INLINE_VISIBILITY
15330b57cec5SDimitry Andric    size_type __recommend(size_type __s) _NOEXCEPT
15340b57cec5SDimitry Andric        {
15350b57cec5SDimitry Andric        if (__s < __min_cap) return static_cast<size_type>(__min_cap) - 1;
15360b57cec5SDimitry Andric        size_type __guess = __align_it<sizeof(value_type) < __alignment ?
15370b57cec5SDimitry Andric                     __alignment/sizeof(value_type) : 1 > (__s+1) - 1;
15380b57cec5SDimitry Andric        if (__guess == __min_cap) ++__guess;
15390b57cec5SDimitry Andric        return __guess;
15400b57cec5SDimitry Andric        }
15410b57cec5SDimitry Andric
15420b57cec5SDimitry Andric    inline
15430b57cec5SDimitry Andric    void __init(const value_type* __s, size_type __sz, size_type __reserve);
15440b57cec5SDimitry Andric    inline
15450b57cec5SDimitry Andric    void __init(const value_type* __s, size_type __sz);
15460b57cec5SDimitry Andric    inline
15470b57cec5SDimitry Andric    void __init(size_type __n, value_type __c);
15480b57cec5SDimitry Andric
1549*5ffd83dbSDimitry Andric    // Slow path for the (inlined) copy constructor for 'long' strings.
1550*5ffd83dbSDimitry Andric    // Always externally instantiated and not inlined.
1551*5ffd83dbSDimitry Andric    // Requires that __s is zero terminated.
1552*5ffd83dbSDimitry Andric    // The main reason for this function to exist is because for unstable, we
1553*5ffd83dbSDimitry Andric    // want to allow inlining of the copy constructor. However, we don't want
1554*5ffd83dbSDimitry Andric    // to call the __init() functions as those are marked as inline which may
1555*5ffd83dbSDimitry Andric    // result in over-aggressive inlining by the compiler, where our aim is
1556*5ffd83dbSDimitry Andric    // to only inline the fast path code directly in the ctor.
1557*5ffd83dbSDimitry Andric    void __init_copy_ctor_external(const value_type* __s, size_type __sz);
1558*5ffd83dbSDimitry Andric
15590b57cec5SDimitry Andric    template <class _InputIterator>
15600b57cec5SDimitry Andric    inline
1561*5ffd83dbSDimitry Andric    _EnableIf
15620b57cec5SDimitry Andric    <
1563*5ffd83dbSDimitry Andric        __is_exactly_cpp17_input_iterator<_InputIterator>::value
1564*5ffd83dbSDimitry Andric    >
15650b57cec5SDimitry Andric    __init(_InputIterator __first, _InputIterator __last);
15660b57cec5SDimitry Andric
15670b57cec5SDimitry Andric    template <class _ForwardIterator>
15680b57cec5SDimitry Andric    inline
1569*5ffd83dbSDimitry Andric    _EnableIf
15700b57cec5SDimitry Andric    <
1571*5ffd83dbSDimitry Andric        __is_cpp17_forward_iterator<_ForwardIterator>::value
1572*5ffd83dbSDimitry Andric    >
15730b57cec5SDimitry Andric    __init(_ForwardIterator __first, _ForwardIterator __last);
15740b57cec5SDimitry Andric
15750b57cec5SDimitry Andric    void __grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
15760b57cec5SDimitry Andric                   size_type __n_copy,  size_type __n_del,     size_type __n_add = 0);
15770b57cec5SDimitry Andric    void __grow_by_and_replace(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
15780b57cec5SDimitry Andric                               size_type __n_copy,  size_type __n_del,
15790b57cec5SDimitry Andric                               size_type __n_add, const value_type* __p_new_stuff);
15800b57cec5SDimitry Andric
1581*5ffd83dbSDimitry Andric    // __assign_no_alias is invoked for assignment operations where we
1582*5ffd83dbSDimitry Andric    // have proof that the input does not alias the current instance.
1583*5ffd83dbSDimitry Andric    // For example, operator=(basic_string) performs a 'self' check.
1584*5ffd83dbSDimitry Andric    template <bool __is_short>
1585*5ffd83dbSDimitry Andric    basic_string& __assign_no_alias(const value_type* __s, size_type __n);
1586*5ffd83dbSDimitry Andric
15870b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
15880b57cec5SDimitry Andric    void __erase_to_end(size_type __pos);
15890b57cec5SDimitry Andric
1590*5ffd83dbSDimitry Andric    // __erase_external_with_move is invoked for erase() invocations where
1591*5ffd83dbSDimitry Andric    // `n ~= npos`, likely requiring memory moves on the string data.
1592*5ffd83dbSDimitry Andric    void __erase_external_with_move(size_type __pos, size_type __n);
1593*5ffd83dbSDimitry Andric
15940b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
15950b57cec5SDimitry Andric    void __copy_assign_alloc(const basic_string& __str)
15960b57cec5SDimitry Andric        {__copy_assign_alloc(__str, integral_constant<bool,
15970b57cec5SDimitry Andric                      __alloc_traits::propagate_on_container_copy_assignment::value>());}
15980b57cec5SDimitry Andric
15990b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
16000b57cec5SDimitry Andric    void __copy_assign_alloc(const basic_string& __str, true_type)
16010b57cec5SDimitry Andric        {
16020b57cec5SDimitry Andric            if (__alloc() == __str.__alloc())
16030b57cec5SDimitry Andric                __alloc() = __str.__alloc();
16040b57cec5SDimitry Andric            else
16050b57cec5SDimitry Andric            {
16060b57cec5SDimitry Andric                if (!__str.__is_long())
16070b57cec5SDimitry Andric                {
16080b57cec5SDimitry Andric                    __clear_and_shrink();
16090b57cec5SDimitry Andric                    __alloc() = __str.__alloc();
16100b57cec5SDimitry Andric                }
16110b57cec5SDimitry Andric                else
16120b57cec5SDimitry Andric                {
16130b57cec5SDimitry Andric                    allocator_type __a = __str.__alloc();
16140b57cec5SDimitry Andric                    pointer __p = __alloc_traits::allocate(__a, __str.__get_long_cap());
16150b57cec5SDimitry Andric                    __clear_and_shrink();
16160b57cec5SDimitry Andric                    __alloc() = _VSTD::move(__a);
16170b57cec5SDimitry Andric                    __set_long_pointer(__p);
16180b57cec5SDimitry Andric                    __set_long_cap(__str.__get_long_cap());
16190b57cec5SDimitry Andric                    __set_long_size(__str.size());
16200b57cec5SDimitry Andric                }
16210b57cec5SDimitry Andric            }
16220b57cec5SDimitry Andric        }
16230b57cec5SDimitry Andric
16240b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
16250b57cec5SDimitry Andric    void __copy_assign_alloc(const basic_string&, false_type) _NOEXCEPT
16260b57cec5SDimitry Andric        {}
16270b57cec5SDimitry Andric
16280b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
16290b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
16300b57cec5SDimitry Andric    void __move_assign(basic_string& __str, false_type)
16310b57cec5SDimitry Andric        _NOEXCEPT_(__alloc_traits::is_always_equal::value);
16320b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
16330b57cec5SDimitry Andric    void __move_assign(basic_string& __str, true_type)
16340b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 14
16350b57cec5SDimitry Andric        _NOEXCEPT;
16360b57cec5SDimitry Andric#else
16370b57cec5SDimitry Andric        _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
16380b57cec5SDimitry Andric#endif
16390b57cec5SDimitry Andric#endif
16400b57cec5SDimitry Andric
16410b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
16420b57cec5SDimitry Andric    void
16430b57cec5SDimitry Andric    __move_assign_alloc(basic_string& __str)
16440b57cec5SDimitry Andric        _NOEXCEPT_(
16450b57cec5SDimitry Andric            !__alloc_traits::propagate_on_container_move_assignment::value ||
16460b57cec5SDimitry Andric            is_nothrow_move_assignable<allocator_type>::value)
16470b57cec5SDimitry Andric    {__move_assign_alloc(__str, integral_constant<bool,
16480b57cec5SDimitry Andric                      __alloc_traits::propagate_on_container_move_assignment::value>());}
16490b57cec5SDimitry Andric
16500b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
16510b57cec5SDimitry Andric    void __move_assign_alloc(basic_string& __c, true_type)
16520b57cec5SDimitry Andric        _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
16530b57cec5SDimitry Andric        {
16540b57cec5SDimitry Andric            __alloc() = _VSTD::move(__c.__alloc());
16550b57cec5SDimitry Andric        }
16560b57cec5SDimitry Andric
16570b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
16580b57cec5SDimitry Andric    void __move_assign_alloc(basic_string&, false_type)
16590b57cec5SDimitry Andric        _NOEXCEPT
16600b57cec5SDimitry Andric        {}
16610b57cec5SDimitry Andric
1662*5ffd83dbSDimitry Andric    basic_string& __assign_external(const value_type* __s);
1663*5ffd83dbSDimitry Andric    basic_string& __assign_external(const value_type* __s, size_type __n);
1664*5ffd83dbSDimitry Andric
1665*5ffd83dbSDimitry Andric    // Assigns the value in __s, guaranteed to be __n < __min_cap in length.
1666*5ffd83dbSDimitry Andric    inline basic_string& __assign_short(const value_type* __s, size_type __n) {
1667*5ffd83dbSDimitry Andric      pointer __p = __is_long()
1668*5ffd83dbSDimitry Andric                        ? (__set_long_size(__n), __get_long_pointer())
1669*5ffd83dbSDimitry Andric                        : (__set_short_size(__n), __get_short_pointer());
1670*5ffd83dbSDimitry Andric      traits_type::move(_VSTD::__to_address(__p), __s, __n);
1671*5ffd83dbSDimitry Andric      traits_type::assign(__p[__n], value_type());
1672*5ffd83dbSDimitry Andric      return *this;
1673*5ffd83dbSDimitry Andric    }
1674*5ffd83dbSDimitry Andric
16750b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators();
16760b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY void __invalidate_iterators_past(size_type);
16770b57cec5SDimitry Andric
16780b57cec5SDimitry Andric    friend basic_string operator+<>(const basic_string&, const basic_string&);
16790b57cec5SDimitry Andric    friend basic_string operator+<>(const value_type*, const basic_string&);
16800b57cec5SDimitry Andric    friend basic_string operator+<>(value_type, const basic_string&);
16810b57cec5SDimitry Andric    friend basic_string operator+<>(const basic_string&, const value_type*);
16820b57cec5SDimitry Andric    friend basic_string operator+<>(const basic_string&, value_type);
16830b57cec5SDimitry Andric};
16840b57cec5SDimitry Andric
1685*5ffd83dbSDimitry Andric// These declarations must appear before any functions are implicitly used
1686*5ffd83dbSDimitry Andric// so that they have the correct visibility specifier.
1687*5ffd83dbSDimitry Andric#ifdef _LIBCPP_ABI_STRING_OPTIMIZED_EXTERNAL_INSTANTIATION
1688*5ffd83dbSDimitry Andric_LIBCPP_STRING_UNSTABLE_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE, char)
1689*5ffd83dbSDimitry Andric_LIBCPP_STRING_UNSTABLE_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE, wchar_t)
1690*5ffd83dbSDimitry Andric#else
1691*5ffd83dbSDimitry Andric_LIBCPP_STRING_V1_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE, char)
1692*5ffd83dbSDimitry Andric_LIBCPP_STRING_V1_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE, wchar_t)
1693*5ffd83dbSDimitry Andric#endif
1694*5ffd83dbSDimitry Andric
1695*5ffd83dbSDimitry Andric
16960b57cec5SDimitry Andric#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
16970b57cec5SDimitry Andrictemplate<class _InputIterator,
16980b57cec5SDimitry Andric         class _CharT = typename iterator_traits<_InputIterator>::value_type,
16990b57cec5SDimitry Andric         class _Allocator = allocator<_CharT>,
1700*5ffd83dbSDimitry Andric         class = _EnableIf<__is_cpp17_input_iterator<_InputIterator>::value>,
1701*5ffd83dbSDimitry Andric         class = _EnableIf<__is_allocator<_Allocator>::value>
17020b57cec5SDimitry Andric         >
17030b57cec5SDimitry Andricbasic_string(_InputIterator, _InputIterator, _Allocator = _Allocator())
17040b57cec5SDimitry Andric  -> basic_string<_CharT, char_traits<_CharT>, _Allocator>;
17050b57cec5SDimitry Andric
17060b57cec5SDimitry Andrictemplate<class _CharT,
17070b57cec5SDimitry Andric         class _Traits,
17080b57cec5SDimitry Andric         class _Allocator = allocator<_CharT>,
1709*5ffd83dbSDimitry Andric         class = _EnableIf<__is_allocator<_Allocator>::value>
17100b57cec5SDimitry Andric         >
17110b57cec5SDimitry Andricexplicit basic_string(basic_string_view<_CharT, _Traits>, const _Allocator& = _Allocator())
17120b57cec5SDimitry Andric  -> basic_string<_CharT, _Traits, _Allocator>;
17130b57cec5SDimitry Andric
17140b57cec5SDimitry Andrictemplate<class _CharT,
17150b57cec5SDimitry Andric         class _Traits,
17160b57cec5SDimitry Andric         class _Allocator = allocator<_CharT>,
1717*5ffd83dbSDimitry Andric         class = _EnableIf<__is_allocator<_Allocator>::value>,
17180b57cec5SDimitry Andric         class _Sz = typename allocator_traits<_Allocator>::size_type
17190b57cec5SDimitry Andric         >
17200b57cec5SDimitry Andricbasic_string(basic_string_view<_CharT, _Traits>, _Sz, _Sz, const _Allocator& = _Allocator())
17210b57cec5SDimitry Andric  -> basic_string<_CharT, _Traits, _Allocator>;
17220b57cec5SDimitry Andric#endif
17230b57cec5SDimitry Andric
17240b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
17250b57cec5SDimitry Andricinline
17260b57cec5SDimitry Andricvoid
17270b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::__invalidate_all_iterators()
17280b57cec5SDimitry Andric{
17290b57cec5SDimitry Andric#if _LIBCPP_DEBUG_LEVEL >= 2
17300b57cec5SDimitry Andric    __get_db()->__invalidate_all(this);
17310b57cec5SDimitry Andric#endif  // _LIBCPP_DEBUG_LEVEL >= 2
17320b57cec5SDimitry Andric}
17330b57cec5SDimitry Andric
17340b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
17350b57cec5SDimitry Andricinline
17360b57cec5SDimitry Andricvoid
17370b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::__invalidate_iterators_past(size_type
17380b57cec5SDimitry Andric#if _LIBCPP_DEBUG_LEVEL >= 2
17390b57cec5SDimitry Andric                                                                        __pos
17400b57cec5SDimitry Andric#endif
17410b57cec5SDimitry Andric                                                                      )
17420b57cec5SDimitry Andric{
17430b57cec5SDimitry Andric#if _LIBCPP_DEBUG_LEVEL >= 2
17440b57cec5SDimitry Andric    __c_node* __c = __get_db()->__find_c_and_lock(this);
17450b57cec5SDimitry Andric    if (__c)
17460b57cec5SDimitry Andric    {
17470b57cec5SDimitry Andric        const_pointer __new_last = __get_pointer() + __pos;
17480b57cec5SDimitry Andric        for (__i_node** __p = __c->end_; __p != __c->beg_; )
17490b57cec5SDimitry Andric        {
17500b57cec5SDimitry Andric            --__p;
17510b57cec5SDimitry Andric            const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_);
17520b57cec5SDimitry Andric            if (__i->base() > __new_last)
17530b57cec5SDimitry Andric            {
17540b57cec5SDimitry Andric                (*__p)->__c_ = nullptr;
17550b57cec5SDimitry Andric                if (--__c->end_ != __p)
17560b57cec5SDimitry Andric                    memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
17570b57cec5SDimitry Andric            }
17580b57cec5SDimitry Andric        }
17590b57cec5SDimitry Andric        __get_db()->unlock();
17600b57cec5SDimitry Andric    }
17610b57cec5SDimitry Andric#endif  // _LIBCPP_DEBUG_LEVEL >= 2
17620b57cec5SDimitry Andric}
17630b57cec5SDimitry Andric
17640b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
17650b57cec5SDimitry Andricinline
17660b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::basic_string()
17670b57cec5SDimitry Andric    _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
1768480093f4SDimitry Andric     : __r_(__default_init_tag(), __default_init_tag())
17690b57cec5SDimitry Andric{
17700b57cec5SDimitry Andric#if _LIBCPP_DEBUG_LEVEL >= 2
17710b57cec5SDimitry Andric    __get_db()->__insert_c(this);
17720b57cec5SDimitry Andric#endif
17730b57cec5SDimitry Andric    __zero();
17740b57cec5SDimitry Andric}
17750b57cec5SDimitry Andric
17760b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
17770b57cec5SDimitry Andricinline
17780b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::basic_string(const allocator_type& __a)
17790b57cec5SDimitry Andric#if _LIBCPP_STD_VER <= 14
17800b57cec5SDimitry Andric        _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value)
17810b57cec5SDimitry Andric#else
17820b57cec5SDimitry Andric        _NOEXCEPT
17830b57cec5SDimitry Andric#endif
1784480093f4SDimitry Andric: __r_(__default_init_tag(), __a)
17850b57cec5SDimitry Andric{
17860b57cec5SDimitry Andric#if _LIBCPP_DEBUG_LEVEL >= 2
17870b57cec5SDimitry Andric    __get_db()->__insert_c(this);
17880b57cec5SDimitry Andric#endif
17890b57cec5SDimitry Andric    __zero();
17900b57cec5SDimitry Andric}
17910b57cec5SDimitry Andric
17920b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
17930b57cec5SDimitry Andricvoid basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s,
17940b57cec5SDimitry Andric                                                       size_type __sz,
17950b57cec5SDimitry Andric                                                       size_type __reserve)
17960b57cec5SDimitry Andric{
17970b57cec5SDimitry Andric    if (__reserve > max_size())
17980b57cec5SDimitry Andric        this->__throw_length_error();
17990b57cec5SDimitry Andric    pointer __p;
18000b57cec5SDimitry Andric    if (__reserve < __min_cap)
18010b57cec5SDimitry Andric    {
18020b57cec5SDimitry Andric        __set_short_size(__sz);
18030b57cec5SDimitry Andric        __p = __get_short_pointer();
18040b57cec5SDimitry Andric    }
18050b57cec5SDimitry Andric    else
18060b57cec5SDimitry Andric    {
18070b57cec5SDimitry Andric        size_type __cap = __recommend(__reserve);
18080b57cec5SDimitry Andric        __p = __alloc_traits::allocate(__alloc(), __cap+1);
18090b57cec5SDimitry Andric        __set_long_pointer(__p);
18100b57cec5SDimitry Andric        __set_long_cap(__cap+1);
18110b57cec5SDimitry Andric        __set_long_size(__sz);
18120b57cec5SDimitry Andric    }
1813480093f4SDimitry Andric    traits_type::copy(_VSTD::__to_address(__p), __s, __sz);
18140b57cec5SDimitry Andric    traits_type::assign(__p[__sz], value_type());
18150b57cec5SDimitry Andric}
18160b57cec5SDimitry Andric
18170b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
18180b57cec5SDimitry Andricvoid
18190b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, size_type __sz)
18200b57cec5SDimitry Andric{
18210b57cec5SDimitry Andric    if (__sz > max_size())
18220b57cec5SDimitry Andric        this->__throw_length_error();
18230b57cec5SDimitry Andric    pointer __p;
18240b57cec5SDimitry Andric    if (__sz < __min_cap)
18250b57cec5SDimitry Andric    {
18260b57cec5SDimitry Andric        __set_short_size(__sz);
18270b57cec5SDimitry Andric        __p = __get_short_pointer();
18280b57cec5SDimitry Andric    }
18290b57cec5SDimitry Andric    else
18300b57cec5SDimitry Andric    {
18310b57cec5SDimitry Andric        size_type __cap = __recommend(__sz);
18320b57cec5SDimitry Andric        __p = __alloc_traits::allocate(__alloc(), __cap+1);
18330b57cec5SDimitry Andric        __set_long_pointer(__p);
18340b57cec5SDimitry Andric        __set_long_cap(__cap+1);
18350b57cec5SDimitry Andric        __set_long_size(__sz);
18360b57cec5SDimitry Andric    }
1837480093f4SDimitry Andric    traits_type::copy(_VSTD::__to_address(__p), __s, __sz);
18380b57cec5SDimitry Andric    traits_type::assign(__p[__sz], value_type());
18390b57cec5SDimitry Andric}
18400b57cec5SDimitry Andric
18410b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
18420b57cec5SDimitry Andrictemplate <class>
18430b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, const _Allocator& __a)
1844480093f4SDimitry Andric    : __r_(__default_init_tag(), __a)
18450b57cec5SDimitry Andric{
18460b57cec5SDimitry Andric    _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*, allocator) detected nullptr");
18470b57cec5SDimitry Andric    __init(__s, traits_type::length(__s));
18480b57cec5SDimitry Andric#if _LIBCPP_DEBUG_LEVEL >= 2
18490b57cec5SDimitry Andric    __get_db()->__insert_c(this);
18500b57cec5SDimitry Andric#endif
18510b57cec5SDimitry Andric}
18520b57cec5SDimitry Andric
18530b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
18540b57cec5SDimitry Andricinline
18550b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, size_type __n)
1856480093f4SDimitry Andric     : __r_(__default_init_tag(), __default_init_tag())
18570b57cec5SDimitry Andric{
18580b57cec5SDimitry Andric    _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n) detected nullptr");
18590b57cec5SDimitry Andric    __init(__s, __n);
18600b57cec5SDimitry Andric#if _LIBCPP_DEBUG_LEVEL >= 2
18610b57cec5SDimitry Andric    __get_db()->__insert_c(this);
18620b57cec5SDimitry Andric#endif
18630b57cec5SDimitry Andric}
18640b57cec5SDimitry Andric
18650b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
18660b57cec5SDimitry Andricinline
18670b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, size_type __n, const _Allocator& __a)
1868480093f4SDimitry Andric    : __r_(__default_init_tag(), __a)
18690b57cec5SDimitry Andric{
18700b57cec5SDimitry Andric    _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n, allocator) detected nullptr");
18710b57cec5SDimitry Andric    __init(__s, __n);
18720b57cec5SDimitry Andric#if _LIBCPP_DEBUG_LEVEL >= 2
18730b57cec5SDimitry Andric    __get_db()->__insert_c(this);
18740b57cec5SDimitry Andric#endif
18750b57cec5SDimitry Andric}
18760b57cec5SDimitry Andric
18770b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
18780b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str)
1879480093f4SDimitry Andric    : __r_(__default_init_tag(), __alloc_traits::select_on_container_copy_construction(__str.__alloc()))
18800b57cec5SDimitry Andric{
18810b57cec5SDimitry Andric    if (!__str.__is_long())
18820b57cec5SDimitry Andric        __r_.first().__r = __str.__r_.first().__r;
18830b57cec5SDimitry Andric    else
1884*5ffd83dbSDimitry Andric        __init_copy_ctor_external(_VSTD::__to_address(__str.__get_long_pointer()),
1885*5ffd83dbSDimitry Andric                                  __str.__get_long_size());
1886*5ffd83dbSDimitry Andric
18870b57cec5SDimitry Andric#if _LIBCPP_DEBUG_LEVEL >= 2
18880b57cec5SDimitry Andric    __get_db()->__insert_c(this);
18890b57cec5SDimitry Andric#endif
18900b57cec5SDimitry Andric}
18910b57cec5SDimitry Andric
18920b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
18930b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::basic_string(
18940b57cec5SDimitry Andric    const basic_string& __str, const allocator_type& __a)
1895480093f4SDimitry Andric    : __r_(__default_init_tag(), __a)
18960b57cec5SDimitry Andric{
18970b57cec5SDimitry Andric    if (!__str.__is_long())
18980b57cec5SDimitry Andric        __r_.first().__r = __str.__r_.first().__r;
18990b57cec5SDimitry Andric    else
1900*5ffd83dbSDimitry Andric        __init_copy_ctor_external(_VSTD::__to_address(__str.__get_long_pointer()),
1901*5ffd83dbSDimitry Andric                                  __str.__get_long_size());
19020b57cec5SDimitry Andric#if _LIBCPP_DEBUG_LEVEL >= 2
19030b57cec5SDimitry Andric    __get_db()->__insert_c(this);
19040b57cec5SDimitry Andric#endif
19050b57cec5SDimitry Andric}
19060b57cec5SDimitry Andric
1907*5ffd83dbSDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
1908*5ffd83dbSDimitry Andricvoid basic_string<_CharT, _Traits, _Allocator>::__init_copy_ctor_external(
1909*5ffd83dbSDimitry Andric    const value_type* __s, size_type __sz) {
1910*5ffd83dbSDimitry Andric  pointer __p;
1911*5ffd83dbSDimitry Andric  if (__sz < __min_cap) {
1912*5ffd83dbSDimitry Andric    __p = __get_short_pointer();
1913*5ffd83dbSDimitry Andric    __set_short_size(__sz);
1914*5ffd83dbSDimitry Andric  } else {
1915*5ffd83dbSDimitry Andric    if (__sz > max_size())
1916*5ffd83dbSDimitry Andric      this->__throw_length_error();
1917*5ffd83dbSDimitry Andric    size_t __cap = __recommend(__sz);
1918*5ffd83dbSDimitry Andric    __p = __alloc_traits::allocate(__alloc(), __cap + 1);
1919*5ffd83dbSDimitry Andric    __set_long_pointer(__p);
1920*5ffd83dbSDimitry Andric    __set_long_cap(__cap + 1);
1921*5ffd83dbSDimitry Andric    __set_long_size(__sz);
1922*5ffd83dbSDimitry Andric  }
1923*5ffd83dbSDimitry Andric  traits_type::copy(_VSTD::__to_address(__p), __s, __sz + 1);
1924*5ffd83dbSDimitry Andric}
1925*5ffd83dbSDimitry Andric
19260b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
19270b57cec5SDimitry Andric
19280b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
19290b57cec5SDimitry Andricinline
19300b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str)
19310b57cec5SDimitry Andric#if _LIBCPP_STD_VER <= 14
19320b57cec5SDimitry Andric        _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
19330b57cec5SDimitry Andric#else
19340b57cec5SDimitry Andric        _NOEXCEPT
19350b57cec5SDimitry Andric#endif
19360b57cec5SDimitry Andric    : __r_(_VSTD::move(__str.__r_))
19370b57cec5SDimitry Andric{
19380b57cec5SDimitry Andric    __str.__zero();
19390b57cec5SDimitry Andric#if _LIBCPP_DEBUG_LEVEL >= 2
19400b57cec5SDimitry Andric    __get_db()->__insert_c(this);
19410b57cec5SDimitry Andric    if (__is_long())
19420b57cec5SDimitry Andric        __get_db()->swap(this, &__str);
19430b57cec5SDimitry Andric#endif
19440b57cec5SDimitry Andric}
19450b57cec5SDimitry Andric
19460b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
19470b57cec5SDimitry Andricinline
19480b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str, const allocator_type& __a)
1949480093f4SDimitry Andric    : __r_(__default_init_tag(), __a)
19500b57cec5SDimitry Andric{
19510b57cec5SDimitry Andric    if (__str.__is_long() && __a != __str.__alloc()) // copy, not move
1952480093f4SDimitry Andric        __init(_VSTD::__to_address(__str.__get_long_pointer()), __str.__get_long_size());
19530b57cec5SDimitry Andric    else
19540b57cec5SDimitry Andric    {
19550b57cec5SDimitry Andric        __r_.first().__r = __str.__r_.first().__r;
19560b57cec5SDimitry Andric        __str.__zero();
19570b57cec5SDimitry Andric    }
19580b57cec5SDimitry Andric#if _LIBCPP_DEBUG_LEVEL >= 2
19590b57cec5SDimitry Andric    __get_db()->__insert_c(this);
19600b57cec5SDimitry Andric    if (__is_long())
19610b57cec5SDimitry Andric        __get_db()->swap(this, &__str);
19620b57cec5SDimitry Andric#endif
19630b57cec5SDimitry Andric}
19640b57cec5SDimitry Andric
19650b57cec5SDimitry Andric#endif  // _LIBCPP_CXX03_LANG
19660b57cec5SDimitry Andric
19670b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
19680b57cec5SDimitry Andricvoid
19690b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::__init(size_type __n, value_type __c)
19700b57cec5SDimitry Andric{
19710b57cec5SDimitry Andric    if (__n > max_size())
19720b57cec5SDimitry Andric        this->__throw_length_error();
19730b57cec5SDimitry Andric    pointer __p;
19740b57cec5SDimitry Andric    if (__n < __min_cap)
19750b57cec5SDimitry Andric    {
19760b57cec5SDimitry Andric        __set_short_size(__n);
19770b57cec5SDimitry Andric        __p = __get_short_pointer();
19780b57cec5SDimitry Andric    }
19790b57cec5SDimitry Andric    else
19800b57cec5SDimitry Andric    {
19810b57cec5SDimitry Andric        size_type __cap = __recommend(__n);
19820b57cec5SDimitry Andric        __p = __alloc_traits::allocate(__alloc(), __cap+1);
19830b57cec5SDimitry Andric        __set_long_pointer(__p);
19840b57cec5SDimitry Andric        __set_long_cap(__cap+1);
19850b57cec5SDimitry Andric        __set_long_size(__n);
19860b57cec5SDimitry Andric    }
1987480093f4SDimitry Andric    traits_type::assign(_VSTD::__to_address(__p), __n, __c);
19880b57cec5SDimitry Andric    traits_type::assign(__p[__n], value_type());
19890b57cec5SDimitry Andric}
19900b57cec5SDimitry Andric
19910b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
19920b57cec5SDimitry Andricinline
19930b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, _CharT __c)
1994480093f4SDimitry Andric     : __r_(__default_init_tag(), __default_init_tag())
19950b57cec5SDimitry Andric{
19960b57cec5SDimitry Andric    __init(__n, __c);
19970b57cec5SDimitry Andric#if _LIBCPP_DEBUG_LEVEL >= 2
19980b57cec5SDimitry Andric    __get_db()->__insert_c(this);
19990b57cec5SDimitry Andric#endif
20000b57cec5SDimitry Andric}
20010b57cec5SDimitry Andric
20020b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
20030b57cec5SDimitry Andrictemplate <class>
20040b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, _CharT __c, const _Allocator& __a)
2005480093f4SDimitry Andric    : __r_(__default_init_tag(), __a)
20060b57cec5SDimitry Andric{
20070b57cec5SDimitry Andric    __init(__n, __c);
20080b57cec5SDimitry Andric#if _LIBCPP_DEBUG_LEVEL >= 2
20090b57cec5SDimitry Andric    __get_db()->__insert_c(this);
20100b57cec5SDimitry Andric#endif
20110b57cec5SDimitry Andric}
20120b57cec5SDimitry Andric
20130b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
20140b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str,
20150b57cec5SDimitry Andric                                                        size_type __pos, size_type __n,
20160b57cec5SDimitry Andric                                                        const _Allocator& __a)
2017480093f4SDimitry Andric    : __r_(__default_init_tag(), __a)
20180b57cec5SDimitry Andric{
20190b57cec5SDimitry Andric    size_type __str_sz = __str.size();
20200b57cec5SDimitry Andric    if (__pos > __str_sz)
20210b57cec5SDimitry Andric        this->__throw_out_of_range();
20220b57cec5SDimitry Andric    __init(__str.data() + __pos, _VSTD::min(__n, __str_sz - __pos));
20230b57cec5SDimitry Andric#if _LIBCPP_DEBUG_LEVEL >= 2
20240b57cec5SDimitry Andric    __get_db()->__insert_c(this);
20250b57cec5SDimitry Andric#endif
20260b57cec5SDimitry Andric}
20270b57cec5SDimitry Andric
20280b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
20290b57cec5SDimitry Andricinline
20300b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str, size_type __pos,
20310b57cec5SDimitry Andric                                                        const _Allocator& __a)
2032480093f4SDimitry Andric    : __r_(__default_init_tag(), __a)
20330b57cec5SDimitry Andric{
20340b57cec5SDimitry Andric    size_type __str_sz = __str.size();
20350b57cec5SDimitry Andric    if (__pos > __str_sz)
20360b57cec5SDimitry Andric        this->__throw_out_of_range();
20370b57cec5SDimitry Andric    __init(__str.data() + __pos, __str_sz - __pos);
20380b57cec5SDimitry Andric#if _LIBCPP_DEBUG_LEVEL >= 2
20390b57cec5SDimitry Andric    __get_db()->__insert_c(this);
20400b57cec5SDimitry Andric#endif
20410b57cec5SDimitry Andric}
20420b57cec5SDimitry Andric
20430b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
20440b57cec5SDimitry Andrictemplate <class _Tp, class>
20450b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::basic_string(
20460b57cec5SDimitry Andric             const _Tp& __t, size_type __pos, size_type __n, const allocator_type& __a)
2047480093f4SDimitry Andric    : __r_(__default_init_tag(), __a)
20480b57cec5SDimitry Andric{
20490b57cec5SDimitry Andric    __self_view __sv0 = __t;
20500b57cec5SDimitry Andric    __self_view __sv = __sv0.substr(__pos, __n);
20510b57cec5SDimitry Andric    __init(__sv.data(), __sv.size());
20520b57cec5SDimitry Andric#if _LIBCPP_DEBUG_LEVEL >= 2
20530b57cec5SDimitry Andric    __get_db()->__insert_c(this);
20540b57cec5SDimitry Andric#endif
20550b57cec5SDimitry Andric}
20560b57cec5SDimitry Andric
20570b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
20580b57cec5SDimitry Andrictemplate <class _Tp, class>
20590b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::basic_string(const _Tp & __t)
2060480093f4SDimitry Andric     : __r_(__default_init_tag(), __default_init_tag())
20610b57cec5SDimitry Andric{
20620b57cec5SDimitry Andric    __self_view __sv = __t;
20630b57cec5SDimitry Andric    __init(__sv.data(), __sv.size());
20640b57cec5SDimitry Andric#if _LIBCPP_DEBUG_LEVEL >= 2
20650b57cec5SDimitry Andric    __get_db()->__insert_c(this);
20660b57cec5SDimitry Andric#endif
20670b57cec5SDimitry Andric}
20680b57cec5SDimitry Andric
20690b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
20700b57cec5SDimitry Andrictemplate <class _Tp, class>
20710b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::basic_string(const _Tp & __t, const _Allocator& __a)
2072480093f4SDimitry Andric    : __r_(__default_init_tag(), __a)
20730b57cec5SDimitry Andric{
20740b57cec5SDimitry Andric    __self_view __sv = __t;
20750b57cec5SDimitry Andric    __init(__sv.data(), __sv.size());
20760b57cec5SDimitry Andric#if _LIBCPP_DEBUG_LEVEL >= 2
20770b57cec5SDimitry Andric    __get_db()->__insert_c(this);
20780b57cec5SDimitry Andric#endif
20790b57cec5SDimitry Andric}
20800b57cec5SDimitry Andric
20810b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
20820b57cec5SDimitry Andrictemplate <class _InputIterator>
2083*5ffd83dbSDimitry Andric_EnableIf
20840b57cec5SDimitry Andric<
2085*5ffd83dbSDimitry Andric    __is_exactly_cpp17_input_iterator<_InputIterator>::value
2086*5ffd83dbSDimitry Andric>
20870b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::__init(_InputIterator __first, _InputIterator __last)
20880b57cec5SDimitry Andric{
20890b57cec5SDimitry Andric    __zero();
20900b57cec5SDimitry Andric#ifndef _LIBCPP_NO_EXCEPTIONS
20910b57cec5SDimitry Andric    try
20920b57cec5SDimitry Andric    {
20930b57cec5SDimitry Andric#endif  // _LIBCPP_NO_EXCEPTIONS
20940b57cec5SDimitry Andric    for (; __first != __last; ++__first)
20950b57cec5SDimitry Andric        push_back(*__first);
20960b57cec5SDimitry Andric#ifndef _LIBCPP_NO_EXCEPTIONS
20970b57cec5SDimitry Andric    }
20980b57cec5SDimitry Andric    catch (...)
20990b57cec5SDimitry Andric    {
21000b57cec5SDimitry Andric        if (__is_long())
21010b57cec5SDimitry Andric            __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
21020b57cec5SDimitry Andric        throw;
21030b57cec5SDimitry Andric    }
21040b57cec5SDimitry Andric#endif  // _LIBCPP_NO_EXCEPTIONS
21050b57cec5SDimitry Andric}
21060b57cec5SDimitry Andric
21070b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
21080b57cec5SDimitry Andrictemplate <class _ForwardIterator>
2109*5ffd83dbSDimitry Andric_EnableIf
21100b57cec5SDimitry Andric<
2111*5ffd83dbSDimitry Andric    __is_cpp17_forward_iterator<_ForwardIterator>::value
2112*5ffd83dbSDimitry Andric>
21130b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::__init(_ForwardIterator __first, _ForwardIterator __last)
21140b57cec5SDimitry Andric{
21150b57cec5SDimitry Andric    size_type __sz = static_cast<size_type>(_VSTD::distance(__first, __last));
21160b57cec5SDimitry Andric    if (__sz > max_size())
21170b57cec5SDimitry Andric        this->__throw_length_error();
21180b57cec5SDimitry Andric    pointer __p;
21190b57cec5SDimitry Andric    if (__sz < __min_cap)
21200b57cec5SDimitry Andric    {
21210b57cec5SDimitry Andric        __set_short_size(__sz);
21220b57cec5SDimitry Andric        __p = __get_short_pointer();
21230b57cec5SDimitry Andric    }
21240b57cec5SDimitry Andric    else
21250b57cec5SDimitry Andric    {
21260b57cec5SDimitry Andric        size_type __cap = __recommend(__sz);
21270b57cec5SDimitry Andric        __p = __alloc_traits::allocate(__alloc(), __cap+1);
21280b57cec5SDimitry Andric        __set_long_pointer(__p);
21290b57cec5SDimitry Andric        __set_long_cap(__cap+1);
21300b57cec5SDimitry Andric        __set_long_size(__sz);
21310b57cec5SDimitry Andric    }
21320b57cec5SDimitry Andric    for (; __first != __last; ++__first, (void) ++__p)
21330b57cec5SDimitry Andric        traits_type::assign(*__p, *__first);
21340b57cec5SDimitry Andric    traits_type::assign(*__p, value_type());
21350b57cec5SDimitry Andric}
21360b57cec5SDimitry Andric
21370b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
21380b57cec5SDimitry Andrictemplate<class _InputIterator, class>
21390b57cec5SDimitry Andricinline
21400b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last)
2141480093f4SDimitry Andric     : __r_(__default_init_tag(), __default_init_tag())
21420b57cec5SDimitry Andric{
21430b57cec5SDimitry Andric    __init(__first, __last);
21440b57cec5SDimitry Andric#if _LIBCPP_DEBUG_LEVEL >= 2
21450b57cec5SDimitry Andric    __get_db()->__insert_c(this);
21460b57cec5SDimitry Andric#endif
21470b57cec5SDimitry Andric}
21480b57cec5SDimitry Andric
21490b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
21500b57cec5SDimitry Andrictemplate<class _InputIterator, class>
21510b57cec5SDimitry Andricinline
21520b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last,
21530b57cec5SDimitry Andric                                                        const allocator_type& __a)
2154480093f4SDimitry Andric    : __r_(__default_init_tag(), __a)
21550b57cec5SDimitry Andric{
21560b57cec5SDimitry Andric    __init(__first, __last);
21570b57cec5SDimitry Andric#if _LIBCPP_DEBUG_LEVEL >= 2
21580b57cec5SDimitry Andric    __get_db()->__insert_c(this);
21590b57cec5SDimitry Andric#endif
21600b57cec5SDimitry Andric}
21610b57cec5SDimitry Andric
21620b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
21630b57cec5SDimitry Andric
21640b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
21650b57cec5SDimitry Andricinline
21660b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::basic_string(
21670b57cec5SDimitry Andric    initializer_list<_CharT> __il)
2168480093f4SDimitry Andric     : __r_(__default_init_tag(), __default_init_tag())
21690b57cec5SDimitry Andric{
21700b57cec5SDimitry Andric    __init(__il.begin(), __il.end());
21710b57cec5SDimitry Andric#if _LIBCPP_DEBUG_LEVEL >= 2
21720b57cec5SDimitry Andric    __get_db()->__insert_c(this);
21730b57cec5SDimitry Andric#endif
21740b57cec5SDimitry Andric}
21750b57cec5SDimitry Andric
21760b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
21770b57cec5SDimitry Andricinline
21780b57cec5SDimitry Andric
21790b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::basic_string(
21800b57cec5SDimitry Andric    initializer_list<_CharT> __il, const _Allocator& __a)
2181480093f4SDimitry Andric    : __r_(__default_init_tag(), __a)
21820b57cec5SDimitry Andric{
21830b57cec5SDimitry Andric    __init(__il.begin(), __il.end());
21840b57cec5SDimitry Andric#if _LIBCPP_DEBUG_LEVEL >= 2
21850b57cec5SDimitry Andric    __get_db()->__insert_c(this);
21860b57cec5SDimitry Andric#endif
21870b57cec5SDimitry Andric}
21880b57cec5SDimitry Andric
21890b57cec5SDimitry Andric#endif  // _LIBCPP_CXX03_LANG
21900b57cec5SDimitry Andric
21910b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
21920b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::~basic_string()
21930b57cec5SDimitry Andric{
21940b57cec5SDimitry Andric#if _LIBCPP_DEBUG_LEVEL >= 2
21950b57cec5SDimitry Andric    __get_db()->__erase_c(this);
21960b57cec5SDimitry Andric#endif
21970b57cec5SDimitry Andric    if (__is_long())
21980b57cec5SDimitry Andric        __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
21990b57cec5SDimitry Andric}
22000b57cec5SDimitry Andric
22010b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
22020b57cec5SDimitry Andricvoid
22030b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::__grow_by_and_replace
22040b57cec5SDimitry Andric    (size_type __old_cap, size_type __delta_cap, size_type __old_sz,
22050b57cec5SDimitry Andric     size_type __n_copy,  size_type __n_del,     size_type __n_add, const value_type* __p_new_stuff)
22060b57cec5SDimitry Andric{
22070b57cec5SDimitry Andric    size_type __ms = max_size();
22080b57cec5SDimitry Andric    if (__delta_cap > __ms - __old_cap - 1)
22090b57cec5SDimitry Andric        this->__throw_length_error();
22100b57cec5SDimitry Andric    pointer __old_p = __get_pointer();
22110b57cec5SDimitry Andric    size_type __cap = __old_cap < __ms / 2 - __alignment ?
22120b57cec5SDimitry Andric                          __recommend(_VSTD::max(__old_cap + __delta_cap, 2 * __old_cap)) :
22130b57cec5SDimitry Andric                          __ms - 1;
22140b57cec5SDimitry Andric    pointer __p = __alloc_traits::allocate(__alloc(), __cap+1);
22150b57cec5SDimitry Andric    __invalidate_all_iterators();
22160b57cec5SDimitry Andric    if (__n_copy != 0)
2217480093f4SDimitry Andric        traits_type::copy(_VSTD::__to_address(__p),
2218480093f4SDimitry Andric                          _VSTD::__to_address(__old_p), __n_copy);
22190b57cec5SDimitry Andric    if (__n_add != 0)
2220480093f4SDimitry Andric        traits_type::copy(_VSTD::__to_address(__p) + __n_copy, __p_new_stuff, __n_add);
22210b57cec5SDimitry Andric    size_type __sec_cp_sz = __old_sz - __n_del - __n_copy;
22220b57cec5SDimitry Andric    if (__sec_cp_sz != 0)
2223480093f4SDimitry Andric        traits_type::copy(_VSTD::__to_address(__p) + __n_copy + __n_add,
2224480093f4SDimitry Andric                          _VSTD::__to_address(__old_p) + __n_copy + __n_del, __sec_cp_sz);
22250b57cec5SDimitry Andric    if (__old_cap+1 != __min_cap)
22260b57cec5SDimitry Andric        __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1);
22270b57cec5SDimitry Andric    __set_long_pointer(__p);
22280b57cec5SDimitry Andric    __set_long_cap(__cap+1);
22290b57cec5SDimitry Andric    __old_sz = __n_copy + __n_add + __sec_cp_sz;
22300b57cec5SDimitry Andric    __set_long_size(__old_sz);
22310b57cec5SDimitry Andric    traits_type::assign(__p[__old_sz], value_type());
22320b57cec5SDimitry Andric}
22330b57cec5SDimitry Andric
22340b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
22350b57cec5SDimitry Andricvoid
22360b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::__grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
22370b57cec5SDimitry Andric                                                     size_type __n_copy,  size_type __n_del,     size_type __n_add)
22380b57cec5SDimitry Andric{
22390b57cec5SDimitry Andric    size_type __ms = max_size();
22400b57cec5SDimitry Andric    if (__delta_cap > __ms - __old_cap)
22410b57cec5SDimitry Andric        this->__throw_length_error();
22420b57cec5SDimitry Andric    pointer __old_p = __get_pointer();
22430b57cec5SDimitry Andric    size_type __cap = __old_cap < __ms / 2 - __alignment ?
22440b57cec5SDimitry Andric                          __recommend(_VSTD::max(__old_cap + __delta_cap, 2 * __old_cap)) :
22450b57cec5SDimitry Andric                          __ms - 1;
22460b57cec5SDimitry Andric    pointer __p = __alloc_traits::allocate(__alloc(), __cap+1);
22470b57cec5SDimitry Andric    __invalidate_all_iterators();
22480b57cec5SDimitry Andric    if (__n_copy != 0)
2249480093f4SDimitry Andric        traits_type::copy(_VSTD::__to_address(__p),
2250480093f4SDimitry Andric                          _VSTD::__to_address(__old_p), __n_copy);
22510b57cec5SDimitry Andric    size_type __sec_cp_sz = __old_sz - __n_del - __n_copy;
22520b57cec5SDimitry Andric    if (__sec_cp_sz != 0)
2253480093f4SDimitry Andric        traits_type::copy(_VSTD::__to_address(__p) + __n_copy + __n_add,
2254480093f4SDimitry Andric                          _VSTD::__to_address(__old_p) + __n_copy + __n_del,
22550b57cec5SDimitry Andric                          __sec_cp_sz);
22560b57cec5SDimitry Andric    if (__old_cap+1 != __min_cap)
22570b57cec5SDimitry Andric        __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1);
22580b57cec5SDimitry Andric    __set_long_pointer(__p);
22590b57cec5SDimitry Andric    __set_long_cap(__cap+1);
22600b57cec5SDimitry Andric}
22610b57cec5SDimitry Andric
22620b57cec5SDimitry Andric// assign
22630b57cec5SDimitry Andric
22640b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
2265*5ffd83dbSDimitry Andrictemplate <bool __is_short>
22660b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>&
2267*5ffd83dbSDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::__assign_no_alias(
2268*5ffd83dbSDimitry Andric    const value_type* __s, size_type __n) {
2269*5ffd83dbSDimitry Andric  size_type __cap = __is_short ? __min_cap : __get_long_cap();
2270*5ffd83dbSDimitry Andric  if (__n < __cap) {
2271*5ffd83dbSDimitry Andric    pointer __p = __is_short ? __get_short_pointer() : __get_long_pointer();
2272*5ffd83dbSDimitry Andric    __is_short ? __set_short_size(__n) : __set_long_size(__n);
2273*5ffd83dbSDimitry Andric    traits_type::copy(_VSTD::__to_address(__p), __s, __n);
2274*5ffd83dbSDimitry Andric    traits_type::assign(__p[__n], value_type());
2275*5ffd83dbSDimitry Andric    __invalidate_iterators_past(__n);
2276*5ffd83dbSDimitry Andric  } else {
2277*5ffd83dbSDimitry Andric    size_type __sz = __is_short ? __get_short_size() : __get_long_size();
2278*5ffd83dbSDimitry Andric    __grow_by_and_replace(__cap - 1, __n - __cap + 1, __sz, 0, __sz, __n, __s);
2279*5ffd83dbSDimitry Andric  }
2280*5ffd83dbSDimitry Andric  return *this;
2281*5ffd83dbSDimitry Andric}
2282*5ffd83dbSDimitry Andric
2283*5ffd83dbSDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
2284*5ffd83dbSDimitry Andricbasic_string<_CharT, _Traits, _Allocator>&
2285*5ffd83dbSDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::__assign_external(
2286*5ffd83dbSDimitry Andric    const value_type* __s, size_type __n) {
22870b57cec5SDimitry Andric  size_type __cap = capacity();
2288*5ffd83dbSDimitry Andric  if (__cap >= __n) {
2289480093f4SDimitry Andric    value_type* __p = _VSTD::__to_address(__get_pointer());
22900b57cec5SDimitry Andric    traits_type::move(__p, __s, __n);
22910b57cec5SDimitry Andric    traits_type::assign(__p[__n], value_type());
22920b57cec5SDimitry Andric    __set_size(__n);
22930b57cec5SDimitry Andric    __invalidate_iterators_past(__n);
2294*5ffd83dbSDimitry Andric  } else {
22950b57cec5SDimitry Andric    size_type __sz = size();
22960b57cec5SDimitry Andric    __grow_by_and_replace(__cap, __n - __cap, __sz, 0, __sz, __n, __s);
22970b57cec5SDimitry Andric  }
22980b57cec5SDimitry Andric  return *this;
22990b57cec5SDimitry Andric}
23000b57cec5SDimitry Andric
23010b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
23020b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>&
2303*5ffd83dbSDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s, size_type __n)
2304*5ffd83dbSDimitry Andric{
2305*5ffd83dbSDimitry Andric    _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::assign received nullptr");
2306*5ffd83dbSDimitry Andric    return (_LIBCPP_BUILTIN_CONSTANT_P(__n) && __n < __min_cap)
2307*5ffd83dbSDimitry Andric               ? __assign_short(__s, __n)
2308*5ffd83dbSDimitry Andric               : __assign_external(__s, __n);
2309*5ffd83dbSDimitry Andric}
2310*5ffd83dbSDimitry Andric
2311*5ffd83dbSDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
2312*5ffd83dbSDimitry Andricbasic_string<_CharT, _Traits, _Allocator>&
23130b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::assign(size_type __n, value_type __c)
23140b57cec5SDimitry Andric{
23150b57cec5SDimitry Andric    size_type __cap = capacity();
23160b57cec5SDimitry Andric    if (__cap < __n)
23170b57cec5SDimitry Andric    {
23180b57cec5SDimitry Andric        size_type __sz = size();
23190b57cec5SDimitry Andric        __grow_by(__cap, __n - __cap, __sz, 0, __sz);
23200b57cec5SDimitry Andric    }
23210b57cec5SDimitry Andric    else
23220b57cec5SDimitry Andric        __invalidate_iterators_past(__n);
2323480093f4SDimitry Andric    value_type* __p = _VSTD::__to_address(__get_pointer());
23240b57cec5SDimitry Andric    traits_type::assign(__p, __n, __c);
23250b57cec5SDimitry Andric    traits_type::assign(__p[__n], value_type());
23260b57cec5SDimitry Andric    __set_size(__n);
23270b57cec5SDimitry Andric    return *this;
23280b57cec5SDimitry Andric}
23290b57cec5SDimitry Andric
23300b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
23310b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>&
23320b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::operator=(value_type __c)
23330b57cec5SDimitry Andric{
23340b57cec5SDimitry Andric    pointer __p;
23350b57cec5SDimitry Andric    if (__is_long())
23360b57cec5SDimitry Andric    {
23370b57cec5SDimitry Andric        __p = __get_long_pointer();
23380b57cec5SDimitry Andric        __set_long_size(1);
23390b57cec5SDimitry Andric    }
23400b57cec5SDimitry Andric    else
23410b57cec5SDimitry Andric    {
23420b57cec5SDimitry Andric        __p = __get_short_pointer();
23430b57cec5SDimitry Andric        __set_short_size(1);
23440b57cec5SDimitry Andric    }
23450b57cec5SDimitry Andric    traits_type::assign(*__p, __c);
23460b57cec5SDimitry Andric    traits_type::assign(*++__p, value_type());
23470b57cec5SDimitry Andric    __invalidate_iterators_past(1);
23480b57cec5SDimitry Andric    return *this;
23490b57cec5SDimitry Andric}
23500b57cec5SDimitry Andric
23510b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
23520b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>&
23530b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::operator=(const basic_string& __str)
23540b57cec5SDimitry Andric{
2355*5ffd83dbSDimitry Andric  if (this != &__str) {
23560b57cec5SDimitry Andric    __copy_assign_alloc(__str);
2357*5ffd83dbSDimitry Andric    if (!__is_long()) {
2358*5ffd83dbSDimitry Andric      if (!__str.__is_long()) {
2359*5ffd83dbSDimitry Andric        __r_.first().__r = __str.__r_.first().__r;
2360*5ffd83dbSDimitry Andric      } else {
2361*5ffd83dbSDimitry Andric        return __assign_no_alias<true>(__str.data(), __str.size());
2362*5ffd83dbSDimitry Andric      }
2363*5ffd83dbSDimitry Andric    } else {
2364*5ffd83dbSDimitry Andric      return __assign_no_alias<false>(__str.data(), __str.size());
2365*5ffd83dbSDimitry Andric    }
23660b57cec5SDimitry Andric  }
23670b57cec5SDimitry Andric  return *this;
23680b57cec5SDimitry Andric}
23690b57cec5SDimitry Andric
23700b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
23710b57cec5SDimitry Andric
23720b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
23730b57cec5SDimitry Andricinline
23740b57cec5SDimitry Andricvoid
23750b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, false_type)
23760b57cec5SDimitry Andric    _NOEXCEPT_(__alloc_traits::is_always_equal::value)
23770b57cec5SDimitry Andric{
23780b57cec5SDimitry Andric    if (__alloc() != __str.__alloc())
23790b57cec5SDimitry Andric        assign(__str);
23800b57cec5SDimitry Andric    else
23810b57cec5SDimitry Andric        __move_assign(__str, true_type());
23820b57cec5SDimitry Andric}
23830b57cec5SDimitry Andric
23840b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
23850b57cec5SDimitry Andricinline
23860b57cec5SDimitry Andricvoid
23870b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, true_type)
23880b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 14
23890b57cec5SDimitry Andric    _NOEXCEPT
23900b57cec5SDimitry Andric#else
23910b57cec5SDimitry Andric    _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
23920b57cec5SDimitry Andric#endif
23930b57cec5SDimitry Andric{
2394480093f4SDimitry Andric  if (__is_long()) {
2395480093f4SDimitry Andric    __alloc_traits::deallocate(__alloc(), __get_long_pointer(),
2396480093f4SDimitry Andric                               __get_long_cap());
2397480093f4SDimitry Andric#if _LIBCPP_STD_VER <= 14
2398480093f4SDimitry Andric    if (!is_nothrow_move_assignable<allocator_type>::value) {
2399480093f4SDimitry Andric      __set_short_size(0);
2400480093f4SDimitry Andric      traits_type::assign(__get_short_pointer()[0], value_type());
2401480093f4SDimitry Andric    }
2402480093f4SDimitry Andric#endif
2403480093f4SDimitry Andric  }
24040b57cec5SDimitry Andric  __move_assign_alloc(__str);
2405480093f4SDimitry Andric  __r_.first() = __str.__r_.first();
2406480093f4SDimitry Andric  __str.__set_short_size(0);
2407480093f4SDimitry Andric  traits_type::assign(__str.__get_short_pointer()[0], value_type());
24080b57cec5SDimitry Andric}
24090b57cec5SDimitry Andric
24100b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
24110b57cec5SDimitry Andricinline
24120b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>&
24130b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::operator=(basic_string&& __str)
24140b57cec5SDimitry Andric    _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value))
24150b57cec5SDimitry Andric{
24160b57cec5SDimitry Andric    __move_assign(__str, integral_constant<bool,
24170b57cec5SDimitry Andric          __alloc_traits::propagate_on_container_move_assignment::value>());
24180b57cec5SDimitry Andric    return *this;
24190b57cec5SDimitry Andric}
24200b57cec5SDimitry Andric
24210b57cec5SDimitry Andric#endif
24220b57cec5SDimitry Andric
24230b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
24240b57cec5SDimitry Andrictemplate<class _InputIterator>
2425*5ffd83dbSDimitry Andric_EnableIf
24260b57cec5SDimitry Andric<
2427480093f4SDimitry Andric     __is_exactly_cpp17_input_iterator <_InputIterator>::value
24280b57cec5SDimitry Andric          || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
24290b57cec5SDimitry Andric    basic_string<_CharT, _Traits, _Allocator>&
2430*5ffd83dbSDimitry Andric>
24310b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
24320b57cec5SDimitry Andric{
24330b57cec5SDimitry Andric    const basic_string __temp(__first, __last, __alloc());
24340b57cec5SDimitry Andric    assign(__temp.data(), __temp.size());
24350b57cec5SDimitry Andric    return *this;
24360b57cec5SDimitry Andric}
24370b57cec5SDimitry Andric
24380b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
24390b57cec5SDimitry Andrictemplate<class _ForwardIterator>
2440*5ffd83dbSDimitry Andric_EnableIf
24410b57cec5SDimitry Andric<
2442480093f4SDimitry Andric    __is_cpp17_forward_iterator<_ForwardIterator>::value
24430b57cec5SDimitry Andric         && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
24440b57cec5SDimitry Andric    basic_string<_CharT, _Traits, _Allocator>&
2445*5ffd83dbSDimitry Andric>
24460b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last)
24470b57cec5SDimitry Andric{
24480b57cec5SDimitry Andric    size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
24490b57cec5SDimitry Andric    size_type __cap = capacity();
24500b57cec5SDimitry Andric    if (__cap < __n)
24510b57cec5SDimitry Andric    {
24520b57cec5SDimitry Andric        size_type __sz = size();
24530b57cec5SDimitry Andric        __grow_by(__cap, __n - __cap, __sz, 0, __sz);
24540b57cec5SDimitry Andric    }
24550b57cec5SDimitry Andric    else
24560b57cec5SDimitry Andric        __invalidate_iterators_past(__n);
24570b57cec5SDimitry Andric    pointer __p = __get_pointer();
24580b57cec5SDimitry Andric    for (; __first != __last; ++__first, ++__p)
24590b57cec5SDimitry Andric        traits_type::assign(*__p, *__first);
24600b57cec5SDimitry Andric    traits_type::assign(*__p, value_type());
24610b57cec5SDimitry Andric    __set_size(__n);
24620b57cec5SDimitry Andric    return *this;
24630b57cec5SDimitry Andric}
24640b57cec5SDimitry Andric
24650b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
24660b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>&
24670b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::assign(const basic_string& __str, size_type __pos, size_type __n)
24680b57cec5SDimitry Andric{
24690b57cec5SDimitry Andric    size_type __sz = __str.size();
24700b57cec5SDimitry Andric    if (__pos > __sz)
24710b57cec5SDimitry Andric        this->__throw_out_of_range();
24720b57cec5SDimitry Andric    return assign(__str.data() + __pos, _VSTD::min(__n, __sz - __pos));
24730b57cec5SDimitry Andric}
24740b57cec5SDimitry Andric
24750b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
24760b57cec5SDimitry Andrictemplate <class _Tp>
2477*5ffd83dbSDimitry Andric_EnableIf
24780b57cec5SDimitry Andric<
2479*5ffd83dbSDimitry Andric    __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value
2480*5ffd83dbSDimitry Andric    && !__is_same_uncvref<_Tp, basic_string<_CharT, _Traits, _Allocator> >::value,
24810b57cec5SDimitry Andric    basic_string<_CharT, _Traits, _Allocator>&
2482*5ffd83dbSDimitry Andric>
24830b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::assign(const _Tp & __t, size_type __pos, size_type __n)
24840b57cec5SDimitry Andric{
24850b57cec5SDimitry Andric    __self_view __sv = __t;
24860b57cec5SDimitry Andric    size_type __sz = __sv.size();
24870b57cec5SDimitry Andric    if (__pos > __sz)
24880b57cec5SDimitry Andric        this->__throw_out_of_range();
24890b57cec5SDimitry Andric    return assign(__sv.data() + __pos, _VSTD::min(__n, __sz - __pos));
24900b57cec5SDimitry Andric}
24910b57cec5SDimitry Andric
24920b57cec5SDimitry Andric
24930b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
24940b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>&
2495*5ffd83dbSDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::__assign_external(const value_type* __s) {
2496*5ffd83dbSDimitry Andric  return __assign_external(__s, traits_type::length(__s));
2497*5ffd83dbSDimitry Andric}
2498*5ffd83dbSDimitry Andric
2499*5ffd83dbSDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
2500*5ffd83dbSDimitry Andricbasic_string<_CharT, _Traits, _Allocator>&
25010b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s)
25020b57cec5SDimitry Andric{
25030b57cec5SDimitry Andric    _LIBCPP_ASSERT(__s != nullptr, "string::assign received nullptr");
2504*5ffd83dbSDimitry Andric    return _LIBCPP_BUILTIN_CONSTANT_P(*__s)
2505*5ffd83dbSDimitry Andric               ? (traits_type::length(__s) < __min_cap
2506*5ffd83dbSDimitry Andric                      ? __assign_short(__s, traits_type::length(__s))
2507*5ffd83dbSDimitry Andric                      : __assign_external(__s, traits_type::length(__s)))
2508*5ffd83dbSDimitry Andric               : __assign_external(__s);
25090b57cec5SDimitry Andric}
25100b57cec5SDimitry Andric// append
25110b57cec5SDimitry Andric
25120b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
25130b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>&
25140b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s, size_type __n)
25150b57cec5SDimitry Andric{
25160b57cec5SDimitry Andric    _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::append received nullptr");
25170b57cec5SDimitry Andric    size_type __cap = capacity();
25180b57cec5SDimitry Andric    size_type __sz = size();
25190b57cec5SDimitry Andric    if (__cap - __sz >= __n)
25200b57cec5SDimitry Andric    {
25210b57cec5SDimitry Andric        if (__n)
25220b57cec5SDimitry Andric        {
2523480093f4SDimitry Andric            value_type* __p = _VSTD::__to_address(__get_pointer());
25240b57cec5SDimitry Andric            traits_type::copy(__p + __sz, __s, __n);
25250b57cec5SDimitry Andric            __sz += __n;
25260b57cec5SDimitry Andric            __set_size(__sz);
25270b57cec5SDimitry Andric            traits_type::assign(__p[__sz], value_type());
25280b57cec5SDimitry Andric        }
25290b57cec5SDimitry Andric    }
25300b57cec5SDimitry Andric    else
25310b57cec5SDimitry Andric        __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __sz, 0, __n, __s);
25320b57cec5SDimitry Andric    return *this;
25330b57cec5SDimitry Andric}
25340b57cec5SDimitry Andric
25350b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
25360b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>&
25370b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::append(size_type __n, value_type __c)
25380b57cec5SDimitry Andric{
25390b57cec5SDimitry Andric    if (__n)
25400b57cec5SDimitry Andric    {
25410b57cec5SDimitry Andric        size_type __cap = capacity();
25420b57cec5SDimitry Andric        size_type __sz = size();
25430b57cec5SDimitry Andric        if (__cap - __sz < __n)
25440b57cec5SDimitry Andric            __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
25450b57cec5SDimitry Andric        pointer __p = __get_pointer();
2546480093f4SDimitry Andric        traits_type::assign(_VSTD::__to_address(__p) + __sz, __n, __c);
25470b57cec5SDimitry Andric        __sz += __n;
25480b57cec5SDimitry Andric        __set_size(__sz);
25490b57cec5SDimitry Andric        traits_type::assign(__p[__sz], value_type());
25500b57cec5SDimitry Andric    }
25510b57cec5SDimitry Andric    return *this;
25520b57cec5SDimitry Andric}
25530b57cec5SDimitry Andric
25540b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
25550b57cec5SDimitry Andricinline void
25560b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::__append_default_init(size_type __n)
25570b57cec5SDimitry Andric{
25580b57cec5SDimitry Andric    if (__n)
25590b57cec5SDimitry Andric    {
25600b57cec5SDimitry Andric        size_type __cap = capacity();
25610b57cec5SDimitry Andric        size_type __sz = size();
25620b57cec5SDimitry Andric        if (__cap - __sz < __n)
25630b57cec5SDimitry Andric            __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
25640b57cec5SDimitry Andric        pointer __p = __get_pointer();
25650b57cec5SDimitry Andric        __sz += __n;
25660b57cec5SDimitry Andric        __set_size(__sz);
25670b57cec5SDimitry Andric        traits_type::assign(__p[__sz], value_type());
25680b57cec5SDimitry Andric    }
25690b57cec5SDimitry Andric}
25700b57cec5SDimitry Andric
25710b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
25720b57cec5SDimitry Andricvoid
25730b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::push_back(value_type __c)
25740b57cec5SDimitry Andric{
25750b57cec5SDimitry Andric    bool __is_short = !__is_long();
25760b57cec5SDimitry Andric    size_type __cap;
25770b57cec5SDimitry Andric    size_type __sz;
25780b57cec5SDimitry Andric    if (__is_short)
25790b57cec5SDimitry Andric    {
25800b57cec5SDimitry Andric        __cap = __min_cap - 1;
25810b57cec5SDimitry Andric        __sz = __get_short_size();
25820b57cec5SDimitry Andric    }
25830b57cec5SDimitry Andric    else
25840b57cec5SDimitry Andric    {
25850b57cec5SDimitry Andric        __cap = __get_long_cap() - 1;
25860b57cec5SDimitry Andric        __sz = __get_long_size();
25870b57cec5SDimitry Andric    }
25880b57cec5SDimitry Andric    if (__sz == __cap)
25890b57cec5SDimitry Andric    {
25900b57cec5SDimitry Andric        __grow_by(__cap, 1, __sz, __sz, 0);
25910b57cec5SDimitry Andric        __is_short = !__is_long();
25920b57cec5SDimitry Andric    }
25930b57cec5SDimitry Andric    pointer __p;
25940b57cec5SDimitry Andric    if (__is_short)
25950b57cec5SDimitry Andric    {
25960b57cec5SDimitry Andric        __p = __get_short_pointer() + __sz;
25970b57cec5SDimitry Andric        __set_short_size(__sz+1);
25980b57cec5SDimitry Andric    }
25990b57cec5SDimitry Andric    else
26000b57cec5SDimitry Andric    {
26010b57cec5SDimitry Andric        __p = __get_long_pointer() + __sz;
26020b57cec5SDimitry Andric        __set_long_size(__sz+1);
26030b57cec5SDimitry Andric    }
26040b57cec5SDimitry Andric    traits_type::assign(*__p, __c);
26050b57cec5SDimitry Andric    traits_type::assign(*++__p, value_type());
26060b57cec5SDimitry Andric}
26070b57cec5SDimitry Andric
26080b57cec5SDimitry Andrictemplate <class _Tp>
26090b57cec5SDimitry Andricbool __ptr_in_range (const _Tp* __p, const _Tp* __first, const _Tp* __last)
26100b57cec5SDimitry Andric{
26110b57cec5SDimitry Andric    return __first <= __p && __p < __last;
26120b57cec5SDimitry Andric}
26130b57cec5SDimitry Andric
26140b57cec5SDimitry Andrictemplate <class _Tp1, class _Tp2>
26150b57cec5SDimitry Andricbool __ptr_in_range (const _Tp1*, const _Tp2*, const _Tp2*)
26160b57cec5SDimitry Andric{
26170b57cec5SDimitry Andric    return false;
26180b57cec5SDimitry Andric}
26190b57cec5SDimitry Andric
26200b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
26210b57cec5SDimitry Andrictemplate<class _ForwardIterator>
26220b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>&
26230b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::__append_forward_unsafe(
26240b57cec5SDimitry Andric    _ForwardIterator __first, _ForwardIterator __last)
26250b57cec5SDimitry Andric{
2626480093f4SDimitry Andric    static_assert(__is_cpp17_forward_iterator<_ForwardIterator>::value,
26270b57cec5SDimitry Andric                  "function requires a ForwardIterator");
26280b57cec5SDimitry Andric    size_type __sz = size();
26290b57cec5SDimitry Andric    size_type __cap = capacity();
26300b57cec5SDimitry Andric    size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
26310b57cec5SDimitry Andric    if (__n)
26320b57cec5SDimitry Andric    {
26330b57cec5SDimitry Andric        typedef typename iterator_traits<_ForwardIterator>::reference _CharRef;
26340b57cec5SDimitry Andric        _CharRef __tmp_ref = *__first;
26350b57cec5SDimitry Andric        if (__ptr_in_range(_VSTD::addressof(__tmp_ref), data(), data() + size()))
26360b57cec5SDimitry Andric        {
26370b57cec5SDimitry Andric            const basic_string __temp (__first, __last, __alloc());
26380b57cec5SDimitry Andric            append(__temp.data(), __temp.size());
26390b57cec5SDimitry Andric        }
26400b57cec5SDimitry Andric        else
26410b57cec5SDimitry Andric        {
26420b57cec5SDimitry Andric            if (__cap - __sz < __n)
26430b57cec5SDimitry Andric                __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
26440b57cec5SDimitry Andric            pointer __p = __get_pointer() + __sz;
26450b57cec5SDimitry Andric            for (; __first != __last; ++__p, ++__first)
26460b57cec5SDimitry Andric                traits_type::assign(*__p, *__first);
26470b57cec5SDimitry Andric            traits_type::assign(*__p, value_type());
26480b57cec5SDimitry Andric            __set_size(__sz + __n);
26490b57cec5SDimitry Andric        }
26500b57cec5SDimitry Andric    }
26510b57cec5SDimitry Andric    return *this;
26520b57cec5SDimitry Andric}
26530b57cec5SDimitry Andric
26540b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
26550b57cec5SDimitry Andricinline
26560b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>&
26570b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str)
26580b57cec5SDimitry Andric{
26590b57cec5SDimitry Andric    return append(__str.data(), __str.size());
26600b57cec5SDimitry Andric}
26610b57cec5SDimitry Andric
26620b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
26630b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>&
26640b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str, size_type __pos, size_type __n)
26650b57cec5SDimitry Andric{
26660b57cec5SDimitry Andric    size_type __sz = __str.size();
26670b57cec5SDimitry Andric    if (__pos > __sz)
26680b57cec5SDimitry Andric        this->__throw_out_of_range();
26690b57cec5SDimitry Andric    return append(__str.data() + __pos, _VSTD::min(__n, __sz - __pos));
26700b57cec5SDimitry Andric}
26710b57cec5SDimitry Andric
26720b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
26730b57cec5SDimitry Andrictemplate <class _Tp>
2674*5ffd83dbSDimitry Andric    _EnableIf
26750b57cec5SDimitry Andric    <
2676*5ffd83dbSDimitry Andric        __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value  && !__is_same_uncvref<_Tp, basic_string<_CharT, _Traits, _Allocator> >::value,
26770b57cec5SDimitry Andric        basic_string<_CharT, _Traits, _Allocator>&
2678*5ffd83dbSDimitry Andric    >
26790b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::append(const _Tp & __t, size_type __pos, size_type __n)
26800b57cec5SDimitry Andric{
26810b57cec5SDimitry Andric    __self_view __sv = __t;
26820b57cec5SDimitry Andric    size_type __sz = __sv.size();
26830b57cec5SDimitry Andric    if (__pos > __sz)
26840b57cec5SDimitry Andric        this->__throw_out_of_range();
26850b57cec5SDimitry Andric    return append(__sv.data() + __pos, _VSTD::min(__n, __sz - __pos));
26860b57cec5SDimitry Andric}
26870b57cec5SDimitry Andric
26880b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
26890b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>&
26900b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s)
26910b57cec5SDimitry Andric{
26920b57cec5SDimitry Andric    _LIBCPP_ASSERT(__s != nullptr, "string::append received nullptr");
26930b57cec5SDimitry Andric    return append(__s, traits_type::length(__s));
26940b57cec5SDimitry Andric}
26950b57cec5SDimitry Andric
26960b57cec5SDimitry Andric// insert
26970b57cec5SDimitry Andric
26980b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
26990b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>&
27000b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s, size_type __n)
27010b57cec5SDimitry Andric{
27020b57cec5SDimitry Andric    _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::insert received nullptr");
27030b57cec5SDimitry Andric    size_type __sz = size();
27040b57cec5SDimitry Andric    if (__pos > __sz)
27050b57cec5SDimitry Andric        this->__throw_out_of_range();
27060b57cec5SDimitry Andric    size_type __cap = capacity();
27070b57cec5SDimitry Andric    if (__cap - __sz >= __n)
27080b57cec5SDimitry Andric    {
27090b57cec5SDimitry Andric        if (__n)
27100b57cec5SDimitry Andric        {
2711480093f4SDimitry Andric            value_type* __p = _VSTD::__to_address(__get_pointer());
27120b57cec5SDimitry Andric            size_type __n_move = __sz - __pos;
27130b57cec5SDimitry Andric            if (__n_move != 0)
27140b57cec5SDimitry Andric            {
27150b57cec5SDimitry Andric                if (__p + __pos <= __s && __s < __p + __sz)
27160b57cec5SDimitry Andric                    __s += __n;
27170b57cec5SDimitry Andric                traits_type::move(__p + __pos + __n, __p + __pos, __n_move);
27180b57cec5SDimitry Andric            }
27190b57cec5SDimitry Andric            traits_type::move(__p + __pos, __s, __n);
27200b57cec5SDimitry Andric            __sz += __n;
27210b57cec5SDimitry Andric            __set_size(__sz);
27220b57cec5SDimitry Andric            traits_type::assign(__p[__sz], value_type());
27230b57cec5SDimitry Andric        }
27240b57cec5SDimitry Andric    }
27250b57cec5SDimitry Andric    else
27260b57cec5SDimitry Andric        __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __pos, 0, __n, __s);
27270b57cec5SDimitry Andric    return *this;
27280b57cec5SDimitry Andric}
27290b57cec5SDimitry Andric
27300b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
27310b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>&
27320b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, size_type __n, value_type __c)
27330b57cec5SDimitry Andric{
27340b57cec5SDimitry Andric    size_type __sz = size();
27350b57cec5SDimitry Andric    if (__pos > __sz)
27360b57cec5SDimitry Andric        this->__throw_out_of_range();
27370b57cec5SDimitry Andric    if (__n)
27380b57cec5SDimitry Andric    {
27390b57cec5SDimitry Andric        size_type __cap = capacity();
27400b57cec5SDimitry Andric        value_type* __p;
27410b57cec5SDimitry Andric        if (__cap - __sz >= __n)
27420b57cec5SDimitry Andric        {
2743480093f4SDimitry Andric            __p = _VSTD::__to_address(__get_pointer());
27440b57cec5SDimitry Andric            size_type __n_move = __sz - __pos;
27450b57cec5SDimitry Andric            if (__n_move != 0)
27460b57cec5SDimitry Andric                traits_type::move(__p + __pos + __n, __p + __pos, __n_move);
27470b57cec5SDimitry Andric        }
27480b57cec5SDimitry Andric        else
27490b57cec5SDimitry Andric        {
27500b57cec5SDimitry Andric            __grow_by(__cap, __sz + __n - __cap, __sz, __pos, 0, __n);
2751480093f4SDimitry Andric            __p = _VSTD::__to_address(__get_long_pointer());
27520b57cec5SDimitry Andric        }
27530b57cec5SDimitry Andric        traits_type::assign(__p + __pos, __n, __c);
27540b57cec5SDimitry Andric        __sz += __n;
27550b57cec5SDimitry Andric        __set_size(__sz);
27560b57cec5SDimitry Andric        traits_type::assign(__p[__sz], value_type());
27570b57cec5SDimitry Andric    }
27580b57cec5SDimitry Andric    return *this;
27590b57cec5SDimitry Andric}
27600b57cec5SDimitry Andric
27610b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
27620b57cec5SDimitry Andrictemplate<class _InputIterator>
2763*5ffd83dbSDimitry Andric_EnableIf
27640b57cec5SDimitry Andric<
2765480093f4SDimitry Andric   __is_exactly_cpp17_input_iterator<_InputIterator>::value
27660b57cec5SDimitry Andric        || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
27670b57cec5SDimitry Andric   typename basic_string<_CharT, _Traits, _Allocator>::iterator
2768*5ffd83dbSDimitry Andric>
27690b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _InputIterator __first, _InputIterator __last)
27700b57cec5SDimitry Andric{
27710b57cec5SDimitry Andric#if _LIBCPP_DEBUG_LEVEL >= 2
27720b57cec5SDimitry Andric    _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
27730b57cec5SDimitry Andric        "string::insert(iterator, range) called with an iterator not"
27740b57cec5SDimitry Andric        " referring to this string");
27750b57cec5SDimitry Andric#endif
27760b57cec5SDimitry Andric    const basic_string __temp(__first, __last, __alloc());
27770b57cec5SDimitry Andric    return insert(__pos, __temp.data(), __temp.data() + __temp.size());
27780b57cec5SDimitry Andric}
27790b57cec5SDimitry Andric
27800b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
27810b57cec5SDimitry Andrictemplate<class _ForwardIterator>
2782*5ffd83dbSDimitry Andric_EnableIf
27830b57cec5SDimitry Andric<
2784480093f4SDimitry Andric    __is_cpp17_forward_iterator<_ForwardIterator>::value
27850b57cec5SDimitry Andric        && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
27860b57cec5SDimitry Andric    typename basic_string<_CharT, _Traits, _Allocator>::iterator
2787*5ffd83dbSDimitry Andric>
27880b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last)
27890b57cec5SDimitry Andric{
27900b57cec5SDimitry Andric#if _LIBCPP_DEBUG_LEVEL >= 2
27910b57cec5SDimitry Andric    _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
27920b57cec5SDimitry Andric        "string::insert(iterator, range) called with an iterator not"
27930b57cec5SDimitry Andric        " referring to this string");
27940b57cec5SDimitry Andric#endif
27950b57cec5SDimitry Andric    size_type __ip = static_cast<size_type>(__pos - begin());
27960b57cec5SDimitry Andric    size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
27970b57cec5SDimitry Andric    if (__n)
27980b57cec5SDimitry Andric    {
27990b57cec5SDimitry Andric        typedef typename iterator_traits<_ForwardIterator>::reference _CharRef;
28000b57cec5SDimitry Andric        _CharRef __tmp_char = *__first;
28010b57cec5SDimitry Andric        if (__ptr_in_range(_VSTD::addressof(__tmp_char), data(), data() + size()))
28020b57cec5SDimitry Andric        {
28030b57cec5SDimitry Andric            const basic_string __temp(__first, __last, __alloc());
28040b57cec5SDimitry Andric            return insert(__pos, __temp.data(), __temp.data() + __temp.size());
28050b57cec5SDimitry Andric        }
28060b57cec5SDimitry Andric
28070b57cec5SDimitry Andric        size_type __sz = size();
28080b57cec5SDimitry Andric        size_type __cap = capacity();
28090b57cec5SDimitry Andric        value_type* __p;
28100b57cec5SDimitry Andric        if (__cap - __sz >= __n)
28110b57cec5SDimitry Andric        {
2812480093f4SDimitry Andric            __p = _VSTD::__to_address(__get_pointer());
28130b57cec5SDimitry Andric            size_type __n_move = __sz - __ip;
28140b57cec5SDimitry Andric            if (__n_move != 0)
28150b57cec5SDimitry Andric                traits_type::move(__p + __ip + __n, __p + __ip, __n_move);
28160b57cec5SDimitry Andric        }
28170b57cec5SDimitry Andric        else
28180b57cec5SDimitry Andric        {
28190b57cec5SDimitry Andric            __grow_by(__cap, __sz + __n - __cap, __sz, __ip, 0, __n);
2820480093f4SDimitry Andric            __p = _VSTD::__to_address(__get_long_pointer());
28210b57cec5SDimitry Andric        }
28220b57cec5SDimitry Andric        __sz += __n;
28230b57cec5SDimitry Andric        __set_size(__sz);
28240b57cec5SDimitry Andric        traits_type::assign(__p[__sz], value_type());
28250b57cec5SDimitry Andric        for (__p += __ip; __first != __last; ++__p, ++__first)
28260b57cec5SDimitry Andric            traits_type::assign(*__p, *__first);
28270b57cec5SDimitry Andric    }
28280b57cec5SDimitry Andric    return begin() + __ip;
28290b57cec5SDimitry Andric}
28300b57cec5SDimitry Andric
28310b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
28320b57cec5SDimitry Andricinline
28330b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>&
28340b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str)
28350b57cec5SDimitry Andric{
28360b57cec5SDimitry Andric    return insert(__pos1, __str.data(), __str.size());
28370b57cec5SDimitry Andric}
28380b57cec5SDimitry Andric
28390b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
28400b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>&
28410b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str,
28420b57cec5SDimitry Andric                                                  size_type __pos2, size_type __n)
28430b57cec5SDimitry Andric{
28440b57cec5SDimitry Andric    size_type __str_sz = __str.size();
28450b57cec5SDimitry Andric    if (__pos2 > __str_sz)
28460b57cec5SDimitry Andric        this->__throw_out_of_range();
28470b57cec5SDimitry Andric    return insert(__pos1, __str.data() + __pos2, _VSTD::min(__n, __str_sz - __pos2));
28480b57cec5SDimitry Andric}
28490b57cec5SDimitry Andric
28500b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
28510b57cec5SDimitry Andrictemplate <class _Tp>
2852*5ffd83dbSDimitry Andric_EnableIf
28530b57cec5SDimitry Andric<
2854*5ffd83dbSDimitry Andric    __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value  && !__is_same_uncvref<_Tp, basic_string<_CharT, _Traits, _Allocator> >::value,
28550b57cec5SDimitry Andric    basic_string<_CharT, _Traits, _Allocator>&
2856*5ffd83dbSDimitry Andric>
28570b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const _Tp& __t,
28580b57cec5SDimitry Andric                                                  size_type __pos2, size_type __n)
28590b57cec5SDimitry Andric{
28600b57cec5SDimitry Andric    __self_view __sv = __t;
28610b57cec5SDimitry Andric    size_type __str_sz = __sv.size();
28620b57cec5SDimitry Andric    if (__pos2 > __str_sz)
28630b57cec5SDimitry Andric        this->__throw_out_of_range();
28640b57cec5SDimitry Andric    return insert(__pos1, __sv.data() + __pos2, _VSTD::min(__n, __str_sz - __pos2));
28650b57cec5SDimitry Andric}
28660b57cec5SDimitry Andric
28670b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
28680b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>&
28690b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s)
28700b57cec5SDimitry Andric{
28710b57cec5SDimitry Andric    _LIBCPP_ASSERT(__s != nullptr, "string::insert received nullptr");
28720b57cec5SDimitry Andric    return insert(__pos, __s, traits_type::length(__s));
28730b57cec5SDimitry Andric}
28740b57cec5SDimitry Andric
28750b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
28760b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::iterator
28770b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, value_type __c)
28780b57cec5SDimitry Andric{
28790b57cec5SDimitry Andric    size_type __ip = static_cast<size_type>(__pos - begin());
28800b57cec5SDimitry Andric    size_type __sz = size();
28810b57cec5SDimitry Andric    size_type __cap = capacity();
28820b57cec5SDimitry Andric    value_type* __p;
28830b57cec5SDimitry Andric    if (__cap == __sz)
28840b57cec5SDimitry Andric    {
28850b57cec5SDimitry Andric        __grow_by(__cap, 1, __sz, __ip, 0, 1);
2886480093f4SDimitry Andric        __p = _VSTD::__to_address(__get_long_pointer());
28870b57cec5SDimitry Andric    }
28880b57cec5SDimitry Andric    else
28890b57cec5SDimitry Andric    {
2890480093f4SDimitry Andric        __p = _VSTD::__to_address(__get_pointer());
28910b57cec5SDimitry Andric        size_type __n_move = __sz - __ip;
28920b57cec5SDimitry Andric        if (__n_move != 0)
28930b57cec5SDimitry Andric            traits_type::move(__p + __ip + 1, __p + __ip, __n_move);
28940b57cec5SDimitry Andric    }
28950b57cec5SDimitry Andric    traits_type::assign(__p[__ip], __c);
28960b57cec5SDimitry Andric    traits_type::assign(__p[++__sz], value_type());
28970b57cec5SDimitry Andric    __set_size(__sz);
28980b57cec5SDimitry Andric    return begin() + static_cast<difference_type>(__ip);
28990b57cec5SDimitry Andric}
29000b57cec5SDimitry Andric
29010b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
29020b57cec5SDimitry Andricinline
29030b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::iterator
29040b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, size_type __n, value_type __c)
29050b57cec5SDimitry Andric{
29060b57cec5SDimitry Andric#if _LIBCPP_DEBUG_LEVEL >= 2
29070b57cec5SDimitry Andric    _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
29080b57cec5SDimitry Andric        "string::insert(iterator, n, value) called with an iterator not"
29090b57cec5SDimitry Andric        " referring to this string");
29100b57cec5SDimitry Andric#endif
29110b57cec5SDimitry Andric    difference_type __p = __pos - begin();
29120b57cec5SDimitry Andric    insert(static_cast<size_type>(__p), __n, __c);
29130b57cec5SDimitry Andric    return begin() + __p;
29140b57cec5SDimitry Andric}
29150b57cec5SDimitry Andric
29160b57cec5SDimitry Andric// replace
29170b57cec5SDimitry Andric
29180b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
29190b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>&
29200b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, const value_type* __s, size_type __n2)
29210b57cec5SDimitry Andric    _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
29220b57cec5SDimitry Andric{
29230b57cec5SDimitry Andric    _LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::replace received nullptr");
29240b57cec5SDimitry Andric    size_type __sz = size();
29250b57cec5SDimitry Andric    if (__pos > __sz)
29260b57cec5SDimitry Andric        this->__throw_out_of_range();
29270b57cec5SDimitry Andric    __n1 = _VSTD::min(__n1, __sz - __pos);
29280b57cec5SDimitry Andric    size_type __cap = capacity();
29290b57cec5SDimitry Andric    if (__cap - __sz + __n1 >= __n2)
29300b57cec5SDimitry Andric    {
2931480093f4SDimitry Andric        value_type* __p = _VSTD::__to_address(__get_pointer());
29320b57cec5SDimitry Andric        if (__n1 != __n2)
29330b57cec5SDimitry Andric        {
29340b57cec5SDimitry Andric            size_type __n_move = __sz - __pos - __n1;
29350b57cec5SDimitry Andric            if (__n_move != 0)
29360b57cec5SDimitry Andric            {
29370b57cec5SDimitry Andric                if (__n1 > __n2)
29380b57cec5SDimitry Andric                {
29390b57cec5SDimitry Andric                    traits_type::move(__p + __pos, __s, __n2);
29400b57cec5SDimitry Andric                    traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
29410b57cec5SDimitry Andric                    goto __finish;
29420b57cec5SDimitry Andric                }
29430b57cec5SDimitry Andric                if (__p + __pos < __s && __s < __p + __sz)
29440b57cec5SDimitry Andric                {
29450b57cec5SDimitry Andric                    if (__p + __pos + __n1 <= __s)
29460b57cec5SDimitry Andric                        __s += __n2 - __n1;
29470b57cec5SDimitry Andric                    else // __p + __pos < __s < __p + __pos + __n1
29480b57cec5SDimitry Andric                    {
29490b57cec5SDimitry Andric                        traits_type::move(__p + __pos, __s, __n1);
29500b57cec5SDimitry Andric                        __pos += __n1;
29510b57cec5SDimitry Andric                        __s += __n2;
29520b57cec5SDimitry Andric                        __n2 -= __n1;
29530b57cec5SDimitry Andric                        __n1 = 0;
29540b57cec5SDimitry Andric                    }
29550b57cec5SDimitry Andric                }
29560b57cec5SDimitry Andric                traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
29570b57cec5SDimitry Andric            }
29580b57cec5SDimitry Andric        }
29590b57cec5SDimitry Andric        traits_type::move(__p + __pos, __s, __n2);
29600b57cec5SDimitry Andric__finish:
2961*5ffd83dbSDimitry Andric// __sz += __n2 - __n1; in this and the below function below can cause unsigned
2962*5ffd83dbSDimitry Andric// integer overflow, but this is a safe operation, so we disable the check.
29630b57cec5SDimitry Andric        __sz += __n2 - __n1;
29640b57cec5SDimitry Andric        __set_size(__sz);
29650b57cec5SDimitry Andric        __invalidate_iterators_past(__sz);
29660b57cec5SDimitry Andric        traits_type::assign(__p[__sz], value_type());
29670b57cec5SDimitry Andric    }
29680b57cec5SDimitry Andric    else
29690b57cec5SDimitry Andric        __grow_by_and_replace(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2, __s);
29700b57cec5SDimitry Andric    return *this;
29710b57cec5SDimitry Andric}
29720b57cec5SDimitry Andric
29730b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
29740b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>&
29750b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, size_type __n2, value_type __c)
29760b57cec5SDimitry Andric    _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
29770b57cec5SDimitry Andric{
29780b57cec5SDimitry Andric    size_type __sz = size();
29790b57cec5SDimitry Andric    if (__pos > __sz)
29800b57cec5SDimitry Andric        this->__throw_out_of_range();
29810b57cec5SDimitry Andric    __n1 = _VSTD::min(__n1, __sz - __pos);
29820b57cec5SDimitry Andric    size_type __cap = capacity();
29830b57cec5SDimitry Andric    value_type* __p;
29840b57cec5SDimitry Andric    if (__cap - __sz + __n1 >= __n2)
29850b57cec5SDimitry Andric    {
2986480093f4SDimitry Andric        __p = _VSTD::__to_address(__get_pointer());
29870b57cec5SDimitry Andric        if (__n1 != __n2)
29880b57cec5SDimitry Andric        {
29890b57cec5SDimitry Andric            size_type __n_move = __sz - __pos - __n1;
29900b57cec5SDimitry Andric            if (__n_move != 0)
29910b57cec5SDimitry Andric                traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
29920b57cec5SDimitry Andric        }
29930b57cec5SDimitry Andric    }
29940b57cec5SDimitry Andric    else
29950b57cec5SDimitry Andric    {
29960b57cec5SDimitry Andric        __grow_by(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2);
2997480093f4SDimitry Andric        __p = _VSTD::__to_address(__get_long_pointer());
29980b57cec5SDimitry Andric    }
29990b57cec5SDimitry Andric    traits_type::assign(__p + __pos, __n2, __c);
30000b57cec5SDimitry Andric    __sz += __n2 - __n1;
30010b57cec5SDimitry Andric    __set_size(__sz);
30020b57cec5SDimitry Andric    __invalidate_iterators_past(__sz);
30030b57cec5SDimitry Andric    traits_type::assign(__p[__sz], value_type());
30040b57cec5SDimitry Andric    return *this;
30050b57cec5SDimitry Andric}
30060b57cec5SDimitry Andric
30070b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
30080b57cec5SDimitry Andrictemplate<class _InputIterator>
3009*5ffd83dbSDimitry Andric_EnableIf
30100b57cec5SDimitry Andric<
3011480093f4SDimitry Andric    __is_cpp17_input_iterator<_InputIterator>::value,
30120b57cec5SDimitry Andric    basic_string<_CharT, _Traits, _Allocator>&
3013*5ffd83dbSDimitry Andric>
30140b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2,
30150b57cec5SDimitry Andric                                                   _InputIterator __j1, _InputIterator __j2)
30160b57cec5SDimitry Andric{
30170b57cec5SDimitry Andric    const basic_string __temp(__j1, __j2, __alloc());
30180b57cec5SDimitry Andric    return this->replace(__i1, __i2, __temp);
30190b57cec5SDimitry Andric}
30200b57cec5SDimitry Andric
30210b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
30220b57cec5SDimitry Andricinline
30230b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>&
30240b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str)
30250b57cec5SDimitry Andric{
30260b57cec5SDimitry Andric    return replace(__pos1, __n1, __str.data(), __str.size());
30270b57cec5SDimitry Andric}
30280b57cec5SDimitry Andric
30290b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
30300b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>&
30310b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str,
30320b57cec5SDimitry Andric                                                   size_type __pos2, size_type __n2)
30330b57cec5SDimitry Andric{
30340b57cec5SDimitry Andric    size_type __str_sz = __str.size();
30350b57cec5SDimitry Andric    if (__pos2 > __str_sz)
30360b57cec5SDimitry Andric        this->__throw_out_of_range();
30370b57cec5SDimitry Andric    return replace(__pos1, __n1, __str.data() + __pos2, _VSTD::min(__n2, __str_sz - __pos2));
30380b57cec5SDimitry Andric}
30390b57cec5SDimitry Andric
30400b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
30410b57cec5SDimitry Andrictemplate <class _Tp>
3042*5ffd83dbSDimitry Andric_EnableIf
30430b57cec5SDimitry Andric<
3044*5ffd83dbSDimitry Andric    __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && !__is_same_uncvref<_Tp, basic_string<_CharT, _Traits, _Allocator> >::value,
30450b57cec5SDimitry Andric    basic_string<_CharT, _Traits, _Allocator>&
3046*5ffd83dbSDimitry Andric>
30470b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const _Tp& __t,
30480b57cec5SDimitry Andric                                                   size_type __pos2, size_type __n2)
30490b57cec5SDimitry Andric{
30500b57cec5SDimitry Andric    __self_view __sv = __t;
30510b57cec5SDimitry Andric    size_type __str_sz = __sv.size();
30520b57cec5SDimitry Andric    if (__pos2 > __str_sz)
30530b57cec5SDimitry Andric        this->__throw_out_of_range();
30540b57cec5SDimitry Andric    return replace(__pos1, __n1, __sv.data() + __pos2, _VSTD::min(__n2, __str_sz - __pos2));
30550b57cec5SDimitry Andric}
30560b57cec5SDimitry Andric
30570b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
30580b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>&
30590b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, const value_type* __s)
30600b57cec5SDimitry Andric{
30610b57cec5SDimitry Andric    _LIBCPP_ASSERT(__s != nullptr, "string::replace received nullptr");
30620b57cec5SDimitry Andric    return replace(__pos, __n1, __s, traits_type::length(__s));
30630b57cec5SDimitry Andric}
30640b57cec5SDimitry Andric
30650b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
30660b57cec5SDimitry Andricinline
30670b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>&
30680b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const basic_string& __str)
30690b57cec5SDimitry Andric{
30700b57cec5SDimitry Andric    return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1),
30710b57cec5SDimitry Andric                   __str.data(), __str.size());
30720b57cec5SDimitry Andric}
30730b57cec5SDimitry Andric
30740b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
30750b57cec5SDimitry Andricinline
30760b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>&
30770b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const value_type* __s, size_type __n)
30780b57cec5SDimitry Andric{
30790b57cec5SDimitry Andric    return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s, __n);
30800b57cec5SDimitry Andric}
30810b57cec5SDimitry Andric
30820b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
30830b57cec5SDimitry Andricinline
30840b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>&
30850b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const value_type* __s)
30860b57cec5SDimitry Andric{
30870b57cec5SDimitry Andric    return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s);
30880b57cec5SDimitry Andric}
30890b57cec5SDimitry Andric
30900b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
30910b57cec5SDimitry Andricinline
30920b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>&
30930b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c)
30940b57cec5SDimitry Andric{
30950b57cec5SDimitry Andric    return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __n, __c);
30960b57cec5SDimitry Andric}
30970b57cec5SDimitry Andric
30980b57cec5SDimitry Andric// erase
30990b57cec5SDimitry Andric
3100*5ffd83dbSDimitry Andric// 'externally instantiated' erase() implementation, called when __n != npos.
3101*5ffd83dbSDimitry Andric// Does not check __pos against size()
31020b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
3103*5ffd83dbSDimitry Andricvoid
3104*5ffd83dbSDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::__erase_external_with_move(
3105*5ffd83dbSDimitry Andric    size_type __pos, size_type __n)
31060b57cec5SDimitry Andric{
31070b57cec5SDimitry Andric    if (__n)
31080b57cec5SDimitry Andric    {
3109*5ffd83dbSDimitry Andric        size_type __sz = size();
3110480093f4SDimitry Andric        value_type* __p = _VSTD::__to_address(__get_pointer());
31110b57cec5SDimitry Andric        __n = _VSTD::min(__n, __sz - __pos);
31120b57cec5SDimitry Andric        size_type __n_move = __sz - __pos - __n;
31130b57cec5SDimitry Andric        if (__n_move != 0)
31140b57cec5SDimitry Andric            traits_type::move(__p + __pos, __p + __pos + __n, __n_move);
31150b57cec5SDimitry Andric        __sz -= __n;
31160b57cec5SDimitry Andric        __set_size(__sz);
31170b57cec5SDimitry Andric        __invalidate_iterators_past(__sz);
31180b57cec5SDimitry Andric        traits_type::assign(__p[__sz], value_type());
31190b57cec5SDimitry Andric    }
3120*5ffd83dbSDimitry Andric}
3121*5ffd83dbSDimitry Andric
3122*5ffd83dbSDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
3123*5ffd83dbSDimitry Andricbasic_string<_CharT, _Traits, _Allocator>&
3124*5ffd83dbSDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::erase(size_type __pos,
3125*5ffd83dbSDimitry Andric                                                 size_type __n) {
3126*5ffd83dbSDimitry Andric  if (__pos > size()) this->__throw_out_of_range();
3127*5ffd83dbSDimitry Andric  if (__n == npos) {
3128*5ffd83dbSDimitry Andric    __erase_to_end(__pos);
3129*5ffd83dbSDimitry Andric  } else {
3130*5ffd83dbSDimitry Andric    __erase_external_with_move(__pos, __n);
3131*5ffd83dbSDimitry Andric  }
31320b57cec5SDimitry Andric  return *this;
31330b57cec5SDimitry Andric}
31340b57cec5SDimitry Andric
31350b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
31360b57cec5SDimitry Andricinline
31370b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::iterator
31380b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __pos)
31390b57cec5SDimitry Andric{
31400b57cec5SDimitry Andric#if _LIBCPP_DEBUG_LEVEL >= 2
31410b57cec5SDimitry Andric    _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
31420b57cec5SDimitry Andric        "string::erase(iterator) called with an iterator not"
31430b57cec5SDimitry Andric        " referring to this string");
31440b57cec5SDimitry Andric#endif
31450b57cec5SDimitry Andric    _LIBCPP_ASSERT(__pos != end(),
31460b57cec5SDimitry Andric        "string::erase(iterator) called with a non-dereferenceable iterator");
31470b57cec5SDimitry Andric    iterator __b = begin();
31480b57cec5SDimitry Andric    size_type __r = static_cast<size_type>(__pos - __b);
31490b57cec5SDimitry Andric    erase(__r, 1);
31500b57cec5SDimitry Andric    return __b + static_cast<difference_type>(__r);
31510b57cec5SDimitry Andric}
31520b57cec5SDimitry Andric
31530b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
31540b57cec5SDimitry Andricinline
31550b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::iterator
31560b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __first, const_iterator __last)
31570b57cec5SDimitry Andric{
31580b57cec5SDimitry Andric#if _LIBCPP_DEBUG_LEVEL >= 2
31590b57cec5SDimitry Andric    _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__first) == this,
31600b57cec5SDimitry Andric        "string::erase(iterator,  iterator) called with an iterator not"
31610b57cec5SDimitry Andric        " referring to this string");
31620b57cec5SDimitry Andric#endif
31630b57cec5SDimitry Andric    _LIBCPP_ASSERT(__first <= __last, "string::erase(first, last) called with invalid range");
31640b57cec5SDimitry Andric    iterator __b = begin();
31650b57cec5SDimitry Andric    size_type __r = static_cast<size_type>(__first - __b);
31660b57cec5SDimitry Andric    erase(__r, static_cast<size_type>(__last - __first));
31670b57cec5SDimitry Andric    return __b + static_cast<difference_type>(__r);
31680b57cec5SDimitry Andric}
31690b57cec5SDimitry Andric
31700b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
31710b57cec5SDimitry Andricinline
31720b57cec5SDimitry Andricvoid
31730b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::pop_back()
31740b57cec5SDimitry Andric{
31750b57cec5SDimitry Andric    _LIBCPP_ASSERT(!empty(), "string::pop_back(): string is already empty");
31760b57cec5SDimitry Andric    size_type __sz;
31770b57cec5SDimitry Andric    if (__is_long())
31780b57cec5SDimitry Andric    {
31790b57cec5SDimitry Andric        __sz = __get_long_size() - 1;
31800b57cec5SDimitry Andric        __set_long_size(__sz);
31810b57cec5SDimitry Andric        traits_type::assign(*(__get_long_pointer() + __sz), value_type());
31820b57cec5SDimitry Andric    }
31830b57cec5SDimitry Andric    else
31840b57cec5SDimitry Andric    {
31850b57cec5SDimitry Andric        __sz = __get_short_size() - 1;
31860b57cec5SDimitry Andric        __set_short_size(__sz);
31870b57cec5SDimitry Andric        traits_type::assign(*(__get_short_pointer() + __sz), value_type());
31880b57cec5SDimitry Andric    }
31890b57cec5SDimitry Andric    __invalidate_iterators_past(__sz);
31900b57cec5SDimitry Andric}
31910b57cec5SDimitry Andric
31920b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
31930b57cec5SDimitry Andricinline
31940b57cec5SDimitry Andricvoid
31950b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::clear() _NOEXCEPT
31960b57cec5SDimitry Andric{
31970b57cec5SDimitry Andric    __invalidate_all_iterators();
31980b57cec5SDimitry Andric    if (__is_long())
31990b57cec5SDimitry Andric    {
32000b57cec5SDimitry Andric        traits_type::assign(*__get_long_pointer(), value_type());
32010b57cec5SDimitry Andric        __set_long_size(0);
32020b57cec5SDimitry Andric    }
32030b57cec5SDimitry Andric    else
32040b57cec5SDimitry Andric    {
32050b57cec5SDimitry Andric        traits_type::assign(*__get_short_pointer(), value_type());
32060b57cec5SDimitry Andric        __set_short_size(0);
32070b57cec5SDimitry Andric    }
32080b57cec5SDimitry Andric}
32090b57cec5SDimitry Andric
32100b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
32110b57cec5SDimitry Andricinline
32120b57cec5SDimitry Andricvoid
32130b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::__erase_to_end(size_type __pos)
32140b57cec5SDimitry Andric{
32150b57cec5SDimitry Andric    if (__is_long())
32160b57cec5SDimitry Andric    {
32170b57cec5SDimitry Andric        traits_type::assign(*(__get_long_pointer() + __pos), value_type());
32180b57cec5SDimitry Andric        __set_long_size(__pos);
32190b57cec5SDimitry Andric    }
32200b57cec5SDimitry Andric    else
32210b57cec5SDimitry Andric    {
32220b57cec5SDimitry Andric        traits_type::assign(*(__get_short_pointer() + __pos), value_type());
32230b57cec5SDimitry Andric        __set_short_size(__pos);
32240b57cec5SDimitry Andric    }
32250b57cec5SDimitry Andric    __invalidate_iterators_past(__pos);
32260b57cec5SDimitry Andric}
32270b57cec5SDimitry Andric
32280b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
32290b57cec5SDimitry Andricvoid
32300b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::resize(size_type __n, value_type __c)
32310b57cec5SDimitry Andric{
32320b57cec5SDimitry Andric    size_type __sz = size();
32330b57cec5SDimitry Andric    if (__n > __sz)
32340b57cec5SDimitry Andric        append(__n - __sz, __c);
32350b57cec5SDimitry Andric    else
32360b57cec5SDimitry Andric        __erase_to_end(__n);
32370b57cec5SDimitry Andric}
32380b57cec5SDimitry Andric
32390b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
32400b57cec5SDimitry Andricinline void
32410b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::__resize_default_init(size_type __n)
32420b57cec5SDimitry Andric{
32430b57cec5SDimitry Andric    size_type __sz = size();
32440b57cec5SDimitry Andric    if (__n > __sz) {
32450b57cec5SDimitry Andric       __append_default_init(__n - __sz);
32460b57cec5SDimitry Andric    } else
32470b57cec5SDimitry Andric        __erase_to_end(__n);
32480b57cec5SDimitry Andric}
32490b57cec5SDimitry Andric
32500b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
32510b57cec5SDimitry Andricinline
32520b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::size_type
32530b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::max_size() const _NOEXCEPT
32540b57cec5SDimitry Andric{
32550b57cec5SDimitry Andric    size_type __m = __alloc_traits::max_size(__alloc());
32560b57cec5SDimitry Andric#ifdef _LIBCPP_BIG_ENDIAN
32570b57cec5SDimitry Andric    return (__m <= ~__long_mask ? __m : __m/2) - __alignment;
32580b57cec5SDimitry Andric#else
32590b57cec5SDimitry Andric    return __m - __alignment;
32600b57cec5SDimitry Andric#endif
32610b57cec5SDimitry Andric}
32620b57cec5SDimitry Andric
32630b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
32640b57cec5SDimitry Andricvoid
32650b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::reserve(size_type __res_arg)
32660b57cec5SDimitry Andric{
32670b57cec5SDimitry Andric    if (__res_arg > max_size())
32680b57cec5SDimitry Andric        this->__throw_length_error();
32690b57cec5SDimitry Andric    size_type __cap = capacity();
32700b57cec5SDimitry Andric    size_type __sz = size();
32710b57cec5SDimitry Andric    __res_arg = _VSTD::max(__res_arg, __sz);
32720b57cec5SDimitry Andric    __res_arg = __recommend(__res_arg);
32730b57cec5SDimitry Andric    if (__res_arg != __cap)
32740b57cec5SDimitry Andric    {
32750b57cec5SDimitry Andric        pointer __new_data, __p;
32760b57cec5SDimitry Andric        bool __was_long, __now_long;
32770b57cec5SDimitry Andric        if (__res_arg == __min_cap - 1)
32780b57cec5SDimitry Andric        {
32790b57cec5SDimitry Andric            __was_long = true;
32800b57cec5SDimitry Andric            __now_long = false;
32810b57cec5SDimitry Andric            __new_data = __get_short_pointer();
32820b57cec5SDimitry Andric            __p = __get_long_pointer();
32830b57cec5SDimitry Andric        }
32840b57cec5SDimitry Andric        else
32850b57cec5SDimitry Andric        {
32860b57cec5SDimitry Andric            if (__res_arg > __cap)
32870b57cec5SDimitry Andric                __new_data = __alloc_traits::allocate(__alloc(), __res_arg+1);
32880b57cec5SDimitry Andric            else
32890b57cec5SDimitry Andric            {
32900b57cec5SDimitry Andric            #ifndef _LIBCPP_NO_EXCEPTIONS
32910b57cec5SDimitry Andric                try
32920b57cec5SDimitry Andric                {
32930b57cec5SDimitry Andric            #endif  // _LIBCPP_NO_EXCEPTIONS
32940b57cec5SDimitry Andric                    __new_data = __alloc_traits::allocate(__alloc(), __res_arg+1);
32950b57cec5SDimitry Andric            #ifndef _LIBCPP_NO_EXCEPTIONS
32960b57cec5SDimitry Andric                }
32970b57cec5SDimitry Andric                catch (...)
32980b57cec5SDimitry Andric                {
32990b57cec5SDimitry Andric                    return;
33000b57cec5SDimitry Andric                }
33010b57cec5SDimitry Andric            #else  // _LIBCPP_NO_EXCEPTIONS
33020b57cec5SDimitry Andric                if (__new_data == nullptr)
33030b57cec5SDimitry Andric                    return;
33040b57cec5SDimitry Andric            #endif  // _LIBCPP_NO_EXCEPTIONS
33050b57cec5SDimitry Andric            }
33060b57cec5SDimitry Andric            __now_long = true;
33070b57cec5SDimitry Andric            __was_long = __is_long();
33080b57cec5SDimitry Andric            __p = __get_pointer();
33090b57cec5SDimitry Andric        }
3310480093f4SDimitry Andric        traits_type::copy(_VSTD::__to_address(__new_data),
3311480093f4SDimitry Andric                          _VSTD::__to_address(__p), size()+1);
33120b57cec5SDimitry Andric        if (__was_long)
33130b57cec5SDimitry Andric            __alloc_traits::deallocate(__alloc(), __p, __cap+1);
33140b57cec5SDimitry Andric        if (__now_long)
33150b57cec5SDimitry Andric        {
33160b57cec5SDimitry Andric            __set_long_cap(__res_arg+1);
33170b57cec5SDimitry Andric            __set_long_size(__sz);
33180b57cec5SDimitry Andric            __set_long_pointer(__new_data);
33190b57cec5SDimitry Andric        }
33200b57cec5SDimitry Andric        else
33210b57cec5SDimitry Andric            __set_short_size(__sz);
33220b57cec5SDimitry Andric        __invalidate_all_iterators();
33230b57cec5SDimitry Andric    }
33240b57cec5SDimitry Andric}
33250b57cec5SDimitry Andric
33260b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
33270b57cec5SDimitry Andricinline
33280b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::const_reference
33290b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos) const _NOEXCEPT
33300b57cec5SDimitry Andric{
33310b57cec5SDimitry Andric    _LIBCPP_ASSERT(__pos <= size(), "string index out of bounds");
33320b57cec5SDimitry Andric    return *(data() + __pos);
33330b57cec5SDimitry Andric}
33340b57cec5SDimitry Andric
33350b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
33360b57cec5SDimitry Andricinline
33370b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::reference
33380b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos) _NOEXCEPT
33390b57cec5SDimitry Andric{
33400b57cec5SDimitry Andric    _LIBCPP_ASSERT(__pos <= size(), "string index out of bounds");
33410b57cec5SDimitry Andric    return *(__get_pointer() + __pos);
33420b57cec5SDimitry Andric}
33430b57cec5SDimitry Andric
33440b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
33450b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::const_reference
33460b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::at(size_type __n) const
33470b57cec5SDimitry Andric{
33480b57cec5SDimitry Andric    if (__n >= size())
33490b57cec5SDimitry Andric        this->__throw_out_of_range();
33500b57cec5SDimitry Andric    return (*this)[__n];
33510b57cec5SDimitry Andric}
33520b57cec5SDimitry Andric
33530b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
33540b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::reference
33550b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::at(size_type __n)
33560b57cec5SDimitry Andric{
33570b57cec5SDimitry Andric    if (__n >= size())
33580b57cec5SDimitry Andric        this->__throw_out_of_range();
33590b57cec5SDimitry Andric    return (*this)[__n];
33600b57cec5SDimitry Andric}
33610b57cec5SDimitry Andric
33620b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
33630b57cec5SDimitry Andricinline
33640b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::reference
33650b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::front() _NOEXCEPT
33660b57cec5SDimitry Andric{
33670b57cec5SDimitry Andric    _LIBCPP_ASSERT(!empty(), "string::front(): string is empty");
33680b57cec5SDimitry Andric    return *__get_pointer();
33690b57cec5SDimitry Andric}
33700b57cec5SDimitry Andric
33710b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
33720b57cec5SDimitry Andricinline
33730b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::const_reference
33740b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::front() const _NOEXCEPT
33750b57cec5SDimitry Andric{
33760b57cec5SDimitry Andric    _LIBCPP_ASSERT(!empty(), "string::front(): string is empty");
33770b57cec5SDimitry Andric    return *data();
33780b57cec5SDimitry Andric}
33790b57cec5SDimitry Andric
33800b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
33810b57cec5SDimitry Andricinline
33820b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::reference
33830b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::back() _NOEXCEPT
33840b57cec5SDimitry Andric{
33850b57cec5SDimitry Andric    _LIBCPP_ASSERT(!empty(), "string::back(): string is empty");
33860b57cec5SDimitry Andric    return *(__get_pointer() + size() - 1);
33870b57cec5SDimitry Andric}
33880b57cec5SDimitry Andric
33890b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
33900b57cec5SDimitry Andricinline
33910b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::const_reference
33920b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::back() const _NOEXCEPT
33930b57cec5SDimitry Andric{
33940b57cec5SDimitry Andric    _LIBCPP_ASSERT(!empty(), "string::back(): string is empty");
33950b57cec5SDimitry Andric    return *(data() + size() - 1);
33960b57cec5SDimitry Andric}
33970b57cec5SDimitry Andric
33980b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
33990b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::size_type
34000b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::copy(value_type* __s, size_type __n, size_type __pos) const
34010b57cec5SDimitry Andric{
34020b57cec5SDimitry Andric    size_type __sz = size();
34030b57cec5SDimitry Andric    if (__pos > __sz)
34040b57cec5SDimitry Andric        this->__throw_out_of_range();
34050b57cec5SDimitry Andric    size_type __rlen = _VSTD::min(__n, __sz - __pos);
34060b57cec5SDimitry Andric    traits_type::copy(__s, data() + __pos, __rlen);
34070b57cec5SDimitry Andric    return __rlen;
34080b57cec5SDimitry Andric}
34090b57cec5SDimitry Andric
34100b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
34110b57cec5SDimitry Andricinline
34120b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>
34130b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::substr(size_type __pos, size_type __n) const
34140b57cec5SDimitry Andric{
34150b57cec5SDimitry Andric    return basic_string(*this, __pos, __n, __alloc());
34160b57cec5SDimitry Andric}
34170b57cec5SDimitry Andric
34180b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
34190b57cec5SDimitry Andricinline
34200b57cec5SDimitry Andricvoid
34210b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::swap(basic_string& __str)
34220b57cec5SDimitry Andric#if _LIBCPP_STD_VER >= 14
34230b57cec5SDimitry Andric        _NOEXCEPT
34240b57cec5SDimitry Andric#else
34250b57cec5SDimitry Andric        _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
34260b57cec5SDimitry Andric                    __is_nothrow_swappable<allocator_type>::value)
34270b57cec5SDimitry Andric#endif
34280b57cec5SDimitry Andric{
34290b57cec5SDimitry Andric#if _LIBCPP_DEBUG_LEVEL >= 2
34300b57cec5SDimitry Andric    if (!__is_long())
34310b57cec5SDimitry Andric        __get_db()->__invalidate_all(this);
34320b57cec5SDimitry Andric    if (!__str.__is_long())
34330b57cec5SDimitry Andric        __get_db()->__invalidate_all(&__str);
34340b57cec5SDimitry Andric    __get_db()->swap(this, &__str);
34350b57cec5SDimitry Andric#endif
34360b57cec5SDimitry Andric    _LIBCPP_ASSERT(
34370b57cec5SDimitry Andric        __alloc_traits::propagate_on_container_swap::value ||
34380b57cec5SDimitry Andric        __alloc_traits::is_always_equal::value ||
34390b57cec5SDimitry Andric        __alloc() == __str.__alloc(), "swapping non-equal allocators");
34400b57cec5SDimitry Andric    _VSTD::swap(__r_.first(), __str.__r_.first());
34410b57cec5SDimitry Andric    __swap_allocator(__alloc(), __str.__alloc());
34420b57cec5SDimitry Andric}
34430b57cec5SDimitry Andric
34440b57cec5SDimitry Andric// find
34450b57cec5SDimitry Andric
34460b57cec5SDimitry Andrictemplate <class _Traits>
34470b57cec5SDimitry Andricstruct _LIBCPP_HIDDEN __traits_eq
34480b57cec5SDimitry Andric{
34490b57cec5SDimitry Andric    typedef typename _Traits::char_type char_type;
34500b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
34510b57cec5SDimitry Andric    bool operator()(const char_type& __x, const char_type& __y) _NOEXCEPT
34520b57cec5SDimitry Andric        {return _Traits::eq(__x, __y);}
34530b57cec5SDimitry Andric};
34540b57cec5SDimitry Andric
34550b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
34560b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::size_type
34570b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s,
34580b57cec5SDimitry Andric                                                size_type __pos,
34590b57cec5SDimitry Andric                                                size_type __n) const _NOEXCEPT
34600b57cec5SDimitry Andric{
34610b57cec5SDimitry Andric    _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find(): received nullptr");
34620b57cec5SDimitry Andric    return __str_find<value_type, size_type, traits_type, npos>
34630b57cec5SDimitry Andric        (data(), size(), __s, __pos, __n);
34640b57cec5SDimitry Andric}
34650b57cec5SDimitry Andric
34660b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
34670b57cec5SDimitry Andricinline
34680b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::size_type
34690b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::find(const basic_string& __str,
34700b57cec5SDimitry Andric                                                size_type __pos) const _NOEXCEPT
34710b57cec5SDimitry Andric{
34720b57cec5SDimitry Andric    return __str_find<value_type, size_type, traits_type, npos>
34730b57cec5SDimitry Andric        (data(), size(), __str.data(), __pos, __str.size());
34740b57cec5SDimitry Andric}
34750b57cec5SDimitry Andric
34760b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
34770b57cec5SDimitry Andrictemplate <class _Tp>
3478*5ffd83dbSDimitry Andric_EnableIf
34790b57cec5SDimitry Andric<
34800b57cec5SDimitry Andric    __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
34810b57cec5SDimitry Andric    typename basic_string<_CharT, _Traits, _Allocator>::size_type
3482*5ffd83dbSDimitry Andric>
34830b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::find(const _Tp &__t,
34840b57cec5SDimitry Andric                                                size_type __pos) const
34850b57cec5SDimitry Andric{
34860b57cec5SDimitry Andric    __self_view __sv = __t;
34870b57cec5SDimitry Andric    return __str_find<value_type, size_type, traits_type, npos>
34880b57cec5SDimitry Andric        (data(), size(), __sv.data(), __pos, __sv.size());
34890b57cec5SDimitry Andric}
34900b57cec5SDimitry Andric
34910b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
34920b57cec5SDimitry Andricinline
34930b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::size_type
34940b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s,
34950b57cec5SDimitry Andric                                                size_type __pos) const _NOEXCEPT
34960b57cec5SDimitry Andric{
34970b57cec5SDimitry Andric    _LIBCPP_ASSERT(__s != nullptr, "string::find(): received nullptr");
34980b57cec5SDimitry Andric    return __str_find<value_type, size_type, traits_type, npos>
34990b57cec5SDimitry Andric        (data(), size(), __s, __pos, traits_type::length(__s));
35000b57cec5SDimitry Andric}
35010b57cec5SDimitry Andric
35020b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
35030b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::size_type
35040b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::find(value_type __c,
35050b57cec5SDimitry Andric                                                size_type __pos) const _NOEXCEPT
35060b57cec5SDimitry Andric{
35070b57cec5SDimitry Andric    return __str_find<value_type, size_type, traits_type, npos>
35080b57cec5SDimitry Andric        (data(), size(), __c, __pos);
35090b57cec5SDimitry Andric}
35100b57cec5SDimitry Andric
35110b57cec5SDimitry Andric// rfind
35120b57cec5SDimitry Andric
35130b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
35140b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::size_type
35150b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s,
35160b57cec5SDimitry Andric                                                 size_type __pos,
35170b57cec5SDimitry Andric                                                 size_type __n) const _NOEXCEPT
35180b57cec5SDimitry Andric{
35190b57cec5SDimitry Andric    _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::rfind(): received nullptr");
35200b57cec5SDimitry Andric    return __str_rfind<value_type, size_type, traits_type, npos>
35210b57cec5SDimitry Andric        (data(), size(), __s, __pos, __n);
35220b57cec5SDimitry Andric}
35230b57cec5SDimitry Andric
35240b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
35250b57cec5SDimitry Andricinline
35260b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::size_type
35270b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::rfind(const basic_string& __str,
35280b57cec5SDimitry Andric                                                 size_type __pos) const _NOEXCEPT
35290b57cec5SDimitry Andric{
35300b57cec5SDimitry Andric    return __str_rfind<value_type, size_type, traits_type, npos>
35310b57cec5SDimitry Andric        (data(), size(), __str.data(), __pos, __str.size());
35320b57cec5SDimitry Andric}
35330b57cec5SDimitry Andric
35340b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
35350b57cec5SDimitry Andrictemplate <class _Tp>
3536*5ffd83dbSDimitry Andric_EnableIf
35370b57cec5SDimitry Andric<
35380b57cec5SDimitry Andric    __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
35390b57cec5SDimitry Andric    typename basic_string<_CharT, _Traits, _Allocator>::size_type
3540*5ffd83dbSDimitry Andric>
35410b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::rfind(const _Tp& __t,
35420b57cec5SDimitry Andric                                                size_type __pos) const
35430b57cec5SDimitry Andric{
35440b57cec5SDimitry Andric    __self_view __sv = __t;
35450b57cec5SDimitry Andric    return __str_rfind<value_type, size_type, traits_type, npos>
35460b57cec5SDimitry Andric        (data(), size(), __sv.data(), __pos, __sv.size());
35470b57cec5SDimitry Andric}
35480b57cec5SDimitry Andric
35490b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
35500b57cec5SDimitry Andricinline
35510b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::size_type
35520b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s,
35530b57cec5SDimitry Andric                                                 size_type __pos) const _NOEXCEPT
35540b57cec5SDimitry Andric{
35550b57cec5SDimitry Andric    _LIBCPP_ASSERT(__s != nullptr, "string::rfind(): received nullptr");
35560b57cec5SDimitry Andric    return __str_rfind<value_type, size_type, traits_type, npos>
35570b57cec5SDimitry Andric        (data(), size(), __s, __pos, traits_type::length(__s));
35580b57cec5SDimitry Andric}
35590b57cec5SDimitry Andric
35600b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
35610b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::size_type
35620b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::rfind(value_type __c,
35630b57cec5SDimitry Andric                                                 size_type __pos) const _NOEXCEPT
35640b57cec5SDimitry Andric{
35650b57cec5SDimitry Andric    return __str_rfind<value_type, size_type, traits_type, npos>
35660b57cec5SDimitry Andric        (data(), size(), __c, __pos);
35670b57cec5SDimitry Andric}
35680b57cec5SDimitry Andric
35690b57cec5SDimitry Andric// find_first_of
35700b57cec5SDimitry Andric
35710b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
35720b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::size_type
35730b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s,
35740b57cec5SDimitry Andric                                                         size_type __pos,
35750b57cec5SDimitry Andric                                                         size_type __n) const _NOEXCEPT
35760b57cec5SDimitry Andric{
35770b57cec5SDimitry Andric    _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_of(): received nullptr");
35780b57cec5SDimitry Andric    return __str_find_first_of<value_type, size_type, traits_type, npos>
35790b57cec5SDimitry Andric        (data(), size(), __s, __pos, __n);
35800b57cec5SDimitry Andric}
35810b57cec5SDimitry Andric
35820b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
35830b57cec5SDimitry Andricinline
35840b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::size_type
35850b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::find_first_of(const basic_string& __str,
35860b57cec5SDimitry Andric                                                         size_type __pos) const _NOEXCEPT
35870b57cec5SDimitry Andric{
35880b57cec5SDimitry Andric    return __str_find_first_of<value_type, size_type, traits_type, npos>
35890b57cec5SDimitry Andric        (data(), size(), __str.data(), __pos, __str.size());
35900b57cec5SDimitry Andric}
35910b57cec5SDimitry Andric
35920b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
35930b57cec5SDimitry Andrictemplate <class _Tp>
3594*5ffd83dbSDimitry Andric_EnableIf
35950b57cec5SDimitry Andric<
35960b57cec5SDimitry Andric    __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
35970b57cec5SDimitry Andric    typename basic_string<_CharT, _Traits, _Allocator>::size_type
3598*5ffd83dbSDimitry Andric>
35990b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::find_first_of(const _Tp& __t,
36000b57cec5SDimitry Andric                                                size_type __pos) const
36010b57cec5SDimitry Andric{
36020b57cec5SDimitry Andric    __self_view __sv = __t;
36030b57cec5SDimitry Andric    return __str_find_first_of<value_type, size_type, traits_type, npos>
36040b57cec5SDimitry Andric        (data(), size(), __sv.data(), __pos, __sv.size());
36050b57cec5SDimitry Andric}
36060b57cec5SDimitry Andric
36070b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
36080b57cec5SDimitry Andricinline
36090b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::size_type
36100b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s,
36110b57cec5SDimitry Andric                                                         size_type __pos) const _NOEXCEPT
36120b57cec5SDimitry Andric{
36130b57cec5SDimitry Andric    _LIBCPP_ASSERT(__s != nullptr, "string::find_first_of(): received nullptr");
36140b57cec5SDimitry Andric    return __str_find_first_of<value_type, size_type, traits_type, npos>
36150b57cec5SDimitry Andric        (data(), size(), __s, __pos, traits_type::length(__s));
36160b57cec5SDimitry Andric}
36170b57cec5SDimitry Andric
36180b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
36190b57cec5SDimitry Andricinline
36200b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::size_type
36210b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::find_first_of(value_type __c,
36220b57cec5SDimitry Andric                                                         size_type __pos) const _NOEXCEPT
36230b57cec5SDimitry Andric{
36240b57cec5SDimitry Andric    return find(__c, __pos);
36250b57cec5SDimitry Andric}
36260b57cec5SDimitry Andric
36270b57cec5SDimitry Andric// find_last_of
36280b57cec5SDimitry Andric
36290b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
36300b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::size_type
36310b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s,
36320b57cec5SDimitry Andric                                                        size_type __pos,
36330b57cec5SDimitry Andric                                                        size_type __n) const _NOEXCEPT
36340b57cec5SDimitry Andric{
36350b57cec5SDimitry Andric    _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_of(): received nullptr");
36360b57cec5SDimitry Andric    return __str_find_last_of<value_type, size_type, traits_type, npos>
36370b57cec5SDimitry Andric        (data(), size(), __s, __pos, __n);
36380b57cec5SDimitry Andric}
36390b57cec5SDimitry Andric
36400b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
36410b57cec5SDimitry Andricinline
36420b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::size_type
36430b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::find_last_of(const basic_string& __str,
36440b57cec5SDimitry Andric                                                        size_type __pos) const _NOEXCEPT
36450b57cec5SDimitry Andric{
36460b57cec5SDimitry Andric    return __str_find_last_of<value_type, size_type, traits_type, npos>
36470b57cec5SDimitry Andric        (data(), size(), __str.data(), __pos, __str.size());
36480b57cec5SDimitry Andric}
36490b57cec5SDimitry Andric
36500b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
36510b57cec5SDimitry Andrictemplate <class _Tp>
3652*5ffd83dbSDimitry Andric_EnableIf
36530b57cec5SDimitry Andric<
36540b57cec5SDimitry Andric    __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
36550b57cec5SDimitry Andric    typename basic_string<_CharT, _Traits, _Allocator>::size_type
3656*5ffd83dbSDimitry Andric>
36570b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::find_last_of(const _Tp& __t,
36580b57cec5SDimitry Andric                                                size_type __pos) const
36590b57cec5SDimitry Andric{
36600b57cec5SDimitry Andric    __self_view __sv = __t;
36610b57cec5SDimitry Andric    return __str_find_last_of<value_type, size_type, traits_type, npos>
36620b57cec5SDimitry Andric        (data(), size(), __sv.data(), __pos, __sv.size());
36630b57cec5SDimitry Andric}
36640b57cec5SDimitry Andric
36650b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
36660b57cec5SDimitry Andricinline
36670b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::size_type
36680b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s,
36690b57cec5SDimitry Andric                                                        size_type __pos) const _NOEXCEPT
36700b57cec5SDimitry Andric{
36710b57cec5SDimitry Andric    _LIBCPP_ASSERT(__s != nullptr, "string::find_last_of(): received nullptr");
36720b57cec5SDimitry Andric    return __str_find_last_of<value_type, size_type, traits_type, npos>
36730b57cec5SDimitry Andric        (data(), size(), __s, __pos, traits_type::length(__s));
36740b57cec5SDimitry Andric}
36750b57cec5SDimitry Andric
36760b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
36770b57cec5SDimitry Andricinline
36780b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::size_type
36790b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::find_last_of(value_type __c,
36800b57cec5SDimitry Andric                                                        size_type __pos) const _NOEXCEPT
36810b57cec5SDimitry Andric{
36820b57cec5SDimitry Andric    return rfind(__c, __pos);
36830b57cec5SDimitry Andric}
36840b57cec5SDimitry Andric
36850b57cec5SDimitry Andric// find_first_not_of
36860b57cec5SDimitry Andric
36870b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
36880b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::size_type
36890b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* __s,
36900b57cec5SDimitry Andric                                                             size_type __pos,
36910b57cec5SDimitry Andric                                                             size_type __n) const _NOEXCEPT
36920b57cec5SDimitry Andric{
36930b57cec5SDimitry Andric    _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_not_of(): received nullptr");
36940b57cec5SDimitry Andric    return __str_find_first_not_of<value_type, size_type, traits_type, npos>
36950b57cec5SDimitry Andric        (data(), size(), __s, __pos, __n);
36960b57cec5SDimitry Andric}
36970b57cec5SDimitry Andric
36980b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
36990b57cec5SDimitry Andricinline
37000b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::size_type
37010b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const basic_string& __str,
37020b57cec5SDimitry Andric                                                             size_type __pos) const _NOEXCEPT
37030b57cec5SDimitry Andric{
37040b57cec5SDimitry Andric    return __str_find_first_not_of<value_type, size_type, traits_type, npos>
37050b57cec5SDimitry Andric        (data(), size(), __str.data(), __pos, __str.size());
37060b57cec5SDimitry Andric}
37070b57cec5SDimitry Andric
37080b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
37090b57cec5SDimitry Andrictemplate <class _Tp>
3710*5ffd83dbSDimitry Andric_EnableIf
37110b57cec5SDimitry Andric<
37120b57cec5SDimitry Andric    __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
37130b57cec5SDimitry Andric    typename basic_string<_CharT, _Traits, _Allocator>::size_type
3714*5ffd83dbSDimitry Andric>
37150b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const _Tp& __t,
37160b57cec5SDimitry Andric                                                size_type __pos) const
37170b57cec5SDimitry Andric{
37180b57cec5SDimitry Andric    __self_view __sv = __t;
37190b57cec5SDimitry Andric    return __str_find_first_not_of<value_type, size_type, traits_type, npos>
37200b57cec5SDimitry Andric        (data(), size(), __sv.data(), __pos, __sv.size());
37210b57cec5SDimitry Andric}
37220b57cec5SDimitry Andric
37230b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
37240b57cec5SDimitry Andricinline
37250b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::size_type
37260b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* __s,
37270b57cec5SDimitry Andric                                                             size_type __pos) const _NOEXCEPT
37280b57cec5SDimitry Andric{
37290b57cec5SDimitry Andric    _LIBCPP_ASSERT(__s != nullptr, "string::find_first_not_of(): received nullptr");
37300b57cec5SDimitry Andric    return __str_find_first_not_of<value_type, size_type, traits_type, npos>
37310b57cec5SDimitry Andric        (data(), size(), __s, __pos, traits_type::length(__s));
37320b57cec5SDimitry Andric}
37330b57cec5SDimitry Andric
37340b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
37350b57cec5SDimitry Andricinline
37360b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::size_type
37370b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::find_first_not_of(value_type __c,
37380b57cec5SDimitry Andric                                                             size_type __pos) const _NOEXCEPT
37390b57cec5SDimitry Andric{
37400b57cec5SDimitry Andric    return __str_find_first_not_of<value_type, size_type, traits_type, npos>
37410b57cec5SDimitry Andric        (data(), size(), __c, __pos);
37420b57cec5SDimitry Andric}
37430b57cec5SDimitry Andric
37440b57cec5SDimitry Andric// find_last_not_of
37450b57cec5SDimitry Andric
37460b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
37470b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::size_type
37480b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __s,
37490b57cec5SDimitry Andric                                                            size_type __pos,
37500b57cec5SDimitry Andric                                                            size_type __n) const _NOEXCEPT
37510b57cec5SDimitry Andric{
37520b57cec5SDimitry Andric    _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_not_of(): received nullptr");
37530b57cec5SDimitry Andric    return __str_find_last_not_of<value_type, size_type, traits_type, npos>
37540b57cec5SDimitry Andric        (data(), size(), __s, __pos, __n);
37550b57cec5SDimitry Andric}
37560b57cec5SDimitry Andric
37570b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
37580b57cec5SDimitry Andricinline
37590b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::size_type
37600b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const basic_string& __str,
37610b57cec5SDimitry Andric                                                            size_type __pos) const _NOEXCEPT
37620b57cec5SDimitry Andric{
37630b57cec5SDimitry Andric    return __str_find_last_not_of<value_type, size_type, traits_type, npos>
37640b57cec5SDimitry Andric        (data(), size(), __str.data(), __pos, __str.size());
37650b57cec5SDimitry Andric}
37660b57cec5SDimitry Andric
37670b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
37680b57cec5SDimitry Andrictemplate <class _Tp>
3769*5ffd83dbSDimitry Andric_EnableIf
37700b57cec5SDimitry Andric<
37710b57cec5SDimitry Andric    __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
37720b57cec5SDimitry Andric    typename basic_string<_CharT, _Traits, _Allocator>::size_type
3773*5ffd83dbSDimitry Andric>
37740b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const _Tp& __t,
37750b57cec5SDimitry Andric                                                size_type __pos) const
37760b57cec5SDimitry Andric{
37770b57cec5SDimitry Andric    __self_view __sv = __t;
37780b57cec5SDimitry Andric    return __str_find_last_not_of<value_type, size_type, traits_type, npos>
37790b57cec5SDimitry Andric        (data(), size(), __sv.data(), __pos, __sv.size());
37800b57cec5SDimitry Andric}
37810b57cec5SDimitry Andric
37820b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
37830b57cec5SDimitry Andricinline
37840b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::size_type
37850b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __s,
37860b57cec5SDimitry Andric                                                            size_type __pos) const _NOEXCEPT
37870b57cec5SDimitry Andric{
37880b57cec5SDimitry Andric    _LIBCPP_ASSERT(__s != nullptr, "string::find_last_not_of(): received nullptr");
37890b57cec5SDimitry Andric    return __str_find_last_not_of<value_type, size_type, traits_type, npos>
37900b57cec5SDimitry Andric        (data(), size(), __s, __pos, traits_type::length(__s));
37910b57cec5SDimitry Andric}
37920b57cec5SDimitry Andric
37930b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
37940b57cec5SDimitry Andricinline
37950b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::size_type
37960b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::find_last_not_of(value_type __c,
37970b57cec5SDimitry Andric                                                            size_type __pos) const _NOEXCEPT
37980b57cec5SDimitry Andric{
37990b57cec5SDimitry Andric    return __str_find_last_not_of<value_type, size_type, traits_type, npos>
38000b57cec5SDimitry Andric        (data(), size(), __c, __pos);
38010b57cec5SDimitry Andric}
38020b57cec5SDimitry Andric
38030b57cec5SDimitry Andric// compare
38040b57cec5SDimitry Andric
38050b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
38060b57cec5SDimitry Andrictemplate <class _Tp>
3807*5ffd83dbSDimitry Andric_EnableIf
38080b57cec5SDimitry Andric<
38090b57cec5SDimitry Andric    __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
38100b57cec5SDimitry Andric    int
3811*5ffd83dbSDimitry Andric>
38120b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::compare(const _Tp& __t) const
38130b57cec5SDimitry Andric{
38140b57cec5SDimitry Andric    __self_view __sv = __t;
38150b57cec5SDimitry Andric    size_t __lhs_sz = size();
38160b57cec5SDimitry Andric    size_t __rhs_sz = __sv.size();
38170b57cec5SDimitry Andric    int __result = traits_type::compare(data(), __sv.data(),
38180b57cec5SDimitry Andric                                        _VSTD::min(__lhs_sz, __rhs_sz));
38190b57cec5SDimitry Andric    if (__result != 0)
38200b57cec5SDimitry Andric        return __result;
38210b57cec5SDimitry Andric    if (__lhs_sz < __rhs_sz)
38220b57cec5SDimitry Andric        return -1;
38230b57cec5SDimitry Andric    if (__lhs_sz > __rhs_sz)
38240b57cec5SDimitry Andric        return 1;
38250b57cec5SDimitry Andric    return 0;
38260b57cec5SDimitry Andric}
38270b57cec5SDimitry Andric
38280b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
38290b57cec5SDimitry Andricinline
38300b57cec5SDimitry Andricint
38310b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::compare(const basic_string& __str) const _NOEXCEPT
38320b57cec5SDimitry Andric{
38330b57cec5SDimitry Andric    return compare(__self_view(__str));
38340b57cec5SDimitry Andric}
38350b57cec5SDimitry Andric
38360b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
38370b57cec5SDimitry Andricint
38380b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
38390b57cec5SDimitry Andric                                                   size_type __n1,
38400b57cec5SDimitry Andric                                                   const value_type* __s,
38410b57cec5SDimitry Andric                                                   size_type __n2) const
38420b57cec5SDimitry Andric{
38430b57cec5SDimitry Andric    _LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::compare(): received nullptr");
38440b57cec5SDimitry Andric    size_type __sz = size();
38450b57cec5SDimitry Andric    if (__pos1 > __sz || __n2 == npos)
38460b57cec5SDimitry Andric        this->__throw_out_of_range();
38470b57cec5SDimitry Andric    size_type __rlen = _VSTD::min(__n1, __sz - __pos1);
38480b57cec5SDimitry Andric    int __r = traits_type::compare(data() + __pos1, __s, _VSTD::min(__rlen, __n2));
38490b57cec5SDimitry Andric    if (__r == 0)
38500b57cec5SDimitry Andric    {
38510b57cec5SDimitry Andric        if (__rlen < __n2)
38520b57cec5SDimitry Andric            __r = -1;
38530b57cec5SDimitry Andric        else if (__rlen > __n2)
38540b57cec5SDimitry Andric            __r = 1;
38550b57cec5SDimitry Andric    }
38560b57cec5SDimitry Andric    return __r;
38570b57cec5SDimitry Andric}
38580b57cec5SDimitry Andric
38590b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
38600b57cec5SDimitry Andrictemplate <class _Tp>
3861*5ffd83dbSDimitry Andric_EnableIf
38620b57cec5SDimitry Andric<
38630b57cec5SDimitry Andric    __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
38640b57cec5SDimitry Andric    int
3865*5ffd83dbSDimitry Andric>
38660b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
38670b57cec5SDimitry Andric                                                   size_type __n1,
38680b57cec5SDimitry Andric                                                   const _Tp& __t) const
38690b57cec5SDimitry Andric{
38700b57cec5SDimitry Andric    __self_view __sv = __t;
38710b57cec5SDimitry Andric    return compare(__pos1, __n1, __sv.data(), __sv.size());
38720b57cec5SDimitry Andric}
38730b57cec5SDimitry Andric
38740b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
38750b57cec5SDimitry Andricinline
38760b57cec5SDimitry Andricint
38770b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
38780b57cec5SDimitry Andric                                                   size_type __n1,
38790b57cec5SDimitry Andric                                                   const basic_string& __str) const
38800b57cec5SDimitry Andric{
38810b57cec5SDimitry Andric    return compare(__pos1, __n1, __str.data(), __str.size());
38820b57cec5SDimitry Andric}
38830b57cec5SDimitry Andric
38840b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
38850b57cec5SDimitry Andrictemplate <class _Tp>
3886*5ffd83dbSDimitry Andric_EnableIf
38870b57cec5SDimitry Andric<
3888*5ffd83dbSDimitry Andric    __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value
3889*5ffd83dbSDimitry Andric    && !__is_same_uncvref<_Tp, basic_string<_CharT, _Traits, _Allocator> >::value,
38900b57cec5SDimitry Andric    int
3891*5ffd83dbSDimitry Andric>
38920b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
38930b57cec5SDimitry Andric                                                   size_type __n1,
38940b57cec5SDimitry Andric                                                   const _Tp& __t,
38950b57cec5SDimitry Andric                                                   size_type __pos2,
38960b57cec5SDimitry Andric                                                   size_type __n2) const
38970b57cec5SDimitry Andric{
38980b57cec5SDimitry Andric    __self_view __sv = __t;
38990b57cec5SDimitry Andric    return __self_view(*this).substr(__pos1, __n1).compare(__sv.substr(__pos2, __n2));
39000b57cec5SDimitry Andric}
39010b57cec5SDimitry Andric
39020b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
39030b57cec5SDimitry Andricint
39040b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
39050b57cec5SDimitry Andric                                                   size_type __n1,
39060b57cec5SDimitry Andric                                                   const basic_string& __str,
39070b57cec5SDimitry Andric                                                   size_type __pos2,
39080b57cec5SDimitry Andric                                                   size_type __n2) const
39090b57cec5SDimitry Andric{
39100b57cec5SDimitry Andric        return compare(__pos1, __n1, __self_view(__str), __pos2, __n2);
39110b57cec5SDimitry Andric}
39120b57cec5SDimitry Andric
39130b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
39140b57cec5SDimitry Andricint
39150b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::compare(const value_type* __s) const _NOEXCEPT
39160b57cec5SDimitry Andric{
39170b57cec5SDimitry Andric    _LIBCPP_ASSERT(__s != nullptr, "string::compare(): received nullptr");
39180b57cec5SDimitry Andric    return compare(0, npos, __s, traits_type::length(__s));
39190b57cec5SDimitry Andric}
39200b57cec5SDimitry Andric
39210b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
39220b57cec5SDimitry Andricint
39230b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
39240b57cec5SDimitry Andric                                                   size_type __n1,
39250b57cec5SDimitry Andric                                                   const value_type* __s) const
39260b57cec5SDimitry Andric{
39270b57cec5SDimitry Andric    _LIBCPP_ASSERT(__s != nullptr, "string::compare(): received nullptr");
39280b57cec5SDimitry Andric    return compare(__pos1, __n1, __s, traits_type::length(__s));
39290b57cec5SDimitry Andric}
39300b57cec5SDimitry Andric
39310b57cec5SDimitry Andric// __invariants
39320b57cec5SDimitry Andric
39330b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
39340b57cec5SDimitry Andricinline
39350b57cec5SDimitry Andricbool
39360b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::__invariants() const
39370b57cec5SDimitry Andric{
39380b57cec5SDimitry Andric    if (size() > capacity())
39390b57cec5SDimitry Andric        return false;
39400b57cec5SDimitry Andric    if (capacity() < __min_cap - 1)
39410b57cec5SDimitry Andric        return false;
39420b57cec5SDimitry Andric    if (data() == 0)
39430b57cec5SDimitry Andric        return false;
39440b57cec5SDimitry Andric    if (data()[size()] != value_type(0))
39450b57cec5SDimitry Andric        return false;
39460b57cec5SDimitry Andric    return true;
39470b57cec5SDimitry Andric}
39480b57cec5SDimitry Andric
39490b57cec5SDimitry Andric// __clear_and_shrink
39500b57cec5SDimitry Andric
39510b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
39520b57cec5SDimitry Andricinline
39530b57cec5SDimitry Andricvoid
39540b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::__clear_and_shrink() _NOEXCEPT
39550b57cec5SDimitry Andric{
39560b57cec5SDimitry Andric    clear();
39570b57cec5SDimitry Andric    if(__is_long())
39580b57cec5SDimitry Andric    {
39590b57cec5SDimitry Andric        __alloc_traits::deallocate(__alloc(), __get_long_pointer(), capacity() + 1);
39600b57cec5SDimitry Andric        __set_long_cap(0);
39610b57cec5SDimitry Andric        __set_short_size(0);
39620b57cec5SDimitry Andric    }
39630b57cec5SDimitry Andric}
39640b57cec5SDimitry Andric
39650b57cec5SDimitry Andric// operator==
39660b57cec5SDimitry Andric
39670b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
39680b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
39690b57cec5SDimitry Andricbool
39700b57cec5SDimitry Andricoperator==(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
39710b57cec5SDimitry Andric           const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
39720b57cec5SDimitry Andric{
39730b57cec5SDimitry Andric    size_t __lhs_sz = __lhs.size();
39740b57cec5SDimitry Andric    return __lhs_sz == __rhs.size() && _Traits::compare(__lhs.data(),
39750b57cec5SDimitry Andric                                                        __rhs.data(),
39760b57cec5SDimitry Andric                                                        __lhs_sz) == 0;
39770b57cec5SDimitry Andric}
39780b57cec5SDimitry Andric
39790b57cec5SDimitry Andrictemplate<class _Allocator>
39800b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
39810b57cec5SDimitry Andricbool
39820b57cec5SDimitry Andricoperator==(const basic_string<char, char_traits<char>, _Allocator>& __lhs,
39830b57cec5SDimitry Andric           const basic_string<char, char_traits<char>, _Allocator>& __rhs) _NOEXCEPT
39840b57cec5SDimitry Andric{
39850b57cec5SDimitry Andric    size_t __lhs_sz = __lhs.size();
39860b57cec5SDimitry Andric    if (__lhs_sz != __rhs.size())
39870b57cec5SDimitry Andric        return false;
39880b57cec5SDimitry Andric    const char* __lp = __lhs.data();
39890b57cec5SDimitry Andric    const char* __rp = __rhs.data();
39900b57cec5SDimitry Andric    if (__lhs.__is_long())
39910b57cec5SDimitry Andric        return char_traits<char>::compare(__lp, __rp, __lhs_sz) == 0;
39920b57cec5SDimitry Andric    for (; __lhs_sz != 0; --__lhs_sz, ++__lp, ++__rp)
39930b57cec5SDimitry Andric        if (*__lp != *__rp)
39940b57cec5SDimitry Andric            return false;
39950b57cec5SDimitry Andric    return true;
39960b57cec5SDimitry Andric}
39970b57cec5SDimitry Andric
39980b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
39990b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
40000b57cec5SDimitry Andricbool
40010b57cec5SDimitry Andricoperator==(const _CharT* __lhs,
40020b57cec5SDimitry Andric           const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
40030b57cec5SDimitry Andric{
40040b57cec5SDimitry Andric    typedef basic_string<_CharT, _Traits, _Allocator> _String;
40050b57cec5SDimitry Andric    _LIBCPP_ASSERT(__lhs != nullptr, "operator==(char*, basic_string): received nullptr");
40060b57cec5SDimitry Andric    size_t __lhs_len = _Traits::length(__lhs);
40070b57cec5SDimitry Andric    if (__lhs_len != __rhs.size()) return false;
40080b57cec5SDimitry Andric    return __rhs.compare(0, _String::npos, __lhs, __lhs_len) == 0;
40090b57cec5SDimitry Andric}
40100b57cec5SDimitry Andric
40110b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
40120b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
40130b57cec5SDimitry Andricbool
40140b57cec5SDimitry Andricoperator==(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
40150b57cec5SDimitry Andric           const _CharT* __rhs) _NOEXCEPT
40160b57cec5SDimitry Andric{
40170b57cec5SDimitry Andric    typedef basic_string<_CharT, _Traits, _Allocator> _String;
40180b57cec5SDimitry Andric    _LIBCPP_ASSERT(__rhs != nullptr, "operator==(basic_string, char*): received nullptr");
40190b57cec5SDimitry Andric    size_t __rhs_len = _Traits::length(__rhs);
40200b57cec5SDimitry Andric    if (__rhs_len != __lhs.size()) return false;
40210b57cec5SDimitry Andric    return __lhs.compare(0, _String::npos, __rhs, __rhs_len) == 0;
40220b57cec5SDimitry Andric}
40230b57cec5SDimitry Andric
40240b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
40250b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
40260b57cec5SDimitry Andricbool
40270b57cec5SDimitry Andricoperator!=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
40280b57cec5SDimitry Andric           const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
40290b57cec5SDimitry Andric{
40300b57cec5SDimitry Andric    return !(__lhs == __rhs);
40310b57cec5SDimitry Andric}
40320b57cec5SDimitry Andric
40330b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
40340b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
40350b57cec5SDimitry Andricbool
40360b57cec5SDimitry Andricoperator!=(const _CharT* __lhs,
40370b57cec5SDimitry Andric           const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
40380b57cec5SDimitry Andric{
40390b57cec5SDimitry Andric    return !(__lhs == __rhs);
40400b57cec5SDimitry Andric}
40410b57cec5SDimitry Andric
40420b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
40430b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
40440b57cec5SDimitry Andricbool
40450b57cec5SDimitry Andricoperator!=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
40460b57cec5SDimitry Andric           const _CharT* __rhs) _NOEXCEPT
40470b57cec5SDimitry Andric{
40480b57cec5SDimitry Andric    return !(__lhs == __rhs);
40490b57cec5SDimitry Andric}
40500b57cec5SDimitry Andric
40510b57cec5SDimitry Andric// operator<
40520b57cec5SDimitry Andric
40530b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
40540b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
40550b57cec5SDimitry Andricbool
40560b57cec5SDimitry Andricoperator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
40570b57cec5SDimitry Andric           const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
40580b57cec5SDimitry Andric{
40590b57cec5SDimitry Andric    return __lhs.compare(__rhs) < 0;
40600b57cec5SDimitry Andric}
40610b57cec5SDimitry Andric
40620b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
40630b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
40640b57cec5SDimitry Andricbool
40650b57cec5SDimitry Andricoperator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
40660b57cec5SDimitry Andric           const _CharT* __rhs) _NOEXCEPT
40670b57cec5SDimitry Andric{
40680b57cec5SDimitry Andric    return __lhs.compare(__rhs) < 0;
40690b57cec5SDimitry Andric}
40700b57cec5SDimitry Andric
40710b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
40720b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
40730b57cec5SDimitry Andricbool
40740b57cec5SDimitry Andricoperator< (const _CharT* __lhs,
40750b57cec5SDimitry Andric           const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
40760b57cec5SDimitry Andric{
40770b57cec5SDimitry Andric    return __rhs.compare(__lhs) > 0;
40780b57cec5SDimitry Andric}
40790b57cec5SDimitry Andric
40800b57cec5SDimitry Andric// operator>
40810b57cec5SDimitry Andric
40820b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
40830b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
40840b57cec5SDimitry Andricbool
40850b57cec5SDimitry Andricoperator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
40860b57cec5SDimitry Andric           const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
40870b57cec5SDimitry Andric{
40880b57cec5SDimitry Andric    return __rhs < __lhs;
40890b57cec5SDimitry Andric}
40900b57cec5SDimitry Andric
40910b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
40920b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
40930b57cec5SDimitry Andricbool
40940b57cec5SDimitry Andricoperator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
40950b57cec5SDimitry Andric           const _CharT* __rhs) _NOEXCEPT
40960b57cec5SDimitry Andric{
40970b57cec5SDimitry Andric    return __rhs < __lhs;
40980b57cec5SDimitry Andric}
40990b57cec5SDimitry Andric
41000b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
41010b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
41020b57cec5SDimitry Andricbool
41030b57cec5SDimitry Andricoperator> (const _CharT* __lhs,
41040b57cec5SDimitry Andric           const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
41050b57cec5SDimitry Andric{
41060b57cec5SDimitry Andric    return __rhs < __lhs;
41070b57cec5SDimitry Andric}
41080b57cec5SDimitry Andric
41090b57cec5SDimitry Andric// operator<=
41100b57cec5SDimitry Andric
41110b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
41120b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
41130b57cec5SDimitry Andricbool
41140b57cec5SDimitry Andricoperator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
41150b57cec5SDimitry Andric           const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
41160b57cec5SDimitry Andric{
41170b57cec5SDimitry Andric    return !(__rhs < __lhs);
41180b57cec5SDimitry Andric}
41190b57cec5SDimitry Andric
41200b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
41210b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
41220b57cec5SDimitry Andricbool
41230b57cec5SDimitry Andricoperator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
41240b57cec5SDimitry Andric           const _CharT* __rhs) _NOEXCEPT
41250b57cec5SDimitry Andric{
41260b57cec5SDimitry Andric    return !(__rhs < __lhs);
41270b57cec5SDimitry Andric}
41280b57cec5SDimitry Andric
41290b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
41300b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
41310b57cec5SDimitry Andricbool
41320b57cec5SDimitry Andricoperator<=(const _CharT* __lhs,
41330b57cec5SDimitry Andric           const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
41340b57cec5SDimitry Andric{
41350b57cec5SDimitry Andric    return !(__rhs < __lhs);
41360b57cec5SDimitry Andric}
41370b57cec5SDimitry Andric
41380b57cec5SDimitry Andric// operator>=
41390b57cec5SDimitry Andric
41400b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
41410b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
41420b57cec5SDimitry Andricbool
41430b57cec5SDimitry Andricoperator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
41440b57cec5SDimitry Andric           const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
41450b57cec5SDimitry Andric{
41460b57cec5SDimitry Andric    return !(__lhs < __rhs);
41470b57cec5SDimitry Andric}
41480b57cec5SDimitry Andric
41490b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
41500b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
41510b57cec5SDimitry Andricbool
41520b57cec5SDimitry Andricoperator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
41530b57cec5SDimitry Andric           const _CharT* __rhs) _NOEXCEPT
41540b57cec5SDimitry Andric{
41550b57cec5SDimitry Andric    return !(__lhs < __rhs);
41560b57cec5SDimitry Andric}
41570b57cec5SDimitry Andric
41580b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
41590b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
41600b57cec5SDimitry Andricbool
41610b57cec5SDimitry Andricoperator>=(const _CharT* __lhs,
41620b57cec5SDimitry Andric           const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
41630b57cec5SDimitry Andric{
41640b57cec5SDimitry Andric    return !(__lhs < __rhs);
41650b57cec5SDimitry Andric}
41660b57cec5SDimitry Andric
41670b57cec5SDimitry Andric// operator +
41680b57cec5SDimitry Andric
41690b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
41700b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>
41710b57cec5SDimitry Andricoperator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
41720b57cec5SDimitry Andric          const basic_string<_CharT, _Traits, _Allocator>& __rhs)
41730b57cec5SDimitry Andric{
41740b57cec5SDimitry Andric    basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
41750b57cec5SDimitry Andric    typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
41760b57cec5SDimitry Andric    typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
41770b57cec5SDimitry Andric    __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + __rhs_sz);
41780b57cec5SDimitry Andric    __r.append(__rhs.data(), __rhs_sz);
41790b57cec5SDimitry Andric    return __r;
41800b57cec5SDimitry Andric}
41810b57cec5SDimitry Andric
41820b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
41830b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>
41840b57cec5SDimitry Andricoperator+(const _CharT* __lhs , const basic_string<_CharT,_Traits,_Allocator>& __rhs)
41850b57cec5SDimitry Andric{
41860b57cec5SDimitry Andric    basic_string<_CharT, _Traits, _Allocator> __r(__rhs.get_allocator());
41870b57cec5SDimitry Andric    typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = _Traits::length(__lhs);
41880b57cec5SDimitry Andric    typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
41890b57cec5SDimitry Andric    __r.__init(__lhs, __lhs_sz, __lhs_sz + __rhs_sz);
41900b57cec5SDimitry Andric    __r.append(__rhs.data(), __rhs_sz);
41910b57cec5SDimitry Andric    return __r;
41920b57cec5SDimitry Andric}
41930b57cec5SDimitry Andric
41940b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
41950b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>
41960b57cec5SDimitry Andricoperator+(_CharT __lhs, const basic_string<_CharT,_Traits,_Allocator>& __rhs)
41970b57cec5SDimitry Andric{
41980b57cec5SDimitry Andric    basic_string<_CharT, _Traits, _Allocator> __r(__rhs.get_allocator());
41990b57cec5SDimitry Andric    typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
42000b57cec5SDimitry Andric    __r.__init(&__lhs, 1, 1 + __rhs_sz);
42010b57cec5SDimitry Andric    __r.append(__rhs.data(), __rhs_sz);
42020b57cec5SDimitry Andric    return __r;
42030b57cec5SDimitry Andric}
42040b57cec5SDimitry Andric
42050b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
42060b57cec5SDimitry Andricinline
42070b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>
42080b57cec5SDimitry Andricoperator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, const _CharT* __rhs)
42090b57cec5SDimitry Andric{
42100b57cec5SDimitry Andric    basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
42110b57cec5SDimitry Andric    typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
42120b57cec5SDimitry Andric    typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = _Traits::length(__rhs);
42130b57cec5SDimitry Andric    __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + __rhs_sz);
42140b57cec5SDimitry Andric    __r.append(__rhs, __rhs_sz);
42150b57cec5SDimitry Andric    return __r;
42160b57cec5SDimitry Andric}
42170b57cec5SDimitry Andric
42180b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
42190b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>
42200b57cec5SDimitry Andricoperator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, _CharT __rhs)
42210b57cec5SDimitry Andric{
42220b57cec5SDimitry Andric    basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
42230b57cec5SDimitry Andric    typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
42240b57cec5SDimitry Andric    __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + 1);
42250b57cec5SDimitry Andric    __r.push_back(__rhs);
42260b57cec5SDimitry Andric    return __r;
42270b57cec5SDimitry Andric}
42280b57cec5SDimitry Andric
42290b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
42300b57cec5SDimitry Andric
42310b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
42320b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
42330b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>
42340b57cec5SDimitry Andricoperator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const basic_string<_CharT, _Traits, _Allocator>& __rhs)
42350b57cec5SDimitry Andric{
42360b57cec5SDimitry Andric    return _VSTD::move(__lhs.append(__rhs));
42370b57cec5SDimitry Andric}
42380b57cec5SDimitry Andric
42390b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
42400b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
42410b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>
42420b57cec5SDimitry Andricoperator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs)
42430b57cec5SDimitry Andric{
42440b57cec5SDimitry Andric    return _VSTD::move(__rhs.insert(0, __lhs));
42450b57cec5SDimitry Andric}
42460b57cec5SDimitry Andric
42470b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
42480b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
42490b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>
42500b57cec5SDimitry Andricoperator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs)
42510b57cec5SDimitry Andric{
42520b57cec5SDimitry Andric    return _VSTD::move(__lhs.append(__rhs));
42530b57cec5SDimitry Andric}
42540b57cec5SDimitry Andric
42550b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
42560b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
42570b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>
42580b57cec5SDimitry Andricoperator+(const _CharT* __lhs , basic_string<_CharT,_Traits,_Allocator>&& __rhs)
42590b57cec5SDimitry Andric{
42600b57cec5SDimitry Andric    return _VSTD::move(__rhs.insert(0, __lhs));
42610b57cec5SDimitry Andric}
42620b57cec5SDimitry Andric
42630b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
42640b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
42650b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>
42660b57cec5SDimitry Andricoperator+(_CharT __lhs, basic_string<_CharT,_Traits,_Allocator>&& __rhs)
42670b57cec5SDimitry Andric{
42680b57cec5SDimitry Andric    __rhs.insert(__rhs.begin(), __lhs);
42690b57cec5SDimitry Andric    return _VSTD::move(__rhs);
42700b57cec5SDimitry Andric}
42710b57cec5SDimitry Andric
42720b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
42730b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
42740b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>
42750b57cec5SDimitry Andricoperator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const _CharT* __rhs)
42760b57cec5SDimitry Andric{
42770b57cec5SDimitry Andric    return _VSTD::move(__lhs.append(__rhs));
42780b57cec5SDimitry Andric}
42790b57cec5SDimitry Andric
42800b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
42810b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
42820b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>
42830b57cec5SDimitry Andricoperator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, _CharT __rhs)
42840b57cec5SDimitry Andric{
42850b57cec5SDimitry Andric    __lhs.push_back(__rhs);
42860b57cec5SDimitry Andric    return _VSTD::move(__lhs);
42870b57cec5SDimitry Andric}
42880b57cec5SDimitry Andric
42890b57cec5SDimitry Andric#endif  // _LIBCPP_CXX03_LANG
42900b57cec5SDimitry Andric
42910b57cec5SDimitry Andric// swap
42920b57cec5SDimitry Andric
42930b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
42940b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
42950b57cec5SDimitry Andricvoid
42960b57cec5SDimitry Andricswap(basic_string<_CharT, _Traits, _Allocator>& __lhs,
42970b57cec5SDimitry Andric     basic_string<_CharT, _Traits, _Allocator>& __rhs)
42980b57cec5SDimitry Andric     _NOEXCEPT_(_NOEXCEPT_(__lhs.swap(__rhs)))
42990b57cec5SDimitry Andric{
43000b57cec5SDimitry Andric    __lhs.swap(__rhs);
43010b57cec5SDimitry Andric}
43020b57cec5SDimitry Andric
43030b57cec5SDimitry Andric#ifndef _LIBCPP_NO_HAS_CHAR8_T
43040b57cec5SDimitry Andrictypedef basic_string<char8_t> u8string;
43050b57cec5SDimitry Andric#endif
43060b57cec5SDimitry Andric
43070b57cec5SDimitry Andric#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
43080b57cec5SDimitry Andrictypedef basic_string<char16_t> u16string;
43090b57cec5SDimitry Andrictypedef basic_string<char32_t> u32string;
43100b57cec5SDimitry Andric#endif  // _LIBCPP_HAS_NO_UNICODE_CHARS
43110b57cec5SDimitry Andric
43120b57cec5SDimitry Andric_LIBCPP_FUNC_VIS int                stoi  (const string& __str, size_t* __idx = 0, int __base = 10);
43130b57cec5SDimitry Andric_LIBCPP_FUNC_VIS long               stol  (const string& __str, size_t* __idx = 0, int __base = 10);
43140b57cec5SDimitry Andric_LIBCPP_FUNC_VIS unsigned long      stoul (const string& __str, size_t* __idx = 0, int __base = 10);
43150b57cec5SDimitry Andric_LIBCPP_FUNC_VIS long long          stoll (const string& __str, size_t* __idx = 0, int __base = 10);
43160b57cec5SDimitry Andric_LIBCPP_FUNC_VIS unsigned long long stoull(const string& __str, size_t* __idx = 0, int __base = 10);
43170b57cec5SDimitry Andric
43180b57cec5SDimitry Andric_LIBCPP_FUNC_VIS float       stof (const string& __str, size_t* __idx = 0);
43190b57cec5SDimitry Andric_LIBCPP_FUNC_VIS double      stod (const string& __str, size_t* __idx = 0);
43200b57cec5SDimitry Andric_LIBCPP_FUNC_VIS long double stold(const string& __str, size_t* __idx = 0);
43210b57cec5SDimitry Andric
43220b57cec5SDimitry Andric_LIBCPP_FUNC_VIS string to_string(int __val);
43230b57cec5SDimitry Andric_LIBCPP_FUNC_VIS string to_string(unsigned __val);
43240b57cec5SDimitry Andric_LIBCPP_FUNC_VIS string to_string(long __val);
43250b57cec5SDimitry Andric_LIBCPP_FUNC_VIS string to_string(unsigned long __val);
43260b57cec5SDimitry Andric_LIBCPP_FUNC_VIS string to_string(long long __val);
43270b57cec5SDimitry Andric_LIBCPP_FUNC_VIS string to_string(unsigned long long __val);
43280b57cec5SDimitry Andric_LIBCPP_FUNC_VIS string to_string(float __val);
43290b57cec5SDimitry Andric_LIBCPP_FUNC_VIS string to_string(double __val);
43300b57cec5SDimitry Andric_LIBCPP_FUNC_VIS string to_string(long double __val);
43310b57cec5SDimitry Andric
43320b57cec5SDimitry Andric_LIBCPP_FUNC_VIS int                stoi  (const wstring& __str, size_t* __idx = 0, int __base = 10);
43330b57cec5SDimitry Andric_LIBCPP_FUNC_VIS long               stol  (const wstring& __str, size_t* __idx = 0, int __base = 10);
43340b57cec5SDimitry Andric_LIBCPP_FUNC_VIS unsigned long      stoul (const wstring& __str, size_t* __idx = 0, int __base = 10);
43350b57cec5SDimitry Andric_LIBCPP_FUNC_VIS long long          stoll (const wstring& __str, size_t* __idx = 0, int __base = 10);
43360b57cec5SDimitry Andric_LIBCPP_FUNC_VIS unsigned long long stoull(const wstring& __str, size_t* __idx = 0, int __base = 10);
43370b57cec5SDimitry Andric
43380b57cec5SDimitry Andric_LIBCPP_FUNC_VIS float       stof (const wstring& __str, size_t* __idx = 0);
43390b57cec5SDimitry Andric_LIBCPP_FUNC_VIS double      stod (const wstring& __str, size_t* __idx = 0);
43400b57cec5SDimitry Andric_LIBCPP_FUNC_VIS long double stold(const wstring& __str, size_t* __idx = 0);
43410b57cec5SDimitry Andric
43420b57cec5SDimitry Andric_LIBCPP_FUNC_VIS wstring to_wstring(int __val);
43430b57cec5SDimitry Andric_LIBCPP_FUNC_VIS wstring to_wstring(unsigned __val);
43440b57cec5SDimitry Andric_LIBCPP_FUNC_VIS wstring to_wstring(long __val);
43450b57cec5SDimitry Andric_LIBCPP_FUNC_VIS wstring to_wstring(unsigned long __val);
43460b57cec5SDimitry Andric_LIBCPP_FUNC_VIS wstring to_wstring(long long __val);
43470b57cec5SDimitry Andric_LIBCPP_FUNC_VIS wstring to_wstring(unsigned long long __val);
43480b57cec5SDimitry Andric_LIBCPP_FUNC_VIS wstring to_wstring(float __val);
43490b57cec5SDimitry Andric_LIBCPP_FUNC_VIS wstring to_wstring(double __val);
43500b57cec5SDimitry Andric_LIBCPP_FUNC_VIS wstring to_wstring(long double __val);
43510b57cec5SDimitry Andric
43520b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
4353*5ffd83dbSDimitry Andric_LIBCPP_FUNC_VIS
43540b57cec5SDimitry Andricconst typename basic_string<_CharT, _Traits, _Allocator>::size_type
43550b57cec5SDimitry Andric               basic_string<_CharT, _Traits, _Allocator>::npos;
43560b57cec5SDimitry Andric
43570b57cec5SDimitry Andrictemplate <class _CharT, class _Allocator>
43580b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS
43590b57cec5SDimitry Andric    hash<basic_string<_CharT, char_traits<_CharT>, _Allocator> >
43600b57cec5SDimitry Andric    : public unary_function<
43610b57cec5SDimitry Andric          basic_string<_CharT, char_traits<_CharT>, _Allocator>, size_t>
43620b57cec5SDimitry Andric{
43630b57cec5SDimitry Andric    size_t
43640b57cec5SDimitry Andric    operator()(const basic_string<_CharT, char_traits<_CharT>, _Allocator>& __val) const _NOEXCEPT
43650b57cec5SDimitry Andric    { return __do_string_hash(__val.data(), __val.data() + __val.size()); }
43660b57cec5SDimitry Andric};
43670b57cec5SDimitry Andric
43680b57cec5SDimitry Andric
43690b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
43700b57cec5SDimitry Andricbasic_ostream<_CharT, _Traits>&
43710b57cec5SDimitry Andricoperator<<(basic_ostream<_CharT, _Traits>& __os,
43720b57cec5SDimitry Andric           const basic_string<_CharT, _Traits, _Allocator>& __str);
43730b57cec5SDimitry Andric
43740b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
43750b57cec5SDimitry Andricbasic_istream<_CharT, _Traits>&
43760b57cec5SDimitry Andricoperator>>(basic_istream<_CharT, _Traits>& __is,
43770b57cec5SDimitry Andric           basic_string<_CharT, _Traits, _Allocator>& __str);
43780b57cec5SDimitry Andric
43790b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
43800b57cec5SDimitry Andricbasic_istream<_CharT, _Traits>&
43810b57cec5SDimitry Andricgetline(basic_istream<_CharT, _Traits>& __is,
43820b57cec5SDimitry Andric        basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm);
43830b57cec5SDimitry Andric
43840b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
43850b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
43860b57cec5SDimitry Andricbasic_istream<_CharT, _Traits>&
43870b57cec5SDimitry Andricgetline(basic_istream<_CharT, _Traits>& __is,
43880b57cec5SDimitry Andric        basic_string<_CharT, _Traits, _Allocator>& __str);
43890b57cec5SDimitry Andric
43900b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
43910b57cec5SDimitry Andric
43920b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
43930b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
43940b57cec5SDimitry Andricbasic_istream<_CharT, _Traits>&
43950b57cec5SDimitry Andricgetline(basic_istream<_CharT, _Traits>&& __is,
43960b57cec5SDimitry Andric        basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm);
43970b57cec5SDimitry Andric
43980b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
43990b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
44000b57cec5SDimitry Andricbasic_istream<_CharT, _Traits>&
44010b57cec5SDimitry Andricgetline(basic_istream<_CharT, _Traits>&& __is,
44020b57cec5SDimitry Andric        basic_string<_CharT, _Traits, _Allocator>& __str);
44030b57cec5SDimitry Andric
44040b57cec5SDimitry Andric#endif  // _LIBCPP_CXX03_LANG
44050b57cec5SDimitry Andric
44060b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 17
44070b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator, class _Up>
44080b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
4409*5ffd83dbSDimitry Andric    typename basic_string<_CharT, _Traits, _Allocator>::size_type
4410*5ffd83dbSDimitry Andric    erase(basic_string<_CharT, _Traits, _Allocator>& __str, const _Up& __v) {
4411*5ffd83dbSDimitry Andric  auto __old_size = __str.size();
4412*5ffd83dbSDimitry Andric  __str.erase(_VSTD::remove(__str.begin(), __str.end(), __v), __str.end());
4413*5ffd83dbSDimitry Andric  return __old_size - __str.size();
4414*5ffd83dbSDimitry Andric}
44150b57cec5SDimitry Andric
44160b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator, class _Predicate>
44170b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
4418*5ffd83dbSDimitry Andric    typename basic_string<_CharT, _Traits, _Allocator>::size_type
4419*5ffd83dbSDimitry Andric    erase_if(basic_string<_CharT, _Traits, _Allocator>& __str,
4420*5ffd83dbSDimitry Andric             _Predicate __pred) {
4421*5ffd83dbSDimitry Andric  auto __old_size = __str.size();
4422*5ffd83dbSDimitry Andric  __str.erase(_VSTD::remove_if(__str.begin(), __str.end(), __pred),
4423*5ffd83dbSDimitry Andric              __str.end());
4424*5ffd83dbSDimitry Andric  return __old_size - __str.size();
4425*5ffd83dbSDimitry Andric}
44260b57cec5SDimitry Andric#endif
44270b57cec5SDimitry Andric
44280b57cec5SDimitry Andric#if _LIBCPP_DEBUG_LEVEL >= 2
44290b57cec5SDimitry Andric
44300b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
44310b57cec5SDimitry Andricbool
44320b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::__dereferenceable(const const_iterator* __i) const
44330b57cec5SDimitry Andric{
4434480093f4SDimitry Andric    return this->data() <= _VSTD::__to_address(__i->base()) &&
4435480093f4SDimitry Andric           _VSTD::__to_address(__i->base()) < this->data() + this->size();
44360b57cec5SDimitry Andric}
44370b57cec5SDimitry Andric
44380b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
44390b57cec5SDimitry Andricbool
44400b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::__decrementable(const const_iterator* __i) const
44410b57cec5SDimitry Andric{
4442480093f4SDimitry Andric    return this->data() < _VSTD::__to_address(__i->base()) &&
4443480093f4SDimitry Andric           _VSTD::__to_address(__i->base()) <= this->data() + this->size();
44440b57cec5SDimitry Andric}
44450b57cec5SDimitry Andric
44460b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
44470b57cec5SDimitry Andricbool
44480b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::__addable(const const_iterator* __i, ptrdiff_t __n) const
44490b57cec5SDimitry Andric{
4450480093f4SDimitry Andric    const value_type* __p = _VSTD::__to_address(__i->base()) + __n;
44510b57cec5SDimitry Andric    return this->data() <= __p && __p <= this->data() + this->size();
44520b57cec5SDimitry Andric}
44530b57cec5SDimitry Andric
44540b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
44550b57cec5SDimitry Andricbool
44560b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::__subscriptable(const const_iterator* __i, ptrdiff_t __n) const
44570b57cec5SDimitry Andric{
4458480093f4SDimitry Andric    const value_type* __p = _VSTD::__to_address(__i->base()) + __n;
44590b57cec5SDimitry Andric    return this->data() <= __p && __p < this->data() + this->size();
44600b57cec5SDimitry Andric}
44610b57cec5SDimitry Andric
44620b57cec5SDimitry Andric#endif  // _LIBCPP_DEBUG_LEVEL >= 2
44630b57cec5SDimitry Andric
44640b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11
44650b57cec5SDimitry Andric// Literal suffixes for basic_string [basic.string.literals]
44660b57cec5SDimitry Andricinline namespace literals
44670b57cec5SDimitry Andric{
44680b57cec5SDimitry Andric  inline namespace string_literals
44690b57cec5SDimitry Andric  {
44700b57cec5SDimitry Andric    inline _LIBCPP_INLINE_VISIBILITY
44710b57cec5SDimitry Andric    basic_string<char> operator "" s( const char *__str, size_t __len )
44720b57cec5SDimitry Andric    {
44730b57cec5SDimitry Andric        return basic_string<char> (__str, __len);
44740b57cec5SDimitry Andric    }
44750b57cec5SDimitry Andric
44760b57cec5SDimitry Andric    inline _LIBCPP_INLINE_VISIBILITY
44770b57cec5SDimitry Andric    basic_string<wchar_t> operator "" s( const wchar_t *__str, size_t __len )
44780b57cec5SDimitry Andric    {
44790b57cec5SDimitry Andric        return basic_string<wchar_t> (__str, __len);
44800b57cec5SDimitry Andric    }
44810b57cec5SDimitry Andric
44820b57cec5SDimitry Andric#ifndef _LIBCPP_NO_HAS_CHAR8_T
44830b57cec5SDimitry Andric    inline _LIBCPP_INLINE_VISIBILITY
44840b57cec5SDimitry Andric    basic_string<char8_t> operator "" s(const char8_t *__str, size_t __len) _NOEXCEPT
44850b57cec5SDimitry Andric    {
44860b57cec5SDimitry Andric        return basic_string<char8_t> (__str, __len);
44870b57cec5SDimitry Andric    }
44880b57cec5SDimitry Andric#endif
44890b57cec5SDimitry Andric
44900b57cec5SDimitry Andric    inline _LIBCPP_INLINE_VISIBILITY
44910b57cec5SDimitry Andric    basic_string<char16_t> operator "" s( const char16_t *__str, size_t __len )
44920b57cec5SDimitry Andric    {
44930b57cec5SDimitry Andric        return basic_string<char16_t> (__str, __len);
44940b57cec5SDimitry Andric    }
44950b57cec5SDimitry Andric
44960b57cec5SDimitry Andric    inline _LIBCPP_INLINE_VISIBILITY
44970b57cec5SDimitry Andric    basic_string<char32_t> operator "" s( const char32_t *__str, size_t __len )
44980b57cec5SDimitry Andric    {
44990b57cec5SDimitry Andric        return basic_string<char32_t> (__str, __len);
45000b57cec5SDimitry Andric    }
45010b57cec5SDimitry Andric  }
45020b57cec5SDimitry Andric}
45030b57cec5SDimitry Andric#endif
45040b57cec5SDimitry Andric
45050b57cec5SDimitry Andric_LIBCPP_END_NAMESPACE_STD
45060b57cec5SDimitry Andric
45070b57cec5SDimitry Andric_LIBCPP_POP_MACROS
45080b57cec5SDimitry Andric
45090b57cec5SDimitry Andric#endif  // _LIBCPP_STRING
4510