xref: /freebsd/contrib/llvm-project/libcxx/include/string (revision 349cc55c9796c4596a5b9904cd3281af295f878f)
10b57cec5SDimitry Andric// -*- C++ -*-
2*349cc55cSDimitry Andric//===----------------------------------------------------------------------===//
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>;
72fe6060f1SDimitry Andrictemplate <> struct char_traits<char8_t>;  // C++20
73fe6060f1SDimitry Andrictemplate <> struct char_traits<char16_t>;
74fe6060f1SDimitry Andrictemplate <> struct char_traits<char32_t>;
750b57cec5SDimitry Andric
760b57cec5SDimitry Andrictemplate<class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> >
770b57cec5SDimitry Andricclass basic_string
780b57cec5SDimitry Andric{
790b57cec5SDimitry Andricpublic:
800b57cec5SDimitry Andric// types:
810b57cec5SDimitry Andric    typedef traits traits_type;
820b57cec5SDimitry Andric    typedef typename traits_type::char_type value_type;
830b57cec5SDimitry Andric    typedef Allocator allocator_type;
840b57cec5SDimitry Andric    typedef typename allocator_type::size_type size_type;
850b57cec5SDimitry Andric    typedef typename allocator_type::difference_type difference_type;
860b57cec5SDimitry Andric    typedef typename allocator_type::reference reference;
870b57cec5SDimitry Andric    typedef typename allocator_type::const_reference const_reference;
880b57cec5SDimitry Andric    typedef typename allocator_type::pointer pointer;
890b57cec5SDimitry Andric    typedef typename allocator_type::const_pointer const_pointer;
900b57cec5SDimitry Andric    typedef implementation-defined iterator;
910b57cec5SDimitry Andric    typedef implementation-defined const_iterator;
920b57cec5SDimitry Andric    typedef std::reverse_iterator<iterator> reverse_iterator;
930b57cec5SDimitry Andric    typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
940b57cec5SDimitry Andric
950b57cec5SDimitry Andric    static const size_type npos = -1;
960b57cec5SDimitry Andric
970b57cec5SDimitry Andric    basic_string()
980b57cec5SDimitry Andric        noexcept(is_nothrow_default_constructible<allocator_type>::value);
990b57cec5SDimitry Andric    explicit basic_string(const allocator_type& a);
1000b57cec5SDimitry Andric    basic_string(const basic_string& str);
1010b57cec5SDimitry Andric    basic_string(basic_string&& str)
1020b57cec5SDimitry Andric        noexcept(is_nothrow_move_constructible<allocator_type>::value);
1030b57cec5SDimitry Andric    basic_string(const basic_string& str, size_type pos,
1040b57cec5SDimitry Andric                 const allocator_type& a = allocator_type());
1050b57cec5SDimitry Andric    basic_string(const basic_string& str, size_type pos, size_type n,
1060b57cec5SDimitry Andric                 const Allocator& a = Allocator());
1070b57cec5SDimitry Andric    template<class T>
1080b57cec5SDimitry Andric        basic_string(const T& t, size_type pos, size_type n, const Allocator& a = Allocator()); // C++17
1090b57cec5SDimitry Andric    template <class T>
1100b57cec5SDimitry Andric        explicit basic_string(const T& t, const Allocator& a = Allocator()); // C++17
1110b57cec5SDimitry Andric    basic_string(const value_type* s, const allocator_type& a = allocator_type());
1120b57cec5SDimitry Andric    basic_string(const value_type* s, size_type n, const allocator_type& a = allocator_type());
113fe6060f1SDimitry Andric    basic_string(nullptr_t) = delete; // C++2b
1140b57cec5SDimitry Andric    basic_string(size_type n, value_type c, const allocator_type& a = allocator_type());
1150b57cec5SDimitry Andric    template<class InputIterator>
1160b57cec5SDimitry Andric        basic_string(InputIterator begin, InputIterator end,
1170b57cec5SDimitry Andric                     const allocator_type& a = allocator_type());
1180b57cec5SDimitry Andric    basic_string(initializer_list<value_type>, const Allocator& = Allocator());
1190b57cec5SDimitry Andric    basic_string(const basic_string&, const Allocator&);
1200b57cec5SDimitry Andric    basic_string(basic_string&&, const Allocator&);
1210b57cec5SDimitry Andric
1220b57cec5SDimitry Andric    ~basic_string();
1230b57cec5SDimitry Andric
1240b57cec5SDimitry Andric    operator basic_string_view<charT, traits>() const noexcept;
1250b57cec5SDimitry Andric
1260b57cec5SDimitry Andric    basic_string& operator=(const basic_string& str);
1270b57cec5SDimitry Andric    template <class T>
1280b57cec5SDimitry Andric        basic_string& operator=(const T& t); // C++17
1290b57cec5SDimitry Andric    basic_string& operator=(basic_string&& str)
1300b57cec5SDimitry Andric        noexcept(
1310b57cec5SDimitry Andric             allocator_type::propagate_on_container_move_assignment::value ||
1320b57cec5SDimitry Andric             allocator_type::is_always_equal::value ); // C++17
1330b57cec5SDimitry Andric    basic_string& operator=(const value_type* s);
134fe6060f1SDimitry Andric    basic_string& operator=(nullptr_t) = delete; // C++2b
1350b57cec5SDimitry Andric    basic_string& operator=(value_type c);
1360b57cec5SDimitry Andric    basic_string& operator=(initializer_list<value_type>);
1370b57cec5SDimitry Andric
1380b57cec5SDimitry Andric    iterator       begin() noexcept;
1390b57cec5SDimitry Andric    const_iterator begin() const noexcept;
1400b57cec5SDimitry Andric    iterator       end() noexcept;
1410b57cec5SDimitry Andric    const_iterator end() const noexcept;
1420b57cec5SDimitry Andric
1430b57cec5SDimitry Andric    reverse_iterator       rbegin() noexcept;
1440b57cec5SDimitry Andric    const_reverse_iterator rbegin() const noexcept;
1450b57cec5SDimitry Andric    reverse_iterator       rend() noexcept;
1460b57cec5SDimitry Andric    const_reverse_iterator rend() const noexcept;
1470b57cec5SDimitry Andric
1480b57cec5SDimitry Andric    const_iterator         cbegin() const noexcept;
1490b57cec5SDimitry Andric    const_iterator         cend() const noexcept;
1500b57cec5SDimitry Andric    const_reverse_iterator crbegin() const noexcept;
1510b57cec5SDimitry Andric    const_reverse_iterator crend() const noexcept;
1520b57cec5SDimitry Andric
1530b57cec5SDimitry Andric    size_type size() const noexcept;
1540b57cec5SDimitry Andric    size_type length() const noexcept;
1550b57cec5SDimitry Andric    size_type max_size() const noexcept;
1560b57cec5SDimitry Andric    size_type capacity() const noexcept;
1570b57cec5SDimitry Andric
1580b57cec5SDimitry Andric    void resize(size_type n, value_type c);
1590b57cec5SDimitry Andric    void resize(size_type n);
1600b57cec5SDimitry Andric
161e8d8bef9SDimitry Andric    void reserve(size_type res_arg);
162e8d8bef9SDimitry Andric    void reserve(); // deprecated in C++20
1630b57cec5SDimitry Andric    void shrink_to_fit();
1640b57cec5SDimitry Andric    void clear() noexcept;
1650b57cec5SDimitry Andric    bool empty() const noexcept;
1660b57cec5SDimitry Andric
1670b57cec5SDimitry Andric    const_reference operator[](size_type pos) const;
1680b57cec5SDimitry Andric    reference       operator[](size_type pos);
1690b57cec5SDimitry Andric
1700b57cec5SDimitry Andric    const_reference at(size_type n) const;
1710b57cec5SDimitry Andric    reference       at(size_type n);
1720b57cec5SDimitry Andric
1730b57cec5SDimitry Andric    basic_string& operator+=(const basic_string& str);
1740b57cec5SDimitry Andric    template <class T>
1750b57cec5SDimitry Andric        basic_string& operator+=(const T& t);              // C++17
1760b57cec5SDimitry Andric    basic_string& operator+=(const value_type* s);
1770b57cec5SDimitry Andric    basic_string& operator+=(value_type c);
1780b57cec5SDimitry Andric    basic_string& operator+=(initializer_list<value_type>);
1790b57cec5SDimitry Andric
1800b57cec5SDimitry Andric    basic_string& append(const basic_string& str);
1810b57cec5SDimitry Andric    template <class T>
1820b57cec5SDimitry Andric        basic_string& append(const T& t);                 // C++17
1830b57cec5SDimitry Andric    basic_string& append(const basic_string& str, size_type pos, size_type n=npos); //C++14
1840b57cec5SDimitry Andric    template <class T>
1850b57cec5SDimitry Andric        basic_string& append(const T& t, size_type pos, size_type n=npos); // C++17
1860b57cec5SDimitry Andric    basic_string& append(const value_type* s, size_type n);
1870b57cec5SDimitry Andric    basic_string& append(const value_type* s);
1880b57cec5SDimitry Andric    basic_string& append(size_type n, value_type c);
1890b57cec5SDimitry Andric    template<class InputIterator>
1900b57cec5SDimitry Andric        basic_string& append(InputIterator first, InputIterator last);
1910b57cec5SDimitry Andric    basic_string& append(initializer_list<value_type>);
1920b57cec5SDimitry Andric
1930b57cec5SDimitry Andric    void push_back(value_type c);
1940b57cec5SDimitry Andric    void pop_back();
1950b57cec5SDimitry Andric    reference       front();
1960b57cec5SDimitry Andric    const_reference front() const;
1970b57cec5SDimitry Andric    reference       back();
1980b57cec5SDimitry Andric    const_reference back() const;
1990b57cec5SDimitry Andric
2000b57cec5SDimitry Andric    basic_string& assign(const basic_string& str);
2010b57cec5SDimitry Andric    template <class T>
2020b57cec5SDimitry Andric        basic_string& assign(const T& t);  // C++17
2030b57cec5SDimitry Andric    basic_string& assign(basic_string&& str);
2040b57cec5SDimitry Andric    basic_string& assign(const basic_string& str, size_type pos, size_type n=npos); // C++14
2050b57cec5SDimitry Andric    template <class T>
2060b57cec5SDimitry Andric        basic_string& assign(const T& t, size_type pos, size_type n=npos); // C++17
2070b57cec5SDimitry Andric    basic_string& assign(const value_type* s, size_type n);
2080b57cec5SDimitry Andric    basic_string& assign(const value_type* s);
2090b57cec5SDimitry Andric    basic_string& assign(size_type n, value_type c);
2100b57cec5SDimitry Andric    template<class InputIterator>
2110b57cec5SDimitry Andric        basic_string& assign(InputIterator first, InputIterator last);
2120b57cec5SDimitry Andric    basic_string& assign(initializer_list<value_type>);
2130b57cec5SDimitry Andric
2140b57cec5SDimitry Andric    basic_string& insert(size_type pos1, const basic_string& str);
2150b57cec5SDimitry Andric    template <class T>
2160b57cec5SDimitry Andric        basic_string& insert(size_type pos1, const T& t);
2170b57cec5SDimitry Andric    basic_string& insert(size_type pos1, const basic_string& str,
2180b57cec5SDimitry Andric                         size_type pos2, size_type n);
2190b57cec5SDimitry Andric    template <class T>
2200b57cec5SDimitry Andric        basic_string& insert(size_type pos1, const T& t, size_type pos2, size_type n); // C++17
2210b57cec5SDimitry Andric    basic_string& insert(size_type pos, const value_type* s, size_type n=npos); //C++14
2220b57cec5SDimitry Andric    basic_string& insert(size_type pos, const value_type* s);
2230b57cec5SDimitry Andric    basic_string& insert(size_type pos, size_type n, value_type c);
2240b57cec5SDimitry Andric    iterator      insert(const_iterator p, value_type c);
2250b57cec5SDimitry Andric    iterator      insert(const_iterator p, size_type n, value_type c);
2260b57cec5SDimitry Andric    template<class InputIterator>
2270b57cec5SDimitry Andric        iterator insert(const_iterator p, InputIterator first, InputIterator last);
2280b57cec5SDimitry Andric    iterator      insert(const_iterator p, initializer_list<value_type>);
2290b57cec5SDimitry Andric
2300b57cec5SDimitry Andric    basic_string& erase(size_type pos = 0, size_type n = npos);
2310b57cec5SDimitry Andric    iterator      erase(const_iterator position);
2320b57cec5SDimitry Andric    iterator      erase(const_iterator first, const_iterator last);
2330b57cec5SDimitry Andric
2340b57cec5SDimitry Andric    basic_string& replace(size_type pos1, size_type n1, const basic_string& str);
2350b57cec5SDimitry Andric    template <class T>
2360b57cec5SDimitry Andric    basic_string& replace(size_type pos1, size_type n1, const T& t);  // C++17
2370b57cec5SDimitry Andric    basic_string& replace(size_type pos1, size_type n1, const basic_string& str,
2380b57cec5SDimitry Andric                          size_type pos2, size_type n2=npos); // C++14
2390b57cec5SDimitry Andric    template <class T>
2400b57cec5SDimitry Andric        basic_string& replace(size_type pos1, size_type n1, const T& t,
2410b57cec5SDimitry Andric                              size_type pos2, size_type n); // C++17
2420b57cec5SDimitry Andric    basic_string& replace(size_type pos, size_type n1, const value_type* s, size_type n2);
2430b57cec5SDimitry Andric    basic_string& replace(size_type pos, size_type n1, const value_type* s);
2440b57cec5SDimitry Andric    basic_string& replace(size_type pos, size_type n1, size_type n2, value_type c);
2450b57cec5SDimitry Andric    basic_string& replace(const_iterator i1, const_iterator i2, const basic_string& str);
2460b57cec5SDimitry Andric    template <class T>
2470b57cec5SDimitry Andric        basic_string& replace(const_iterator i1, const_iterator i2, const T& t);  // C++17
2480b57cec5SDimitry Andric    basic_string& replace(const_iterator i1, const_iterator i2, const value_type* s, size_type n);
2490b57cec5SDimitry Andric    basic_string& replace(const_iterator i1, const_iterator i2, const value_type* s);
2500b57cec5SDimitry Andric    basic_string& replace(const_iterator i1, const_iterator i2, size_type n, value_type c);
2510b57cec5SDimitry Andric    template<class InputIterator>
2520b57cec5SDimitry Andric        basic_string& replace(const_iterator i1, const_iterator i2, InputIterator j1, InputIterator j2);
2530b57cec5SDimitry Andric    basic_string& replace(const_iterator i1, const_iterator i2, initializer_list<value_type>);
2540b57cec5SDimitry Andric
2550b57cec5SDimitry Andric    size_type copy(value_type* s, size_type n, size_type pos = 0) const;
2560b57cec5SDimitry Andric    basic_string substr(size_type pos = 0, size_type n = npos) const;
2570b57cec5SDimitry Andric
2580b57cec5SDimitry Andric    void swap(basic_string& str)
2590b57cec5SDimitry Andric        noexcept(allocator_traits<allocator_type>::propagate_on_container_swap::value ||
2600b57cec5SDimitry Andric                 allocator_traits<allocator_type>::is_always_equal::value);  // C++17
2610b57cec5SDimitry Andric
2620b57cec5SDimitry Andric    const value_type* c_str() const noexcept;
2630b57cec5SDimitry Andric    const value_type* data() const noexcept;
2640b57cec5SDimitry Andric          value_type* data()       noexcept;   // C++17
2650b57cec5SDimitry Andric
2660b57cec5SDimitry Andric    allocator_type get_allocator() const noexcept;
2670b57cec5SDimitry Andric
2680b57cec5SDimitry Andric    size_type find(const basic_string& str, size_type pos = 0) const noexcept;
2690b57cec5SDimitry Andric    template <class T>
270fe6060f1SDimitry Andric        size_type find(const T& t, size_type pos = 0) const noexcept; // C++17, noexcept as an extension
2710b57cec5SDimitry Andric    size_type find(const value_type* s, size_type pos, size_type n) const noexcept;
2720b57cec5SDimitry Andric    size_type find(const value_type* s, size_type pos = 0) const noexcept;
2730b57cec5SDimitry Andric    size_type find(value_type c, size_type pos = 0) const noexcept;
2740b57cec5SDimitry Andric
2750b57cec5SDimitry Andric    size_type rfind(const basic_string& str, size_type pos = npos) const noexcept;
2760b57cec5SDimitry Andric    template <class T>
277fe6060f1SDimitry Andric        size_type rfind(const T& t, size_type pos = npos) const noexcept; // C++17, noexcept as an extension
2780b57cec5SDimitry Andric    size_type rfind(const value_type* s, size_type pos, size_type n) const noexcept;
2790b57cec5SDimitry Andric    size_type rfind(const value_type* s, size_type pos = npos) const noexcept;
2800b57cec5SDimitry Andric    size_type rfind(value_type c, size_type pos = npos) const noexcept;
2810b57cec5SDimitry Andric
2820b57cec5SDimitry Andric    size_type find_first_of(const basic_string& str, size_type pos = 0) const noexcept;
2830b57cec5SDimitry Andric    template <class T>
284fe6060f1SDimitry Andric        size_type find_first_of(const T& t, size_type pos = 0) const noexcept; // C++17, noexcept as an extension
2850b57cec5SDimitry Andric    size_type find_first_of(const value_type* s, size_type pos, size_type n) const noexcept;
2860b57cec5SDimitry Andric    size_type find_first_of(const value_type* s, size_type pos = 0) const noexcept;
2870b57cec5SDimitry Andric    size_type find_first_of(value_type c, size_type pos = 0) const noexcept;
2880b57cec5SDimitry Andric
2890b57cec5SDimitry Andric    size_type find_last_of(const basic_string& str, size_type pos = npos) const noexcept;
2900b57cec5SDimitry Andric    template <class T>
291fe6060f1SDimitry Andric        size_type find_last_of(const T& t, size_type pos = npos) const noexcept noexcept; // C++17, noexcept as an extension
2920b57cec5SDimitry Andric    size_type find_last_of(const value_type* s, size_type pos, size_type n) const noexcept;
2930b57cec5SDimitry Andric    size_type find_last_of(const value_type* s, size_type pos = npos) const noexcept;
2940b57cec5SDimitry Andric    size_type find_last_of(value_type c, size_type pos = npos) const noexcept;
2950b57cec5SDimitry Andric
2960b57cec5SDimitry Andric    size_type find_first_not_of(const basic_string& str, size_type pos = 0) const noexcept;
2970b57cec5SDimitry Andric    template <class T>
298fe6060f1SDimitry Andric        size_type find_first_not_of(const T& t, size_type pos = 0) const noexcept; // C++17, noexcept as an extension
2990b57cec5SDimitry Andric    size_type find_first_not_of(const value_type* s, size_type pos, size_type n) const noexcept;
3000b57cec5SDimitry Andric    size_type find_first_not_of(const value_type* s, size_type pos = 0) const noexcept;
3010b57cec5SDimitry Andric    size_type find_first_not_of(value_type c, size_type pos = 0) const noexcept;
3020b57cec5SDimitry Andric
3030b57cec5SDimitry Andric    size_type find_last_not_of(const basic_string& str, size_type pos = npos) const noexcept;
3040b57cec5SDimitry Andric    template <class T>
305fe6060f1SDimitry Andric        size_type find_last_not_of(const T& t, size_type pos = npos) const noexcept; // C++17, noexcept as an extension
3060b57cec5SDimitry Andric    size_type find_last_not_of(const value_type* s, size_type pos, size_type n) const noexcept;
3070b57cec5SDimitry Andric    size_type find_last_not_of(const value_type* s, size_type pos = npos) const noexcept;
3080b57cec5SDimitry Andric    size_type find_last_not_of(value_type c, size_type pos = npos) const noexcept;
3090b57cec5SDimitry Andric
3100b57cec5SDimitry Andric    int compare(const basic_string& str) const noexcept;
3110b57cec5SDimitry Andric    template <class T>
312fe6060f1SDimitry Andric        int compare(const T& t) const noexcept;  // C++17, noexcept as an extension
3130b57cec5SDimitry Andric    int compare(size_type pos1, size_type n1, const basic_string& str) const;
3140b57cec5SDimitry Andric    template <class T>
3150b57cec5SDimitry Andric        int compare(size_type pos1, size_type n1, const T& t) const;  // C++17
3160b57cec5SDimitry Andric    int compare(size_type pos1, size_type n1, const basic_string& str,
3170b57cec5SDimitry Andric                size_type pos2, size_type n2=npos) const; // C++14
3180b57cec5SDimitry Andric    template <class T>
3190b57cec5SDimitry Andric        int compare(size_type pos1, size_type n1, const T& t,
3200b57cec5SDimitry Andric                    size_type pos2, size_type n2=npos) const; // C++17
3210b57cec5SDimitry Andric    int compare(const value_type* s) const noexcept;
3220b57cec5SDimitry Andric    int compare(size_type pos1, size_type n1, const value_type* s) const;
3230b57cec5SDimitry Andric    int compare(size_type pos1, size_type n1, const value_type* s, size_type n2) const;
3240b57cec5SDimitry Andric
325e8d8bef9SDimitry Andric    bool starts_with(basic_string_view<charT, traits> sv) const noexcept; // C++20
326e8d8bef9SDimitry Andric    bool starts_with(charT c) const noexcept;                             // C++20
327e8d8bef9SDimitry Andric    bool starts_with(const charT* s) const;                               // C++20
328e8d8bef9SDimitry Andric    bool ends_with(basic_string_view<charT, traits> sv) const noexcept;   // C++20
329e8d8bef9SDimitry Andric    bool ends_with(charT c) const noexcept;                               // C++20
330e8d8bef9SDimitry Andric    bool ends_with(const charT* s) const;                                 // C++20
331e8d8bef9SDimitry Andric
332e8d8bef9SDimitry Andric    constexpr bool contains(basic_string_view<charT, traits> sv) const noexcept; // C++2b
333e8d8bef9SDimitry Andric    constexpr bool contains(charT c) const noexcept;                             // C++2b
334e8d8bef9SDimitry Andric    constexpr bool contains(const charT* s) const;                               // C++2b
3350b57cec5SDimitry Andric
3360b57cec5SDimitry Andric    bool __invariants() const;
3370b57cec5SDimitry Andric};
3380b57cec5SDimitry Andric
3390b57cec5SDimitry Andrictemplate<class InputIterator,
3400b57cec5SDimitry Andric         class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>>
3410b57cec5SDimitry Andricbasic_string(InputIterator, InputIterator, Allocator = Allocator())
3420b57cec5SDimitry Andric   -> basic_string<typename iterator_traits<InputIterator>::value_type,
3430b57cec5SDimitry Andric                  char_traits<typename iterator_traits<InputIterator>::value_type>,
3440b57cec5SDimitry Andric                  Allocator>;   // C++17
3450b57cec5SDimitry Andric
3460b57cec5SDimitry Andrictemplate<class charT, class traits, class Allocator>
3470b57cec5SDimitry Andricbasic_string<charT, traits, Allocator>
3480b57cec5SDimitry Andricoperator+(const basic_string<charT, traits, Allocator>& lhs,
3490b57cec5SDimitry Andric          const basic_string<charT, traits, Allocator>& rhs);
3500b57cec5SDimitry Andric
3510b57cec5SDimitry Andrictemplate<class charT, class traits, class Allocator>
3520b57cec5SDimitry Andricbasic_string<charT, traits, Allocator>
3530b57cec5SDimitry Andricoperator+(const charT* lhs , const basic_string<charT,traits,Allocator>&rhs);
3540b57cec5SDimitry Andric
3550b57cec5SDimitry Andrictemplate<class charT, class traits, class Allocator>
3560b57cec5SDimitry Andricbasic_string<charT, traits, Allocator>
3570b57cec5SDimitry Andricoperator+(charT lhs, const basic_string<charT,traits,Allocator>& rhs);
3580b57cec5SDimitry Andric
3590b57cec5SDimitry Andrictemplate<class charT, class traits, class Allocator>
3600b57cec5SDimitry Andricbasic_string<charT, traits, Allocator>
3610b57cec5SDimitry Andricoperator+(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs);
3620b57cec5SDimitry Andric
3630b57cec5SDimitry Andrictemplate<class charT, class traits, class Allocator>
3640b57cec5SDimitry Andricbasic_string<charT, traits, Allocator>
3650b57cec5SDimitry Andricoperator+(const basic_string<charT, traits, Allocator>& lhs, charT rhs);
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 charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
3830b57cec5SDimitry Andric
3840b57cec5SDimitry Andrictemplate<class charT, class traits, class Allocator>
3850b57cec5SDimitry Andricbool operator!=(const basic_string<charT, traits, Allocator>& lhs, const charT* 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 Andricbool operator>=(const basic_string<charT, traits, Allocator>& lhs,
4190b57cec5SDimitry Andric                const basic_string<charT, traits, Allocator>& rhs) noexcept;
4200b57cec5SDimitry Andric
4210b57cec5SDimitry Andrictemplate<class charT, class traits, class Allocator>
4220b57cec5SDimitry Andricbool operator>=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
4230b57cec5SDimitry Andric
4240b57cec5SDimitry Andrictemplate<class charT, class traits, class Allocator>
4250b57cec5SDimitry Andricbool operator>=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
4260b57cec5SDimitry Andric
4270b57cec5SDimitry Andrictemplate<class charT, class traits, class Allocator>
4280b57cec5SDimitry Andricvoid swap(basic_string<charT, traits, Allocator>& lhs,
4290b57cec5SDimitry Andric          basic_string<charT, traits, Allocator>& rhs)
4300b57cec5SDimitry Andric            noexcept(noexcept(lhs.swap(rhs)));
4310b57cec5SDimitry Andric
4320b57cec5SDimitry Andrictemplate<class charT, class traits, class Allocator>
4330b57cec5SDimitry Andricbasic_istream<charT, traits>&
4340b57cec5SDimitry Andricoperator>>(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str);
4350b57cec5SDimitry Andric
4360b57cec5SDimitry Andrictemplate<class charT, class traits, class Allocator>
4370b57cec5SDimitry Andricbasic_ostream<charT, traits>&
4380b57cec5SDimitry Andricoperator<<(basic_ostream<charT, traits>& os, const basic_string<charT, traits, Allocator>& str);
4390b57cec5SDimitry Andric
4400b57cec5SDimitry Andrictemplate<class charT, class traits, class Allocator>
4410b57cec5SDimitry Andricbasic_istream<charT, traits>&
4420b57cec5SDimitry Andricgetline(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str,
4430b57cec5SDimitry Andric        charT delim);
4440b57cec5SDimitry Andric
4450b57cec5SDimitry Andrictemplate<class charT, class traits, class Allocator>
4460b57cec5SDimitry Andricbasic_istream<charT, traits>&
4470b57cec5SDimitry Andricgetline(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str);
4480b57cec5SDimitry Andric
4490b57cec5SDimitry Andrictemplate<class charT, class traits, class Allocator, class U>
4505ffd83dbSDimitry Andrictypename basic_string<charT, traits, Allocator>::size_type
4515ffd83dbSDimitry Andricerase(basic_string<charT, traits, Allocator>& c, const U& value);    // C++20
4520b57cec5SDimitry Andrictemplate<class charT, class traits, class Allocator, class Predicate>
4535ffd83dbSDimitry Andrictypename basic_string<charT, traits, Allocator>::size_type
4545ffd83dbSDimitry Andricerase_if(basic_string<charT, traits, Allocator>& c, Predicate pred); // C++20
4550b57cec5SDimitry Andric
4560b57cec5SDimitry Andrictypedef basic_string<char>    string;
4570b57cec5SDimitry Andrictypedef basic_string<wchar_t> wstring;
458fe6060f1SDimitry Andrictypedef basic_string<char8_t> u8string; // C++20
4590b57cec5SDimitry Andrictypedef basic_string<char16_t> u16string;
4600b57cec5SDimitry Andrictypedef basic_string<char32_t> u32string;
4610b57cec5SDimitry Andric
462e8d8bef9SDimitry Andricint                stoi  (const string& str, size_t* idx = nullptr, int base = 10);
463e8d8bef9SDimitry Andriclong               stol  (const string& str, size_t* idx = nullptr, int base = 10);
464e8d8bef9SDimitry Andricunsigned long      stoul (const string& str, size_t* idx = nullptr, int base = 10);
465e8d8bef9SDimitry Andriclong long          stoll (const string& str, size_t* idx = nullptr, int base = 10);
466e8d8bef9SDimitry Andricunsigned long long stoull(const string& str, size_t* idx = nullptr, int base = 10);
4670b57cec5SDimitry Andric
468e8d8bef9SDimitry Andricfloat       stof (const string& str, size_t* idx = nullptr);
469e8d8bef9SDimitry Andricdouble      stod (const string& str, size_t* idx = nullptr);
470e8d8bef9SDimitry Andriclong double stold(const string& str, size_t* idx = nullptr);
4710b57cec5SDimitry Andric
4720b57cec5SDimitry Andricstring to_string(int val);
4730b57cec5SDimitry Andricstring to_string(unsigned val);
4740b57cec5SDimitry Andricstring to_string(long val);
4750b57cec5SDimitry Andricstring to_string(unsigned long val);
4760b57cec5SDimitry Andricstring to_string(long long val);
4770b57cec5SDimitry Andricstring to_string(unsigned long long val);
4780b57cec5SDimitry Andricstring to_string(float val);
4790b57cec5SDimitry Andricstring to_string(double val);
4800b57cec5SDimitry Andricstring to_string(long double val);
4810b57cec5SDimitry Andric
482e8d8bef9SDimitry Andricint                stoi  (const wstring& str, size_t* idx = nullptr, int base = 10);
483e8d8bef9SDimitry Andriclong               stol  (const wstring& str, size_t* idx = nullptr, int base = 10);
484e8d8bef9SDimitry Andricunsigned long      stoul (const wstring& str, size_t* idx = nullptr, int base = 10);
485e8d8bef9SDimitry Andriclong long          stoll (const wstring& str, size_t* idx = nullptr, int base = 10);
486e8d8bef9SDimitry Andricunsigned long long stoull(const wstring& str, size_t* idx = nullptr, int base = 10);
4870b57cec5SDimitry Andric
488e8d8bef9SDimitry Andricfloat       stof (const wstring& str, size_t* idx = nullptr);
489e8d8bef9SDimitry Andricdouble      stod (const wstring& str, size_t* idx = nullptr);
490e8d8bef9SDimitry Andriclong double stold(const wstring& str, size_t* idx = nullptr);
4910b57cec5SDimitry Andric
4920b57cec5SDimitry Andricwstring to_wstring(int val);
4930b57cec5SDimitry Andricwstring to_wstring(unsigned val);
4940b57cec5SDimitry Andricwstring to_wstring(long val);
4950b57cec5SDimitry Andricwstring to_wstring(unsigned long val);
4960b57cec5SDimitry Andricwstring to_wstring(long long val);
4970b57cec5SDimitry Andricwstring to_wstring(unsigned long long val);
4980b57cec5SDimitry Andricwstring to_wstring(float val);
4990b57cec5SDimitry Andricwstring to_wstring(double val);
5000b57cec5SDimitry Andricwstring to_wstring(long double val);
5010b57cec5SDimitry Andric
5020b57cec5SDimitry Andrictemplate <> struct hash<string>;
503fe6060f1SDimitry Andrictemplate <> struct hash<u8string>; // C++20
5040b57cec5SDimitry Andrictemplate <> struct hash<u16string>;
5050b57cec5SDimitry Andrictemplate <> struct hash<u32string>;
5060b57cec5SDimitry Andrictemplate <> struct hash<wstring>;
5070b57cec5SDimitry Andric
5080b57cec5SDimitry Andricbasic_string<char>     operator "" s( const char *str,     size_t len ); // C++14
5090b57cec5SDimitry Andricbasic_string<wchar_t>  operator "" s( const wchar_t *str,  size_t len ); // C++14
510fe6060f1SDimitry Andricbasic_string<char8_t>  operator "" s( const char8_t *str,  size_t len ); // C++20
5110b57cec5SDimitry Andricbasic_string<char16_t> operator "" s( const char16_t *str, size_t len ); // C++14
5120b57cec5SDimitry Andricbasic_string<char32_t> operator "" s( const char32_t *str, size_t len ); // C++14
5130b57cec5SDimitry Andric
5140b57cec5SDimitry Andric}  // std
5150b57cec5SDimitry Andric
5160b57cec5SDimitry Andric*/
5170b57cec5SDimitry Andric
5180b57cec5SDimitry Andric#include <__config>
519fe6060f1SDimitry Andric#include <__debug>
520fe6060f1SDimitry Andric#include <__functional_base>
521fe6060f1SDimitry Andric#include <__iterator/wrap_iter.h>
5220b57cec5SDimitry Andric#include <algorithm>
523fe6060f1SDimitry Andric#include <compare>
524fe6060f1SDimitry Andric#include <cstdio>  // EOF
52569ade1e0SDimitry Andric#include <cstdlib>
526fe6060f1SDimitry Andric#include <cstring>
527fe6060f1SDimitry Andric#include <initializer_list>
528fe6060f1SDimitry Andric#include <iosfwd>
5290b57cec5SDimitry Andric#include <iterator>
5300b57cec5SDimitry Andric#include <memory>
5310b57cec5SDimitry Andric#include <stdexcept>
532fe6060f1SDimitry Andric#include <string_view>
5330b57cec5SDimitry Andric#include <type_traits>
534fe6060f1SDimitry Andric#include <utility>
5350b57cec5SDimitry Andric#include <version>
536fe6060f1SDimitry Andric
537*349cc55cSDimitry Andric#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
538*349cc55cSDimitry Andric#   include <cwchar>
539*349cc55cSDimitry Andric#endif
540*349cc55cSDimitry Andric
5410b57cec5SDimitry Andric#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
5420b57cec5SDimitry Andric# include <cstdint>
5430b57cec5SDimitry Andric#endif
5440b57cec5SDimitry Andric
5450b57cec5SDimitry Andric#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
5460b57cec5SDimitry Andric#pragma GCC system_header
5470b57cec5SDimitry Andric#endif
5480b57cec5SDimitry Andric
5490b57cec5SDimitry Andric_LIBCPP_PUSH_MACROS
5500b57cec5SDimitry Andric#include <__undef_macros>
5510b57cec5SDimitry Andric
5520b57cec5SDimitry Andric
5530b57cec5SDimitry Andric_LIBCPP_BEGIN_NAMESPACE_STD
5540b57cec5SDimitry Andric
5550b57cec5SDimitry Andric// fpos
5560b57cec5SDimitry Andric
5570b57cec5SDimitry Andrictemplate <class _StateT>
5580b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS fpos
5590b57cec5SDimitry Andric{
5600b57cec5SDimitry Andricprivate:
5610b57cec5SDimitry Andric    _StateT __st_;
5620b57cec5SDimitry Andric    streamoff __off_;
5630b57cec5SDimitry Andricpublic:
5640b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY fpos(streamoff __off = streamoff()) : __st_(), __off_(__off) {}
5650b57cec5SDimitry Andric
5660b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY operator streamoff() const {return __off_;}
5670b57cec5SDimitry Andric
5680b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _StateT state() const {return __st_;}
5690b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY void state(_StateT __st) {__st_ = __st;}
5700b57cec5SDimitry Andric
5710b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY fpos& operator+=(streamoff __off) {__off_ += __off; return *this;}
5720b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY fpos  operator+ (streamoff __off) const {fpos __t(*this); __t += __off; return __t;}
5730b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY fpos& operator-=(streamoff __off) {__off_ -= __off; return *this;}
5740b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY fpos  operator- (streamoff __off) const {fpos __t(*this); __t -= __off; return __t;}
5750b57cec5SDimitry Andric};
5760b57cec5SDimitry Andric
5770b57cec5SDimitry Andrictemplate <class _StateT>
5780b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
5790b57cec5SDimitry Andricstreamoff operator-(const fpos<_StateT>& __x, const fpos<_StateT>& __y)
5800b57cec5SDimitry Andric    {return streamoff(__x) - streamoff(__y);}
5810b57cec5SDimitry Andric
5820b57cec5SDimitry Andrictemplate <class _StateT>
5830b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
5840b57cec5SDimitry Andricbool operator==(const fpos<_StateT>& __x, const fpos<_StateT>& __y)
5850b57cec5SDimitry Andric    {return streamoff(__x) == streamoff(__y);}
5860b57cec5SDimitry Andric
5870b57cec5SDimitry Andrictemplate <class _StateT>
5880b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
5890b57cec5SDimitry Andricbool operator!=(const fpos<_StateT>& __x, const fpos<_StateT>& __y)
5900b57cec5SDimitry Andric    {return streamoff(__x) != streamoff(__y);}
5910b57cec5SDimitry Andric
5920b57cec5SDimitry Andric// basic_string
5930b57cec5SDimitry Andric
5940b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
5950b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>
5960b57cec5SDimitry Andricoperator+(const basic_string<_CharT, _Traits, _Allocator>& __x,
5970b57cec5SDimitry Andric          const basic_string<_CharT, _Traits, _Allocator>& __y);
5980b57cec5SDimitry Andric
5990b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
6000b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>
6010b57cec5SDimitry Andricoperator+(const _CharT* __x, const basic_string<_CharT,_Traits,_Allocator>& __y);
6020b57cec5SDimitry Andric
6030b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
6040b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>
6050b57cec5SDimitry Andricoperator+(_CharT __x, const basic_string<_CharT,_Traits,_Allocator>& __y);
6060b57cec5SDimitry Andric
6070b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
6080b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
6090b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>
6100b57cec5SDimitry Andricoperator+(const basic_string<_CharT, _Traits, _Allocator>& __x, const _CharT* __y);
6110b57cec5SDimitry Andric
6120b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
6130b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>
6140b57cec5SDimitry Andricoperator+(const basic_string<_CharT, _Traits, _Allocator>& __x, _CharT __y);
6150b57cec5SDimitry Andric
6160b57cec5SDimitry Andric_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS string operator+<char, char_traits<char>, allocator<char> >(char const*, string const&))
6170b57cec5SDimitry Andric
6180b57cec5SDimitry Andrictemplate <bool>
619*349cc55cSDimitry Andricstruct __basic_string_common;
620*349cc55cSDimitry Andric
621*349cc55cSDimitry Andrictemplate <>
622*349cc55cSDimitry Andricstruct __basic_string_common<true> {
623*349cc55cSDimitry Andric    // Both are defined in string.cpp
624*349cc55cSDimitry Andric    _LIBCPP_NORETURN _LIBCPP_EXPORTED_FROM_ABI void __throw_length_error() const;
625*349cc55cSDimitry Andric    _LIBCPP_NORETURN _LIBCPP_EXPORTED_FROM_ABI void __throw_out_of_range() const;
6260b57cec5SDimitry Andric};
6270b57cec5SDimitry Andric
6280b57cec5SDimitry Andrictemplate <class _Iter>
629fe6060f1SDimitry Andricstruct __string_is_trivial_iterator : public false_type {};
630fe6060f1SDimitry Andric
631fe6060f1SDimitry Andrictemplate <class _Tp>
632fe6060f1SDimitry Andricstruct __string_is_trivial_iterator<_Tp*>
633fe6060f1SDimitry Andric    : public is_arithmetic<_Tp> {};
6340b57cec5SDimitry Andric
6350b57cec5SDimitry Andrictemplate <class _Iter>
636fe6060f1SDimitry Andricstruct __string_is_trivial_iterator<__wrap_iter<_Iter> >
637fe6060f1SDimitry Andric    : public __string_is_trivial_iterator<_Iter> {};
6380b57cec5SDimitry Andric
6390b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Tp>
6405ffd83dbSDimitry Andricstruct __can_be_converted_to_string_view : public _BoolConstant<
6415ffd83dbSDimitry Andric      is_convertible<const _Tp&, basic_string_view<_CharT, _Traits> >::value &&
6425ffd83dbSDimitry Andric     !is_convertible<const _Tp&, const _CharT*>::value
6435ffd83dbSDimitry Andric    > {};
6440b57cec5SDimitry Andric
6450b57cec5SDimitry Andric#ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
6460b57cec5SDimitry Andric
6470b57cec5SDimitry Andrictemplate <class _CharT, size_t = sizeof(_CharT)>
6480b57cec5SDimitry Andricstruct __padding
6490b57cec5SDimitry Andric{
6500b57cec5SDimitry Andric    unsigned char __xx[sizeof(_CharT)-1];
6510b57cec5SDimitry Andric};
6520b57cec5SDimitry Andric
6530b57cec5SDimitry Andrictemplate <class _CharT>
6540b57cec5SDimitry Andricstruct __padding<_CharT, 1>
6550b57cec5SDimitry Andric{
6560b57cec5SDimitry Andric};
6570b57cec5SDimitry Andric
6580b57cec5SDimitry Andric#endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
6590b57cec5SDimitry Andric
660fe6060f1SDimitry Andric#ifndef _LIBCPP_HAS_NO_CHAR8_T
661e8d8bef9SDimitry Andrictypedef basic_string<char8_t> u8string;
662e8d8bef9SDimitry Andric#endif
663e8d8bef9SDimitry Andric
664e8d8bef9SDimitry Andric#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
665e8d8bef9SDimitry Andrictypedef basic_string<char16_t> u16string;
666e8d8bef9SDimitry Andrictypedef basic_string<char32_t> u32string;
667*349cc55cSDimitry Andric#endif
668e8d8bef9SDimitry Andric
6690b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
670e8d8bef9SDimitry Andricclass
671e8d8bef9SDimitry Andric    _LIBCPP_TEMPLATE_VIS
672fe6060f1SDimitry Andric#ifndef _LIBCPP_HAS_NO_CHAR8_T
673e8d8bef9SDimitry Andric    _LIBCPP_PREFERRED_NAME(u8string)
674e8d8bef9SDimitry Andric#endif
675e8d8bef9SDimitry Andric#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
676e8d8bef9SDimitry Andric    _LIBCPP_PREFERRED_NAME(u16string)
677e8d8bef9SDimitry Andric    _LIBCPP_PREFERRED_NAME(u32string)
678e8d8bef9SDimitry Andric#endif
679e8d8bef9SDimitry Andric    basic_string
680*349cc55cSDimitry Andric    : private __basic_string_common<true> // This base class is historical, but it needs to remain for ABI compatibility
6810b57cec5SDimitry Andric{
6820b57cec5SDimitry Andricpublic:
6830b57cec5SDimitry Andric    typedef basic_string                                 __self;
6840b57cec5SDimitry Andric    typedef basic_string_view<_CharT, _Traits>           __self_view;
6850b57cec5SDimitry Andric    typedef _Traits                                      traits_type;
6860b57cec5SDimitry Andric    typedef _CharT                                       value_type;
6870b57cec5SDimitry Andric    typedef _Allocator                                   allocator_type;
6880b57cec5SDimitry Andric    typedef allocator_traits<allocator_type>             __alloc_traits;
6890b57cec5SDimitry Andric    typedef typename __alloc_traits::size_type           size_type;
6900b57cec5SDimitry Andric    typedef typename __alloc_traits::difference_type     difference_type;
6910b57cec5SDimitry Andric    typedef value_type&                                  reference;
6920b57cec5SDimitry Andric    typedef const value_type&                            const_reference;
6930b57cec5SDimitry Andric    typedef typename __alloc_traits::pointer             pointer;
6940b57cec5SDimitry Andric    typedef typename __alloc_traits::const_pointer       const_pointer;
6950b57cec5SDimitry Andric
6960b57cec5SDimitry Andric    static_assert((!is_array<value_type>::value), "Character type of basic_string must not be an array");
6970b57cec5SDimitry Andric    static_assert(( is_standard_layout<value_type>::value), "Character type of basic_string must be standard-layout");
6980b57cec5SDimitry Andric    static_assert(( is_trivial<value_type>::value), "Character type of basic_string must be trivial");
6990b57cec5SDimitry Andric    static_assert(( is_same<_CharT, typename traits_type::char_type>::value),
7000b57cec5SDimitry Andric                  "traits_type::char_type must be the same type as CharT");
7010b57cec5SDimitry Andric    static_assert(( is_same<typename allocator_type::value_type, value_type>::value),
7020b57cec5SDimitry Andric                  "Allocator::value_type must be same type as value_type");
7030b57cec5SDimitry Andric
7040b57cec5SDimitry Andric    typedef __wrap_iter<pointer>                         iterator;
7050b57cec5SDimitry Andric    typedef __wrap_iter<const_pointer>                   const_iterator;
7060b57cec5SDimitry Andric    typedef _VSTD::reverse_iterator<iterator>             reverse_iterator;
7070b57cec5SDimitry Andric    typedef _VSTD::reverse_iterator<const_iterator>       const_reverse_iterator;
7080b57cec5SDimitry Andric
7090b57cec5SDimitry Andricprivate:
7100b57cec5SDimitry Andric
7110b57cec5SDimitry Andric#ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
7120b57cec5SDimitry Andric
7130b57cec5SDimitry Andric    struct __long
7140b57cec5SDimitry Andric    {
7150b57cec5SDimitry Andric        pointer   __data_;
7160b57cec5SDimitry Andric        size_type __size_;
7170b57cec5SDimitry Andric        size_type __cap_;
7180b57cec5SDimitry Andric    };
7190b57cec5SDimitry Andric
7200b57cec5SDimitry Andric#ifdef _LIBCPP_BIG_ENDIAN
7210b57cec5SDimitry Andric    static const size_type __short_mask = 0x01;
7220b57cec5SDimitry Andric    static const size_type __long_mask  = 0x1ul;
7230b57cec5SDimitry Andric#else  // _LIBCPP_BIG_ENDIAN
7240b57cec5SDimitry Andric    static const size_type __short_mask = 0x80;
7250b57cec5SDimitry Andric    static const size_type __long_mask  = ~(size_type(~0) >> 1);
7260b57cec5SDimitry Andric#endif // _LIBCPP_BIG_ENDIAN
7270b57cec5SDimitry Andric
7280b57cec5SDimitry Andric    enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ?
7290b57cec5SDimitry Andric                      (sizeof(__long) - 1)/sizeof(value_type) : 2};
7300b57cec5SDimitry Andric
7310b57cec5SDimitry Andric    struct __short
7320b57cec5SDimitry Andric    {
7330b57cec5SDimitry Andric        value_type __data_[__min_cap];
7340b57cec5SDimitry Andric        struct
7350b57cec5SDimitry Andric            : __padding<value_type>
7360b57cec5SDimitry Andric        {
7370b57cec5SDimitry Andric            unsigned char __size_;
7380b57cec5SDimitry Andric        };
7390b57cec5SDimitry Andric    };
7400b57cec5SDimitry Andric
7410b57cec5SDimitry Andric#else
7420b57cec5SDimitry Andric
7430b57cec5SDimitry Andric    struct __long
7440b57cec5SDimitry Andric    {
7450b57cec5SDimitry Andric        size_type __cap_;
7460b57cec5SDimitry Andric        size_type __size_;
7470b57cec5SDimitry Andric        pointer   __data_;
7480b57cec5SDimitry Andric    };
7490b57cec5SDimitry Andric
7500b57cec5SDimitry Andric#ifdef _LIBCPP_BIG_ENDIAN
7510b57cec5SDimitry Andric    static const size_type __short_mask = 0x80;
7520b57cec5SDimitry Andric    static const size_type __long_mask  = ~(size_type(~0) >> 1);
7530b57cec5SDimitry Andric#else  // _LIBCPP_BIG_ENDIAN
7540b57cec5SDimitry Andric    static const size_type __short_mask = 0x01;
7550b57cec5SDimitry Andric    static const size_type __long_mask  = 0x1ul;
7560b57cec5SDimitry Andric#endif // _LIBCPP_BIG_ENDIAN
7570b57cec5SDimitry Andric
7580b57cec5SDimitry Andric    enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ?
7590b57cec5SDimitry Andric                      (sizeof(__long) - 1)/sizeof(value_type) : 2};
7600b57cec5SDimitry Andric
7610b57cec5SDimitry Andric    struct __short
7620b57cec5SDimitry Andric    {
7630b57cec5SDimitry Andric        union
7640b57cec5SDimitry Andric        {
7650b57cec5SDimitry Andric            unsigned char __size_;
7660b57cec5SDimitry Andric            value_type __lx;
7670b57cec5SDimitry Andric        };
7680b57cec5SDimitry Andric        value_type __data_[__min_cap];
7690b57cec5SDimitry Andric    };
7700b57cec5SDimitry Andric
7710b57cec5SDimitry Andric#endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
7720b57cec5SDimitry Andric
7730b57cec5SDimitry Andric    union __ulx{__long __lx; __short __lxx;};
7740b57cec5SDimitry Andric
7750b57cec5SDimitry Andric    enum {__n_words = sizeof(__ulx) / sizeof(size_type)};
7760b57cec5SDimitry Andric
7770b57cec5SDimitry Andric    struct __raw
7780b57cec5SDimitry Andric    {
7790b57cec5SDimitry Andric        size_type __words[__n_words];
7800b57cec5SDimitry Andric    };
7810b57cec5SDimitry Andric
7820b57cec5SDimitry Andric    struct __rep
7830b57cec5SDimitry Andric    {
7840b57cec5SDimitry Andric        union
7850b57cec5SDimitry Andric        {
7860b57cec5SDimitry Andric            __long  __l;
7870b57cec5SDimitry Andric            __short __s;
7880b57cec5SDimitry Andric            __raw   __r;
7890b57cec5SDimitry Andric        };
7900b57cec5SDimitry Andric    };
7910b57cec5SDimitry Andric
7920b57cec5SDimitry Andric    __compressed_pair<__rep, allocator_type> __r_;
7930b57cec5SDimitry Andric
7940b57cec5SDimitry Andricpublic:
795fe6060f1SDimitry Andric    _LIBCPP_TEMPLATE_DATA_VIS
7960b57cec5SDimitry Andric    static const size_type npos = -1;
7970b57cec5SDimitry Andric
7980b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY basic_string()
7990b57cec5SDimitry Andric        _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value);
8000b57cec5SDimitry Andric
8010b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY explicit basic_string(const allocator_type& __a)
8020b57cec5SDimitry Andric#if _LIBCPP_STD_VER <= 14
8030b57cec5SDimitry Andric        _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value);
8040b57cec5SDimitry Andric#else
8050b57cec5SDimitry Andric        _NOEXCEPT;
8060b57cec5SDimitry Andric#endif
8070b57cec5SDimitry Andric
8080b57cec5SDimitry Andric    basic_string(const basic_string& __str);
8090b57cec5SDimitry Andric    basic_string(const basic_string& __str, const allocator_type& __a);
8100b57cec5SDimitry Andric
8110b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
8120b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
8130b57cec5SDimitry Andric    basic_string(basic_string&& __str)
8140b57cec5SDimitry Andric#if _LIBCPP_STD_VER <= 14
8150b57cec5SDimitry Andric        _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
8160b57cec5SDimitry Andric#else
8170b57cec5SDimitry Andric        _NOEXCEPT;
8180b57cec5SDimitry Andric#endif
8190b57cec5SDimitry Andric
8200b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
8210b57cec5SDimitry Andric    basic_string(basic_string&& __str, const allocator_type& __a);
8220b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG
8230b57cec5SDimitry Andric
824*349cc55cSDimitry Andric    template <class = __enable_if_t<__is_allocator<_Allocator>::value, nullptr_t> >
8250b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
826480093f4SDimitry Andric    basic_string(const _CharT* __s) : __r_(__default_init_tag(), __default_init_tag()) {
8270b57cec5SDimitry Andric      _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*) detected nullptr");
8280b57cec5SDimitry Andric      __init(__s, traits_type::length(__s));
829e8d8bef9SDimitry Andric#   if _LIBCPP_DEBUG_LEVEL == 2
8300b57cec5SDimitry Andric      __get_db()->__insert_c(this);
8310b57cec5SDimitry Andric#   endif
8320b57cec5SDimitry Andric    }
8330b57cec5SDimitry Andric
834*349cc55cSDimitry Andric    template <class = __enable_if_t<__is_allocator<_Allocator>::value, nullptr_t> >
8350b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY
8360b57cec5SDimitry Andric        basic_string(const _CharT* __s, const _Allocator& __a);
8370b57cec5SDimitry Andric
838fe6060f1SDimitry Andric#if _LIBCPP_STD_VER > 20
839fe6060f1SDimitry Andric    basic_string(nullptr_t) = delete;
840fe6060f1SDimitry Andric#endif
841fe6060f1SDimitry Andric
8420b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
8430b57cec5SDimitry Andric    basic_string(const _CharT* __s, size_type __n);
8440b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
8450b57cec5SDimitry Andric    basic_string(const _CharT* __s, size_type __n, const _Allocator& __a);
8460b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
8470b57cec5SDimitry Andric    basic_string(size_type __n, _CharT __c);
8480b57cec5SDimitry Andric
849*349cc55cSDimitry Andric    template <class = __enable_if_t<__is_allocator<_Allocator>::value, nullptr_t> >
8500b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY
8510b57cec5SDimitry Andric        basic_string(size_type __n, _CharT __c, const _Allocator& __a);
8520b57cec5SDimitry Andric
8530b57cec5SDimitry Andric    basic_string(const basic_string& __str, size_type __pos, size_type __n,
8540b57cec5SDimitry Andric                 const _Allocator& __a = _Allocator());
8550b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
8560b57cec5SDimitry Andric    basic_string(const basic_string& __str, size_type __pos,
8570b57cec5SDimitry Andric                 const _Allocator& __a = _Allocator());
8580b57cec5SDimitry Andric
859*349cc55cSDimitry Andric    template<class _Tp, class = __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && !__is_same_uncvref<_Tp, basic_string>::value> >
8600b57cec5SDimitry Andric        _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
8610b57cec5SDimitry Andric        basic_string(const _Tp& __t, size_type __pos, size_type __n,
8620b57cec5SDimitry Andric                     const allocator_type& __a = allocator_type());
8630b57cec5SDimitry Andric
864*349cc55cSDimitry Andric    template<class _Tp, class = __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value &&
8655ffd83dbSDimitry Andric                                          !__is_same_uncvref<_Tp, basic_string>::value> >
8660b57cec5SDimitry Andric        _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
8670b57cec5SDimitry Andric        explicit basic_string(const _Tp& __t);
8680b57cec5SDimitry Andric
869*349cc55cSDimitry Andric    template<class _Tp, class = __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && !__is_same_uncvref<_Tp, basic_string>::value> >
8700b57cec5SDimitry Andric        _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
8710b57cec5SDimitry Andric        explicit basic_string(const _Tp& __t, const allocator_type& __a);
8720b57cec5SDimitry Andric
873*349cc55cSDimitry Andric    template<class _InputIterator, class = __enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value> >
8740b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY
8750b57cec5SDimitry Andric        basic_string(_InputIterator __first, _InputIterator __last);
876*349cc55cSDimitry Andric    template<class _InputIterator, class = __enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value> >
8770b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY
8780b57cec5SDimitry Andric        basic_string(_InputIterator __first, _InputIterator __last, const allocator_type& __a);
8790b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
8800b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
8810b57cec5SDimitry Andric    basic_string(initializer_list<_CharT> __il);
8820b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
8830b57cec5SDimitry Andric    basic_string(initializer_list<_CharT> __il, const _Allocator& __a);
8840b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG
8850b57cec5SDimitry Andric
8860b57cec5SDimitry Andric    inline ~basic_string();
8870b57cec5SDimitry Andric
8880b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
8890b57cec5SDimitry Andric    operator __self_view() const _NOEXCEPT { return __self_view(data(), size()); }
8900b57cec5SDimitry Andric
8910b57cec5SDimitry Andric    basic_string& operator=(const basic_string& __str);
8920b57cec5SDimitry Andric
893*349cc55cSDimitry Andric    template <class _Tp, class = __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && !__is_same_uncvref<_Tp, basic_string>::value> >
8940b57cec5SDimitry Andric    basic_string& operator=(const _Tp& __t)
8950b57cec5SDimitry Andric        {__self_view __sv = __t; return assign(__sv);}
8960b57cec5SDimitry Andric
8970b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
8980b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
8990b57cec5SDimitry Andric    basic_string& operator=(basic_string&& __str)
9000b57cec5SDimitry Andric        _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value));
9010b57cec5SDimitry Andric     _LIBCPP_INLINE_VISIBILITY
9020b57cec5SDimitry Andric    basic_string& operator=(initializer_list<value_type> __il) {return assign(__il.begin(), __il.size());}
9030b57cec5SDimitry Andric#endif
9040b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY basic_string& operator=(const value_type* __s) {return assign(__s);}
905fe6060f1SDimitry Andric#if _LIBCPP_STD_VER > 20
906fe6060f1SDimitry Andric    basic_string& operator=(nullptr_t) = delete;
907fe6060f1SDimitry Andric#endif
9080b57cec5SDimitry Andric    basic_string& operator=(value_type __c);
9090b57cec5SDimitry Andric
910e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2
9110b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
9120b57cec5SDimitry Andric    iterator begin() _NOEXCEPT
9130b57cec5SDimitry Andric        {return iterator(this, __get_pointer());}
9140b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
9150b57cec5SDimitry Andric    const_iterator begin() const _NOEXCEPT
9160b57cec5SDimitry Andric        {return const_iterator(this, __get_pointer());}
9170b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
9180b57cec5SDimitry Andric    iterator end() _NOEXCEPT
9190b57cec5SDimitry Andric        {return iterator(this, __get_pointer() + size());}
9200b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
9210b57cec5SDimitry Andric    const_iterator end() const _NOEXCEPT
9220b57cec5SDimitry Andric        {return const_iterator(this, __get_pointer() + size());}
9230b57cec5SDimitry Andric#else
9240b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
9250b57cec5SDimitry Andric    iterator begin() _NOEXCEPT
9260b57cec5SDimitry Andric        {return iterator(__get_pointer());}
9270b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
9280b57cec5SDimitry Andric    const_iterator begin() const _NOEXCEPT
9290b57cec5SDimitry Andric        {return const_iterator(__get_pointer());}
9300b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
9310b57cec5SDimitry Andric    iterator end() _NOEXCEPT
9320b57cec5SDimitry Andric        {return iterator(__get_pointer() + size());}
9330b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
9340b57cec5SDimitry Andric    const_iterator end() const _NOEXCEPT
9350b57cec5SDimitry Andric        {return const_iterator(__get_pointer() + size());}
936e8d8bef9SDimitry Andric#endif // _LIBCPP_DEBUG_LEVEL == 2
9370b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
9380b57cec5SDimitry Andric    reverse_iterator rbegin() _NOEXCEPT
9390b57cec5SDimitry Andric        {return reverse_iterator(end());}
9400b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
9410b57cec5SDimitry Andric    const_reverse_iterator rbegin() const _NOEXCEPT
9420b57cec5SDimitry Andric        {return const_reverse_iterator(end());}
9430b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
9440b57cec5SDimitry Andric    reverse_iterator rend() _NOEXCEPT
9450b57cec5SDimitry Andric        {return reverse_iterator(begin());}
9460b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
9470b57cec5SDimitry Andric    const_reverse_iterator rend() const _NOEXCEPT
9480b57cec5SDimitry Andric        {return const_reverse_iterator(begin());}
9490b57cec5SDimitry Andric
9500b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
9510b57cec5SDimitry Andric    const_iterator cbegin() const _NOEXCEPT
9520b57cec5SDimitry Andric        {return begin();}
9530b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
9540b57cec5SDimitry Andric    const_iterator cend() const _NOEXCEPT
9550b57cec5SDimitry Andric        {return end();}
9560b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
9570b57cec5SDimitry Andric    const_reverse_iterator crbegin() const _NOEXCEPT
9580b57cec5SDimitry Andric        {return rbegin();}
9590b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
9600b57cec5SDimitry Andric    const_reverse_iterator crend() const _NOEXCEPT
9610b57cec5SDimitry Andric        {return rend();}
9620b57cec5SDimitry Andric
9630b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY size_type size() const _NOEXCEPT
9640b57cec5SDimitry Andric        {return __is_long() ? __get_long_size() : __get_short_size();}
9650b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY size_type length() const _NOEXCEPT {return size();}
9660b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT;
9670b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY size_type capacity() const _NOEXCEPT
9680b57cec5SDimitry Andric        {return (__is_long() ? __get_long_cap()
9690b57cec5SDimitry Andric                             : static_cast<size_type>(__min_cap)) - 1;}
9700b57cec5SDimitry Andric
9710b57cec5SDimitry Andric    void resize(size_type __n, value_type __c);
9720b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY void resize(size_type __n) {resize(__n, value_type());}
9730b57cec5SDimitry Andric
974e8d8bef9SDimitry Andric    void reserve(size_type __requested_capacity);
9750b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY void __resize_default_init(size_type __n);
9760b57cec5SDimitry Andric
977e8d8bef9SDimitry Andric    _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_INLINE_VISIBILITY
978e8d8bef9SDimitry Andric    void reserve() _NOEXCEPT {shrink_to_fit();}
9790b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
980e8d8bef9SDimitry Andric    void shrink_to_fit() _NOEXCEPT;
9810b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
9820b57cec5SDimitry Andric    void clear() _NOEXCEPT;
9830b57cec5SDimitry Andric    _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
9840b57cec5SDimitry Andric    bool empty() const _NOEXCEPT {return size() == 0;}
9850b57cec5SDimitry Andric
9860b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __pos) const _NOEXCEPT;
9870b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY reference       operator[](size_type __pos)       _NOEXCEPT;
9880b57cec5SDimitry Andric
9890b57cec5SDimitry Andric    const_reference at(size_type __n) const;
9900b57cec5SDimitry Andric    reference       at(size_type __n);
9910b57cec5SDimitry Andric
9920b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(const basic_string& __str) {return append(__str);}
9930b57cec5SDimitry Andric
9940b57cec5SDimitry Andric    template <class _Tp>
9950b57cec5SDimitry Andric    _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
996*349cc55cSDimitry Andric    __enable_if_t
9970b57cec5SDimitry Andric        <
9985ffd83dbSDimitry Andric            __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value
9995ffd83dbSDimitry Andric            && !__is_same_uncvref<_Tp, basic_string >::value,
10000b57cec5SDimitry Andric            basic_string&
10015ffd83dbSDimitry Andric        >
10020b57cec5SDimitry Andric                                            operator+=(const _Tp& __t)            {__self_view __sv = __t; return append(__sv);}
10030b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(const value_type* __s)     {return append(__s);}
10040b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(value_type __c)            {push_back(__c); return *this;}
10050b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
10060b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(initializer_list<value_type> __il) {return append(__il);}
10070b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG
10080b57cec5SDimitry Andric
10090b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
10100b57cec5SDimitry Andric    basic_string& append(const basic_string& __str);
10110b57cec5SDimitry Andric
10120b57cec5SDimitry Andric    template <class _Tp>
10130b57cec5SDimitry Andric    _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1014*349cc55cSDimitry Andric    __enable_if_t<
10155ffd83dbSDimitry Andric            __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value
10165ffd83dbSDimitry Andric            && !__is_same_uncvref<_Tp, basic_string>::value,
10170b57cec5SDimitry Andric            basic_string&
10185ffd83dbSDimitry Andric        >
10190b57cec5SDimitry Andric                  append(const _Tp& __t) { __self_view __sv = __t; return append(__sv.data(), __sv.size()); }
10200b57cec5SDimitry Andric    basic_string& append(const basic_string& __str, size_type __pos, size_type __n=npos);
10210b57cec5SDimitry Andric
10220b57cec5SDimitry Andric    template <class _Tp>
10230b57cec5SDimitry Andric    _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1024*349cc55cSDimitry Andric    __enable_if_t
10250b57cec5SDimitry Andric        <
10265ffd83dbSDimitry Andric            __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value
10275ffd83dbSDimitry Andric            && !__is_same_uncvref<_Tp, basic_string>::value,
10280b57cec5SDimitry Andric            basic_string&
10295ffd83dbSDimitry Andric        >
10300b57cec5SDimitry Andric                  append(const _Tp& __t, size_type __pos, size_type __n=npos);
10310b57cec5SDimitry Andric    basic_string& append(const value_type* __s, size_type __n);
10320b57cec5SDimitry Andric    basic_string& append(const value_type* __s);
10330b57cec5SDimitry Andric    basic_string& append(size_type __n, value_type __c);
10340b57cec5SDimitry Andric
10350b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
10360b57cec5SDimitry Andric    void __append_default_init(size_type __n);
10370b57cec5SDimitry Andric
10380b57cec5SDimitry Andric    template<class _InputIterator>
10390b57cec5SDimitry Andric    _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1040*349cc55cSDimitry Andric    __enable_if_t
10410b57cec5SDimitry Andric        <
1042fe6060f1SDimitry Andric            __is_exactly_cpp17_input_iterator<_InputIterator>::value,
10430b57cec5SDimitry Andric            basic_string&
10445ffd83dbSDimitry Andric        >
10450b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
10460b57cec5SDimitry Andric    append(_InputIterator __first, _InputIterator __last) {
10470b57cec5SDimitry Andric      const basic_string __temp(__first, __last, __alloc());
10480b57cec5SDimitry Andric      append(__temp.data(), __temp.size());
10490b57cec5SDimitry Andric      return *this;
10500b57cec5SDimitry Andric    }
10510b57cec5SDimitry Andric    template<class _ForwardIterator>
10520b57cec5SDimitry Andric    _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1053*349cc55cSDimitry Andric    __enable_if_t
10540b57cec5SDimitry Andric        <
1055fe6060f1SDimitry Andric            __is_cpp17_forward_iterator<_ForwardIterator>::value,
10560b57cec5SDimitry Andric            basic_string&
10575ffd83dbSDimitry Andric        >
10580b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
1059fe6060f1SDimitry Andric    append(_ForwardIterator __first, _ForwardIterator __last);
10600b57cec5SDimitry Andric
10610b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
10620b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
10630b57cec5SDimitry Andric    basic_string& append(initializer_list<value_type> __il) {return append(__il.begin(), __il.size());}
10640b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG
10650b57cec5SDimitry Andric
10660b57cec5SDimitry Andric    void push_back(value_type __c);
10670b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
10680b57cec5SDimitry Andric    void pop_back();
10690b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY reference       front() _NOEXCEPT;
10700b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY const_reference front() const _NOEXCEPT;
10710b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY reference       back() _NOEXCEPT;
10720b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY const_reference back() const _NOEXCEPT;
10730b57cec5SDimitry Andric
10740b57cec5SDimitry Andric    template <class _Tp>
10750b57cec5SDimitry Andric    _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1076*349cc55cSDimitry Andric    __enable_if_t
10770b57cec5SDimitry Andric        <
10780b57cec5SDimitry Andric            __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
10790b57cec5SDimitry Andric            basic_string&
10805ffd83dbSDimitry Andric        >
10810b57cec5SDimitry Andric                 assign(const _Tp & __t) { __self_view __sv = __t; return assign(__sv.data(), __sv.size()); }
10820b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
10830b57cec5SDimitry Andric    basic_string& assign(const basic_string& __str) { return *this = __str; }
10840b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
10850b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
10860b57cec5SDimitry Andric    basic_string& assign(basic_string&& __str)
10870b57cec5SDimitry Andric        _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value))
10880b57cec5SDimitry Andric        {*this = _VSTD::move(__str); return *this;}
10890b57cec5SDimitry Andric#endif
10900b57cec5SDimitry Andric    basic_string& assign(const basic_string& __str, size_type __pos, size_type __n=npos);
10910b57cec5SDimitry Andric    template <class _Tp>
10920b57cec5SDimitry Andric    _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1093*349cc55cSDimitry Andric    __enable_if_t
10940b57cec5SDimitry Andric        <
10955ffd83dbSDimitry Andric            __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value
10965ffd83dbSDimitry Andric            && !__is_same_uncvref<_Tp, basic_string>::value,
10970b57cec5SDimitry Andric            basic_string&
10985ffd83dbSDimitry Andric        >
10990b57cec5SDimitry Andric                  assign(const _Tp & __t, size_type __pos, size_type __n=npos);
11000b57cec5SDimitry Andric    basic_string& assign(const value_type* __s, size_type __n);
11010b57cec5SDimitry Andric    basic_string& assign(const value_type* __s);
11020b57cec5SDimitry Andric    basic_string& assign(size_type __n, value_type __c);
11030b57cec5SDimitry Andric    template<class _InputIterator>
11040b57cec5SDimitry Andric    _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1105*349cc55cSDimitry Andric    __enable_if_t
11060b57cec5SDimitry Andric        <
1107fe6060f1SDimitry Andric            __is_exactly_cpp17_input_iterator<_InputIterator>::value,
11080b57cec5SDimitry Andric            basic_string&
11095ffd83dbSDimitry Andric        >
11100b57cec5SDimitry Andric        assign(_InputIterator __first, _InputIterator __last);
11110b57cec5SDimitry Andric    template<class _ForwardIterator>
11120b57cec5SDimitry Andric    _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1113*349cc55cSDimitry Andric    __enable_if_t
11140b57cec5SDimitry Andric        <
1115fe6060f1SDimitry Andric            __is_cpp17_forward_iterator<_ForwardIterator>::value,
11160b57cec5SDimitry Andric            basic_string&
11175ffd83dbSDimitry Andric        >
11180b57cec5SDimitry Andric        assign(_ForwardIterator __first, _ForwardIterator __last);
11190b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
11200b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
11210b57cec5SDimitry Andric    basic_string& assign(initializer_list<value_type> __il) {return assign(__il.begin(), __il.size());}
11220b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG
11230b57cec5SDimitry Andric
11240b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
11250b57cec5SDimitry Andric    basic_string& insert(size_type __pos1, const basic_string& __str);
11260b57cec5SDimitry Andric
11270b57cec5SDimitry Andric    template <class _Tp>
11280b57cec5SDimitry Andric    _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1129*349cc55cSDimitry Andric    __enable_if_t
11300b57cec5SDimitry Andric        <
11310b57cec5SDimitry Andric            __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
11320b57cec5SDimitry Andric            basic_string&
11335ffd83dbSDimitry Andric        >
11340b57cec5SDimitry Andric                 insert(size_type __pos1, const _Tp& __t)
11350b57cec5SDimitry Andric    { __self_view __sv = __t; return insert(__pos1, __sv.data(), __sv.size()); }
11360b57cec5SDimitry Andric
11370b57cec5SDimitry Andric    template <class _Tp>
11380b57cec5SDimitry Andric    _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1139*349cc55cSDimitry Andric    __enable_if_t
11400b57cec5SDimitry Andric        <
11415ffd83dbSDimitry Andric            __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && !__is_same_uncvref<_Tp, basic_string>::value,
11420b57cec5SDimitry Andric            basic_string&
11435ffd83dbSDimitry Andric        >
11440b57cec5SDimitry Andric                  insert(size_type __pos1, const _Tp& __t, size_type __pos2, size_type __n=npos);
11450b57cec5SDimitry Andric    basic_string& insert(size_type __pos1, const basic_string& __str, size_type __pos2, size_type __n=npos);
11460b57cec5SDimitry Andric    basic_string& insert(size_type __pos, const value_type* __s, size_type __n);
11470b57cec5SDimitry Andric    basic_string& insert(size_type __pos, const value_type* __s);
11480b57cec5SDimitry Andric    basic_string& insert(size_type __pos, size_type __n, value_type __c);
11490b57cec5SDimitry Andric    iterator      insert(const_iterator __pos, value_type __c);
11500b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
11510b57cec5SDimitry Andric    iterator      insert(const_iterator __pos, size_type __n, value_type __c);
11520b57cec5SDimitry Andric    template<class _InputIterator>
11530b57cec5SDimitry Andric    _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1154*349cc55cSDimitry Andric    __enable_if_t
11550b57cec5SDimitry Andric        <
1156fe6060f1SDimitry Andric            __is_exactly_cpp17_input_iterator<_InputIterator>::value,
11570b57cec5SDimitry Andric            iterator
11585ffd83dbSDimitry Andric        >
11590b57cec5SDimitry Andric        insert(const_iterator __pos, _InputIterator __first, _InputIterator __last);
11600b57cec5SDimitry Andric    template<class _ForwardIterator>
11610b57cec5SDimitry Andric    _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1162*349cc55cSDimitry Andric    __enable_if_t
11630b57cec5SDimitry Andric        <
1164fe6060f1SDimitry Andric            __is_cpp17_forward_iterator<_ForwardIterator>::value,
11650b57cec5SDimitry Andric            iterator
11665ffd83dbSDimitry Andric        >
11670b57cec5SDimitry Andric        insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last);
11680b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
11690b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
11700b57cec5SDimitry Andric    iterator insert(const_iterator __pos, initializer_list<value_type> __il)
11710b57cec5SDimitry Andric                    {return insert(__pos, __il.begin(), __il.end());}
11720b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG
11730b57cec5SDimitry Andric
11740b57cec5SDimitry Andric    basic_string& erase(size_type __pos = 0, size_type __n = npos);
11750b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
11760b57cec5SDimitry Andric    iterator      erase(const_iterator __pos);
11770b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
11780b57cec5SDimitry Andric    iterator      erase(const_iterator __first, const_iterator __last);
11790b57cec5SDimitry Andric
11800b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
11810b57cec5SDimitry Andric    basic_string& replace(size_type __pos1, size_type __n1, const basic_string& __str);
11820b57cec5SDimitry Andric
11830b57cec5SDimitry Andric    template <class _Tp>
11840b57cec5SDimitry Andric    _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1185*349cc55cSDimitry Andric    __enable_if_t
11860b57cec5SDimitry Andric        <
11870b57cec5SDimitry Andric            __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
11880b57cec5SDimitry Andric            basic_string&
11895ffd83dbSDimitry Andric        >
11900b57cec5SDimitry Andric                  replace(size_type __pos1, size_type __n1, const _Tp& __t) { __self_view __sv = __t; return replace(__pos1, __n1, __sv.data(), __sv.size()); }
11910b57cec5SDimitry Andric    basic_string& replace(size_type __pos1, size_type __n1, const basic_string& __str, size_type __pos2, size_type __n2=npos);
11920b57cec5SDimitry Andric    template <class _Tp>
11930b57cec5SDimitry Andric    _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1194*349cc55cSDimitry Andric    __enable_if_t
11950b57cec5SDimitry Andric        <
11965ffd83dbSDimitry Andric            __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value  && !__is_same_uncvref<_Tp, basic_string>::value,
11970b57cec5SDimitry Andric            basic_string&
11985ffd83dbSDimitry Andric        >
11990b57cec5SDimitry Andric                  replace(size_type __pos1, size_type __n1, const _Tp& __t, size_type __pos2, size_type __n2=npos);
12000b57cec5SDimitry Andric    basic_string& replace(size_type __pos, size_type __n1, const value_type* __s, size_type __n2);
12010b57cec5SDimitry Andric    basic_string& replace(size_type __pos, size_type __n1, const value_type* __s);
12020b57cec5SDimitry Andric    basic_string& replace(size_type __pos, size_type __n1, size_type __n2, value_type __c);
12030b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
12040b57cec5SDimitry Andric    basic_string& replace(const_iterator __i1, const_iterator __i2, const basic_string& __str);
12050b57cec5SDimitry Andric
12060b57cec5SDimitry Andric    template <class _Tp>
12070b57cec5SDimitry Andric    _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1208*349cc55cSDimitry Andric    __enable_if_t
12090b57cec5SDimitry Andric        <
12100b57cec5SDimitry Andric            __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
12110b57cec5SDimitry Andric            basic_string&
12125ffd83dbSDimitry Andric        >
12130b57cec5SDimitry Andric                  replace(const_iterator __i1, const_iterator __i2, const _Tp& __t) { __self_view __sv = __t; return replace(__i1 - begin(), __i2 - __i1, __sv); }
12140b57cec5SDimitry Andric
12150b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
12160b57cec5SDimitry Andric    basic_string& replace(const_iterator __i1, const_iterator __i2, const value_type* __s, size_type __n);
12170b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
12180b57cec5SDimitry Andric    basic_string& replace(const_iterator __i1, const_iterator __i2, const value_type* __s);
12190b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
12200b57cec5SDimitry Andric    basic_string& replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c);
12210b57cec5SDimitry Andric    template<class _InputIterator>
12220b57cec5SDimitry Andric    _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1223*349cc55cSDimitry Andric    __enable_if_t
12240b57cec5SDimitry Andric        <
1225480093f4SDimitry Andric            __is_cpp17_input_iterator<_InputIterator>::value,
12260b57cec5SDimitry Andric            basic_string&
12275ffd83dbSDimitry Andric        >
12280b57cec5SDimitry Andric        replace(const_iterator __i1, const_iterator __i2, _InputIterator __j1, _InputIterator __j2);
12290b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
12300b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
12310b57cec5SDimitry Andric    basic_string& replace(const_iterator __i1, const_iterator __i2, initializer_list<value_type> __il)
12320b57cec5SDimitry Andric        {return replace(__i1, __i2, __il.begin(), __il.end());}
12330b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG
12340b57cec5SDimitry Andric
12350b57cec5SDimitry Andric    size_type copy(value_type* __s, size_type __n, size_type __pos = 0) const;
12360b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
12370b57cec5SDimitry Andric    basic_string substr(size_type __pos = 0, size_type __n = npos) const;
12380b57cec5SDimitry Andric
12390b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
12400b57cec5SDimitry Andric    void swap(basic_string& __str)
12410b57cec5SDimitry Andric#if _LIBCPP_STD_VER >= 14
12420b57cec5SDimitry Andric        _NOEXCEPT;
12430b57cec5SDimitry Andric#else
12440b57cec5SDimitry Andric        _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
12450b57cec5SDimitry Andric                    __is_nothrow_swappable<allocator_type>::value);
12460b57cec5SDimitry Andric#endif
12470b57cec5SDimitry Andric
12480b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
12490b57cec5SDimitry Andric    const value_type* c_str() const _NOEXCEPT {return data();}
12500b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
1251480093f4SDimitry Andric    const value_type* data() const _NOEXCEPT  {return _VSTD::__to_address(__get_pointer());}
12520b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 14 || defined(_LIBCPP_BUILDING_LIBRARY)
12530b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
1254480093f4SDimitry Andric    value_type* data()             _NOEXCEPT  {return _VSTD::__to_address(__get_pointer());}
12550b57cec5SDimitry Andric#endif
12560b57cec5SDimitry Andric
12570b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
12580b57cec5SDimitry Andric    allocator_type get_allocator() const _NOEXCEPT {return __alloc();}
12590b57cec5SDimitry Andric
12600b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
12610b57cec5SDimitry Andric    size_type find(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
12620b57cec5SDimitry Andric
12630b57cec5SDimitry Andric    template <class _Tp>
12640b57cec5SDimitry Andric    _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1265*349cc55cSDimitry Andric    __enable_if_t
12660b57cec5SDimitry Andric        <
12670b57cec5SDimitry Andric            __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
12680b57cec5SDimitry Andric            size_type
12695ffd83dbSDimitry Andric        >
1270fe6060f1SDimitry Andric              find(const _Tp& __t, size_type __pos = 0) const _NOEXCEPT;
12710b57cec5SDimitry Andric    size_type find(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
12720b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
12730b57cec5SDimitry Andric    size_type find(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
12740b57cec5SDimitry Andric    size_type find(value_type __c, size_type __pos = 0) const _NOEXCEPT;
12750b57cec5SDimitry Andric
12760b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
12770b57cec5SDimitry Andric    size_type rfind(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
12780b57cec5SDimitry Andric
12790b57cec5SDimitry Andric    template <class _Tp>
12800b57cec5SDimitry Andric    _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1281*349cc55cSDimitry Andric    __enable_if_t
12820b57cec5SDimitry Andric        <
12830b57cec5SDimitry Andric            __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
12840b57cec5SDimitry Andric            size_type
12855ffd83dbSDimitry Andric        >
1286fe6060f1SDimitry Andric              rfind(const _Tp& __t, size_type __pos = npos) const _NOEXCEPT;
12870b57cec5SDimitry Andric    size_type rfind(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
12880b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
12890b57cec5SDimitry Andric    size_type rfind(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
12900b57cec5SDimitry Andric    size_type rfind(value_type __c, size_type __pos = npos) const _NOEXCEPT;
12910b57cec5SDimitry Andric
12920b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
12930b57cec5SDimitry Andric    size_type find_first_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
12940b57cec5SDimitry Andric
12950b57cec5SDimitry Andric    template <class _Tp>
12960b57cec5SDimitry Andric    _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1297*349cc55cSDimitry Andric    __enable_if_t
12980b57cec5SDimitry Andric        <
12990b57cec5SDimitry Andric            __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
13000b57cec5SDimitry Andric            size_type
13015ffd83dbSDimitry Andric        >
1302fe6060f1SDimitry Andric              find_first_of(const _Tp& __t, size_type __pos = 0) const _NOEXCEPT;
13030b57cec5SDimitry Andric    size_type find_first_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
13040b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
13050b57cec5SDimitry Andric    size_type find_first_of(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
13060b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
13070b57cec5SDimitry Andric    size_type find_first_of(value_type __c, size_type __pos = 0) const _NOEXCEPT;
13080b57cec5SDimitry Andric
13090b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
13100b57cec5SDimitry Andric    size_type find_last_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
13110b57cec5SDimitry Andric
13120b57cec5SDimitry Andric    template <class _Tp>
13130b57cec5SDimitry Andric    _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1314*349cc55cSDimitry Andric    __enable_if_t
13150b57cec5SDimitry Andric        <
13160b57cec5SDimitry Andric            __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
13170b57cec5SDimitry Andric            size_type
13185ffd83dbSDimitry Andric        >
1319fe6060f1SDimitry Andric              find_last_of(const _Tp& __t, size_type __pos = npos) const _NOEXCEPT;
13200b57cec5SDimitry Andric    size_type find_last_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
13210b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
13220b57cec5SDimitry Andric    size_type find_last_of(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
13230b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
13240b57cec5SDimitry Andric    size_type find_last_of(value_type __c, size_type __pos = npos) const _NOEXCEPT;
13250b57cec5SDimitry Andric
13260b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
13270b57cec5SDimitry Andric    size_type find_first_not_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
13280b57cec5SDimitry Andric
13290b57cec5SDimitry Andric    template <class _Tp>
13300b57cec5SDimitry Andric    _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1331*349cc55cSDimitry Andric    __enable_if_t
13320b57cec5SDimitry Andric        <
13330b57cec5SDimitry Andric            __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
13340b57cec5SDimitry Andric            size_type
13355ffd83dbSDimitry Andric        >
1336fe6060f1SDimitry Andric              find_first_not_of(const _Tp &__t, size_type __pos = 0) const _NOEXCEPT;
13370b57cec5SDimitry Andric    size_type find_first_not_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
13380b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
13390b57cec5SDimitry Andric    size_type find_first_not_of(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
13400b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
13410b57cec5SDimitry Andric    size_type find_first_not_of(value_type __c, size_type __pos = 0) const _NOEXCEPT;
13420b57cec5SDimitry Andric
13430b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
13440b57cec5SDimitry Andric    size_type find_last_not_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
13450b57cec5SDimitry Andric
13460b57cec5SDimitry Andric    template <class _Tp>
13470b57cec5SDimitry Andric    _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1348*349cc55cSDimitry Andric    __enable_if_t
13490b57cec5SDimitry Andric        <
13500b57cec5SDimitry Andric            __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
13510b57cec5SDimitry Andric            size_type
13525ffd83dbSDimitry Andric        >
1353fe6060f1SDimitry Andric              find_last_not_of(const _Tp& __t, size_type __pos = npos) const _NOEXCEPT;
13540b57cec5SDimitry Andric    size_type find_last_not_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
13550b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
13560b57cec5SDimitry Andric    size_type find_last_not_of(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
13570b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
13580b57cec5SDimitry Andric    size_type find_last_not_of(value_type __c, size_type __pos = npos) const _NOEXCEPT;
13590b57cec5SDimitry Andric
13600b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
13610b57cec5SDimitry Andric    int compare(const basic_string& __str) const _NOEXCEPT;
13620b57cec5SDimitry Andric
13630b57cec5SDimitry Andric    template <class _Tp>
13640b57cec5SDimitry Andric    _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1365*349cc55cSDimitry Andric    __enable_if_t
13660b57cec5SDimitry Andric        <
13670b57cec5SDimitry Andric            __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
13680b57cec5SDimitry Andric            int
13695ffd83dbSDimitry Andric        >
1370fe6060f1SDimitry Andric        compare(const _Tp &__t) const _NOEXCEPT;
13710b57cec5SDimitry Andric
13720b57cec5SDimitry Andric    template <class _Tp>
13730b57cec5SDimitry Andric    _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1374*349cc55cSDimitry Andric    __enable_if_t
13750b57cec5SDimitry Andric        <
13760b57cec5SDimitry Andric            __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
13770b57cec5SDimitry Andric            int
13785ffd83dbSDimitry Andric        >
13790b57cec5SDimitry Andric         compare(size_type __pos1, size_type __n1, const _Tp& __t) const;
13800b57cec5SDimitry Andric
13810b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
13820b57cec5SDimitry Andric    int compare(size_type __pos1, size_type __n1, const basic_string& __str) const;
13830b57cec5SDimitry Andric    int compare(size_type __pos1, size_type __n1, const basic_string& __str, size_type __pos2, size_type __n2=npos) const;
13840b57cec5SDimitry Andric
13850b57cec5SDimitry Andric    template <class _Tp>
13860b57cec5SDimitry Andric    inline _LIBCPP_INLINE_VISIBILITY
1387*349cc55cSDimitry Andric        __enable_if_t
13880b57cec5SDimitry Andric        <
13895ffd83dbSDimitry Andric            __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value  && !__is_same_uncvref<_Tp, basic_string>::value,
13900b57cec5SDimitry Andric            int
13915ffd83dbSDimitry Andric        >
13920b57cec5SDimitry Andric        compare(size_type __pos1, size_type __n1, const _Tp& __t, size_type __pos2, size_type __n2=npos) const;
13930b57cec5SDimitry Andric    int compare(const value_type* __s) const _NOEXCEPT;
13940b57cec5SDimitry Andric    int compare(size_type __pos1, size_type __n1, const value_type* __s) const;
13950b57cec5SDimitry Andric    int compare(size_type __pos1, size_type __n1, const value_type* __s, size_type __n2) const;
13960b57cec5SDimitry Andric
13970b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 17
1398*349cc55cSDimitry Andric    constexpr _LIBCPP_INLINE_VISIBILITY
1399*349cc55cSDimitry Andric    bool starts_with(__self_view __sv) const noexcept
14000b57cec5SDimitry Andric    { return __self_view(data(), size()).starts_with(__sv); }
14010b57cec5SDimitry Andric
1402*349cc55cSDimitry Andric    constexpr _LIBCPP_INLINE_VISIBILITY
1403*349cc55cSDimitry Andric    bool starts_with(value_type __c) const noexcept
14040b57cec5SDimitry Andric    { return !empty() && _Traits::eq(front(), __c); }
14050b57cec5SDimitry Andric
1406*349cc55cSDimitry Andric    constexpr _LIBCPP_INLINE_VISIBILITY
1407*349cc55cSDimitry Andric    bool starts_with(const value_type* __s) const noexcept
14080b57cec5SDimitry Andric    { return starts_with(__self_view(__s)); }
14090b57cec5SDimitry Andric
1410*349cc55cSDimitry Andric    constexpr _LIBCPP_INLINE_VISIBILITY
1411*349cc55cSDimitry Andric    bool ends_with(__self_view __sv) const noexcept
14120b57cec5SDimitry Andric    { return __self_view(data(), size()).ends_with( __sv); }
14130b57cec5SDimitry Andric
1414*349cc55cSDimitry Andric    constexpr _LIBCPP_INLINE_VISIBILITY
1415*349cc55cSDimitry Andric    bool ends_with(value_type __c) const noexcept
14160b57cec5SDimitry Andric    { return !empty() && _Traits::eq(back(), __c); }
14170b57cec5SDimitry Andric
1418*349cc55cSDimitry Andric    constexpr _LIBCPP_INLINE_VISIBILITY
1419*349cc55cSDimitry Andric    bool ends_with(const value_type* __s) const noexcept
14200b57cec5SDimitry Andric    { return ends_with(__self_view(__s)); }
14210b57cec5SDimitry Andric#endif
14220b57cec5SDimitry Andric
1423e8d8bef9SDimitry Andric#if _LIBCPP_STD_VER > 20
1424e8d8bef9SDimitry Andric    constexpr _LIBCPP_INLINE_VISIBILITY
1425e8d8bef9SDimitry Andric    bool contains(__self_view __sv) const noexcept
1426e8d8bef9SDimitry Andric    { return __self_view(data(), size()).contains(__sv); }
1427e8d8bef9SDimitry Andric
1428e8d8bef9SDimitry Andric    constexpr _LIBCPP_INLINE_VISIBILITY
1429e8d8bef9SDimitry Andric    bool contains(value_type __c) const noexcept
1430e8d8bef9SDimitry Andric    { return __self_view(data(), size()).contains(__c); }
1431e8d8bef9SDimitry Andric
1432e8d8bef9SDimitry Andric    constexpr _LIBCPP_INLINE_VISIBILITY
1433e8d8bef9SDimitry Andric    bool contains(const value_type* __s) const
1434e8d8bef9SDimitry Andric    { return __self_view(data(), size()).contains(__s); }
1435e8d8bef9SDimitry Andric#endif
1436e8d8bef9SDimitry Andric
14370b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY bool __invariants() const;
14380b57cec5SDimitry Andric
14390b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY void __clear_and_shrink() _NOEXCEPT;
14400b57cec5SDimitry Andric
1441e8d8bef9SDimitry Andric    _LIBCPP_INLINE_VISIBILITY void __shrink_or_extend(size_type __target_capacity);
1442e8d8bef9SDimitry Andric
14430b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
14440b57cec5SDimitry Andric    bool __is_long() const _NOEXCEPT
14450b57cec5SDimitry Andric        {return bool(__r_.first().__s.__size_ & __short_mask);}
14460b57cec5SDimitry Andric
1447e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2
14480b57cec5SDimitry Andric
14490b57cec5SDimitry Andric    bool __dereferenceable(const const_iterator* __i) const;
14500b57cec5SDimitry Andric    bool __decrementable(const const_iterator* __i) const;
14510b57cec5SDimitry Andric    bool __addable(const const_iterator* __i, ptrdiff_t __n) const;
14520b57cec5SDimitry Andric    bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const;
14530b57cec5SDimitry Andric
1454e8d8bef9SDimitry Andric#endif // _LIBCPP_DEBUG_LEVEL == 2
14550b57cec5SDimitry Andric
14560b57cec5SDimitry Andricprivate:
14570b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
14580b57cec5SDimitry Andric    allocator_type& __alloc() _NOEXCEPT
14590b57cec5SDimitry Andric        {return __r_.second();}
14600b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
14610b57cec5SDimitry Andric    const allocator_type& __alloc() const _NOEXCEPT
14620b57cec5SDimitry Andric        {return __r_.second();}
14630b57cec5SDimitry Andric
14640b57cec5SDimitry Andric#ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
14650b57cec5SDimitry Andric
14660b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
14670b57cec5SDimitry Andric    void __set_short_size(size_type __s) _NOEXCEPT
14680b57cec5SDimitry Andric#   ifdef _LIBCPP_BIG_ENDIAN
14690b57cec5SDimitry Andric        {__r_.first().__s.__size_ = (unsigned char)(__s << 1);}
14700b57cec5SDimitry Andric#   else
14710b57cec5SDimitry Andric        {__r_.first().__s.__size_ = (unsigned char)(__s);}
14720b57cec5SDimitry Andric#   endif
14730b57cec5SDimitry Andric
14740b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
14750b57cec5SDimitry Andric    size_type __get_short_size() const _NOEXCEPT
14760b57cec5SDimitry Andric#   ifdef _LIBCPP_BIG_ENDIAN
14770b57cec5SDimitry Andric        {return __r_.first().__s.__size_ >> 1;}
14780b57cec5SDimitry Andric#   else
14790b57cec5SDimitry Andric        {return __r_.first().__s.__size_;}
14800b57cec5SDimitry Andric#   endif
14810b57cec5SDimitry Andric
14820b57cec5SDimitry Andric#else  // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
14830b57cec5SDimitry Andric
14840b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
14850b57cec5SDimitry Andric    void __set_short_size(size_type __s) _NOEXCEPT
14860b57cec5SDimitry Andric#   ifdef _LIBCPP_BIG_ENDIAN
14870b57cec5SDimitry Andric        {__r_.first().__s.__size_ = (unsigned char)(__s);}
14880b57cec5SDimitry Andric#   else
14890b57cec5SDimitry Andric        {__r_.first().__s.__size_ = (unsigned char)(__s << 1);}
14900b57cec5SDimitry Andric#   endif
14910b57cec5SDimitry Andric
14920b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
14930b57cec5SDimitry Andric    size_type __get_short_size() const _NOEXCEPT
14940b57cec5SDimitry Andric#   ifdef _LIBCPP_BIG_ENDIAN
14950b57cec5SDimitry Andric        {return __r_.first().__s.__size_;}
14960b57cec5SDimitry Andric#   else
14970b57cec5SDimitry Andric        {return __r_.first().__s.__size_ >> 1;}
14980b57cec5SDimitry Andric#   endif
14990b57cec5SDimitry Andric
15000b57cec5SDimitry Andric#endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
15010b57cec5SDimitry Andric
15020b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
15030b57cec5SDimitry Andric    void __set_long_size(size_type __s) _NOEXCEPT
15040b57cec5SDimitry Andric        {__r_.first().__l.__size_ = __s;}
15050b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
15060b57cec5SDimitry Andric    size_type __get_long_size() const _NOEXCEPT
15070b57cec5SDimitry Andric        {return __r_.first().__l.__size_;}
15080b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
15090b57cec5SDimitry Andric    void __set_size(size_type __s) _NOEXCEPT
15100b57cec5SDimitry Andric        {if (__is_long()) __set_long_size(__s); else __set_short_size(__s);}
15110b57cec5SDimitry Andric
15120b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
15130b57cec5SDimitry Andric    void __set_long_cap(size_type __s) _NOEXCEPT
15140b57cec5SDimitry Andric        {__r_.first().__l.__cap_  = __long_mask | __s;}
15150b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
15160b57cec5SDimitry Andric    size_type __get_long_cap() const _NOEXCEPT
15170b57cec5SDimitry Andric        {return __r_.first().__l.__cap_ & size_type(~__long_mask);}
15180b57cec5SDimitry Andric
15190b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
15200b57cec5SDimitry Andric    void __set_long_pointer(pointer __p) _NOEXCEPT
15210b57cec5SDimitry Andric        {__r_.first().__l.__data_ = __p;}
15220b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
15230b57cec5SDimitry Andric    pointer __get_long_pointer() _NOEXCEPT
15240b57cec5SDimitry Andric        {return __r_.first().__l.__data_;}
15250b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
15260b57cec5SDimitry Andric    const_pointer __get_long_pointer() const _NOEXCEPT
15270b57cec5SDimitry Andric        {return __r_.first().__l.__data_;}
15280b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
15290b57cec5SDimitry Andric    pointer __get_short_pointer() _NOEXCEPT
15300b57cec5SDimitry Andric        {return pointer_traits<pointer>::pointer_to(__r_.first().__s.__data_[0]);}
15310b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
15320b57cec5SDimitry Andric    const_pointer __get_short_pointer() const _NOEXCEPT
15330b57cec5SDimitry Andric        {return pointer_traits<const_pointer>::pointer_to(__r_.first().__s.__data_[0]);}
15340b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
15350b57cec5SDimitry Andric    pointer __get_pointer() _NOEXCEPT
15360b57cec5SDimitry Andric        {return __is_long() ? __get_long_pointer() : __get_short_pointer();}
15370b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
15380b57cec5SDimitry Andric    const_pointer __get_pointer() const _NOEXCEPT
15390b57cec5SDimitry Andric        {return __is_long() ? __get_long_pointer() : __get_short_pointer();}
15400b57cec5SDimitry Andric
15410b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
15420b57cec5SDimitry Andric    void __zero() _NOEXCEPT
15430b57cec5SDimitry Andric        {
15440b57cec5SDimitry Andric            size_type (&__a)[__n_words] = __r_.first().__r.__words;
15450b57cec5SDimitry Andric            for (unsigned __i = 0; __i < __n_words; ++__i)
15460b57cec5SDimitry Andric                __a[__i] = 0;
15470b57cec5SDimitry Andric        }
15480b57cec5SDimitry Andric
15490b57cec5SDimitry Andric    template <size_type __a> static
15500b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY
15510b57cec5SDimitry Andric        size_type __align_it(size_type __s) _NOEXCEPT
15520b57cec5SDimitry Andric            {return (__s + (__a-1)) & ~(__a-1);}
15530b57cec5SDimitry Andric    enum {__alignment = 16};
15540b57cec5SDimitry Andric    static _LIBCPP_INLINE_VISIBILITY
15550b57cec5SDimitry Andric    size_type __recommend(size_type __s) _NOEXCEPT
15560b57cec5SDimitry Andric        {
15570b57cec5SDimitry Andric        if (__s < __min_cap) return static_cast<size_type>(__min_cap) - 1;
15580b57cec5SDimitry Andric        size_type __guess = __align_it<sizeof(value_type) < __alignment ?
15590b57cec5SDimitry Andric                     __alignment/sizeof(value_type) : 1 > (__s+1) - 1;
15600b57cec5SDimitry Andric        if (__guess == __min_cap) ++__guess;
15610b57cec5SDimitry Andric        return __guess;
15620b57cec5SDimitry Andric        }
15630b57cec5SDimitry Andric
15640b57cec5SDimitry Andric    inline
15650b57cec5SDimitry Andric    void __init(const value_type* __s, size_type __sz, size_type __reserve);
15660b57cec5SDimitry Andric    inline
15670b57cec5SDimitry Andric    void __init(const value_type* __s, size_type __sz);
15680b57cec5SDimitry Andric    inline
15690b57cec5SDimitry Andric    void __init(size_type __n, value_type __c);
15700b57cec5SDimitry Andric
15715ffd83dbSDimitry Andric    // Slow path for the (inlined) copy constructor for 'long' strings.
15725ffd83dbSDimitry Andric    // Always externally instantiated and not inlined.
15735ffd83dbSDimitry Andric    // Requires that __s is zero terminated.
15745ffd83dbSDimitry Andric    // The main reason for this function to exist is because for unstable, we
15755ffd83dbSDimitry Andric    // want to allow inlining of the copy constructor. However, we don't want
15765ffd83dbSDimitry Andric    // to call the __init() functions as those are marked as inline which may
15775ffd83dbSDimitry Andric    // result in over-aggressive inlining by the compiler, where our aim is
15785ffd83dbSDimitry Andric    // to only inline the fast path code directly in the ctor.
15795ffd83dbSDimitry Andric    void __init_copy_ctor_external(const value_type* __s, size_type __sz);
15805ffd83dbSDimitry Andric
15810b57cec5SDimitry Andric    template <class _InputIterator>
15820b57cec5SDimitry Andric    inline
1583*349cc55cSDimitry Andric    __enable_if_t
15840b57cec5SDimitry Andric    <
15855ffd83dbSDimitry Andric        __is_exactly_cpp17_input_iterator<_InputIterator>::value
15865ffd83dbSDimitry Andric    >
15870b57cec5SDimitry Andric    __init(_InputIterator __first, _InputIterator __last);
15880b57cec5SDimitry Andric
15890b57cec5SDimitry Andric    template <class _ForwardIterator>
15900b57cec5SDimitry Andric    inline
1591*349cc55cSDimitry Andric    __enable_if_t
15920b57cec5SDimitry Andric    <
15935ffd83dbSDimitry Andric        __is_cpp17_forward_iterator<_ForwardIterator>::value
15945ffd83dbSDimitry Andric    >
15950b57cec5SDimitry Andric    __init(_ForwardIterator __first, _ForwardIterator __last);
15960b57cec5SDimitry Andric
15970b57cec5SDimitry Andric    void __grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
15980b57cec5SDimitry Andric                   size_type __n_copy,  size_type __n_del,     size_type __n_add = 0);
15990b57cec5SDimitry Andric    void __grow_by_and_replace(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
16000b57cec5SDimitry Andric                               size_type __n_copy,  size_type __n_del,
16010b57cec5SDimitry Andric                               size_type __n_add, const value_type* __p_new_stuff);
16020b57cec5SDimitry Andric
16035ffd83dbSDimitry Andric    // __assign_no_alias is invoked for assignment operations where we
16045ffd83dbSDimitry Andric    // have proof that the input does not alias the current instance.
16055ffd83dbSDimitry Andric    // For example, operator=(basic_string) performs a 'self' check.
16065ffd83dbSDimitry Andric    template <bool __is_short>
16075ffd83dbSDimitry Andric    basic_string& __assign_no_alias(const value_type* __s, size_type __n);
16085ffd83dbSDimitry Andric
16090b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
16100b57cec5SDimitry Andric    void __erase_to_end(size_type __pos);
16110b57cec5SDimitry Andric
16125ffd83dbSDimitry Andric    // __erase_external_with_move is invoked for erase() invocations where
16135ffd83dbSDimitry Andric    // `n ~= npos`, likely requiring memory moves on the string data.
16145ffd83dbSDimitry Andric    void __erase_external_with_move(size_type __pos, size_type __n);
16155ffd83dbSDimitry Andric
16160b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
16170b57cec5SDimitry Andric    void __copy_assign_alloc(const basic_string& __str)
16180b57cec5SDimitry Andric        {__copy_assign_alloc(__str, integral_constant<bool,
16190b57cec5SDimitry Andric                      __alloc_traits::propagate_on_container_copy_assignment::value>());}
16200b57cec5SDimitry Andric
16210b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
16220b57cec5SDimitry Andric    void __copy_assign_alloc(const basic_string& __str, true_type)
16230b57cec5SDimitry Andric        {
16240b57cec5SDimitry Andric            if (__alloc() == __str.__alloc())
16250b57cec5SDimitry Andric                __alloc() = __str.__alloc();
16260b57cec5SDimitry Andric            else
16270b57cec5SDimitry Andric            {
16280b57cec5SDimitry Andric                if (!__str.__is_long())
16290b57cec5SDimitry Andric                {
16300b57cec5SDimitry Andric                    __clear_and_shrink();
16310b57cec5SDimitry Andric                    __alloc() = __str.__alloc();
16320b57cec5SDimitry Andric                }
16330b57cec5SDimitry Andric                else
16340b57cec5SDimitry Andric                {
16350b57cec5SDimitry Andric                    allocator_type __a = __str.__alloc();
16360b57cec5SDimitry Andric                    pointer __p = __alloc_traits::allocate(__a, __str.__get_long_cap());
16370b57cec5SDimitry Andric                    __clear_and_shrink();
16380b57cec5SDimitry Andric                    __alloc() = _VSTD::move(__a);
16390b57cec5SDimitry Andric                    __set_long_pointer(__p);
16400b57cec5SDimitry Andric                    __set_long_cap(__str.__get_long_cap());
16410b57cec5SDimitry Andric                    __set_long_size(__str.size());
16420b57cec5SDimitry Andric                }
16430b57cec5SDimitry Andric            }
16440b57cec5SDimitry Andric        }
16450b57cec5SDimitry Andric
16460b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
16470b57cec5SDimitry Andric    void __copy_assign_alloc(const basic_string&, false_type) _NOEXCEPT
16480b57cec5SDimitry Andric        {}
16490b57cec5SDimitry Andric
16500b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
16510b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
16520b57cec5SDimitry Andric    void __move_assign(basic_string& __str, false_type)
16530b57cec5SDimitry Andric        _NOEXCEPT_(__alloc_traits::is_always_equal::value);
16540b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
16550b57cec5SDimitry Andric    void __move_assign(basic_string& __str, true_type)
16560b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 14
16570b57cec5SDimitry Andric        _NOEXCEPT;
16580b57cec5SDimitry Andric#else
16590b57cec5SDimitry Andric        _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
16600b57cec5SDimitry Andric#endif
16610b57cec5SDimitry Andric#endif
16620b57cec5SDimitry Andric
16630b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
16640b57cec5SDimitry Andric    void
16650b57cec5SDimitry Andric    __move_assign_alloc(basic_string& __str)
16660b57cec5SDimitry Andric        _NOEXCEPT_(
16670b57cec5SDimitry Andric            !__alloc_traits::propagate_on_container_move_assignment::value ||
16680b57cec5SDimitry Andric            is_nothrow_move_assignable<allocator_type>::value)
16690b57cec5SDimitry Andric    {__move_assign_alloc(__str, integral_constant<bool,
16700b57cec5SDimitry Andric                      __alloc_traits::propagate_on_container_move_assignment::value>());}
16710b57cec5SDimitry Andric
16720b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
16730b57cec5SDimitry Andric    void __move_assign_alloc(basic_string& __c, true_type)
16740b57cec5SDimitry Andric        _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
16750b57cec5SDimitry Andric        {
16760b57cec5SDimitry Andric            __alloc() = _VSTD::move(__c.__alloc());
16770b57cec5SDimitry Andric        }
16780b57cec5SDimitry Andric
16790b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
16800b57cec5SDimitry Andric    void __move_assign_alloc(basic_string&, false_type)
16810b57cec5SDimitry Andric        _NOEXCEPT
16820b57cec5SDimitry Andric        {}
16830b57cec5SDimitry Andric
16845ffd83dbSDimitry Andric    basic_string& __assign_external(const value_type* __s);
16855ffd83dbSDimitry Andric    basic_string& __assign_external(const value_type* __s, size_type __n);
16865ffd83dbSDimitry Andric
16875ffd83dbSDimitry Andric    // Assigns the value in __s, guaranteed to be __n < __min_cap in length.
16885ffd83dbSDimitry Andric    inline basic_string& __assign_short(const value_type* __s, size_type __n) {
16895ffd83dbSDimitry Andric      pointer __p = __is_long()
16905ffd83dbSDimitry Andric                        ? (__set_long_size(__n), __get_long_pointer())
16915ffd83dbSDimitry Andric                        : (__set_short_size(__n), __get_short_pointer());
16925ffd83dbSDimitry Andric      traits_type::move(_VSTD::__to_address(__p), __s, __n);
16935ffd83dbSDimitry Andric      traits_type::assign(__p[__n], value_type());
16945ffd83dbSDimitry Andric      return *this;
16955ffd83dbSDimitry Andric    }
16965ffd83dbSDimitry Andric
16970b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators();
16980b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY void __invalidate_iterators_past(size_type);
16990b57cec5SDimitry Andric
1700fe6060f1SDimitry Andric    template<class _Tp>
1701fe6060f1SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
1702fe6060f1SDimitry Andric    bool __addr_in_range(_Tp&& __t) const {
1703fe6060f1SDimitry Andric        const volatile void *__p = _VSTD::addressof(__t);
1704fe6060f1SDimitry Andric        return data() <= __p && __p <= data() + size();
1705fe6060f1SDimitry Andric    }
1706fe6060f1SDimitry Andric
170769ade1e0SDimitry Andric    _LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI
170869ade1e0SDimitry Andric    void __throw_length_error() const {
170969ade1e0SDimitry Andric#ifndef _LIBCPP_NO_EXCEPTIONS
171069ade1e0SDimitry Andric        __basic_string_common<true>::__throw_length_error();
171169ade1e0SDimitry Andric#else
171269ade1e0SDimitry Andric        _VSTD::abort();
171369ade1e0SDimitry Andric#endif
171469ade1e0SDimitry Andric    }
171569ade1e0SDimitry Andric
171669ade1e0SDimitry Andric    _LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI
171769ade1e0SDimitry Andric    void __throw_out_of_range() const {
171869ade1e0SDimitry Andric#ifndef _LIBCPP_NO_EXCEPTIONS
171969ade1e0SDimitry Andric        __basic_string_common<true>::__throw_out_of_range();
172069ade1e0SDimitry Andric#else
172169ade1e0SDimitry Andric        _VSTD::abort();
172269ade1e0SDimitry Andric#endif
172369ade1e0SDimitry Andric    }
172469ade1e0SDimitry Andric
17250b57cec5SDimitry Andric    friend basic_string operator+<>(const basic_string&, const basic_string&);
17260b57cec5SDimitry Andric    friend basic_string operator+<>(const value_type*, const basic_string&);
17270b57cec5SDimitry Andric    friend basic_string operator+<>(value_type, const basic_string&);
17280b57cec5SDimitry Andric    friend basic_string operator+<>(const basic_string&, const value_type*);
17290b57cec5SDimitry Andric    friend basic_string operator+<>(const basic_string&, value_type);
17300b57cec5SDimitry Andric};
17310b57cec5SDimitry Andric
17325ffd83dbSDimitry Andric// These declarations must appear before any functions are implicitly used
17335ffd83dbSDimitry Andric// so that they have the correct visibility specifier.
17345ffd83dbSDimitry Andric#ifdef _LIBCPP_ABI_STRING_OPTIMIZED_EXTERNAL_INSTANTIATION
17355ffd83dbSDimitry Andric    _LIBCPP_STRING_UNSTABLE_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE, char)
1736*349cc55cSDimitry Andric#   ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
17375ffd83dbSDimitry Andric        _LIBCPP_STRING_UNSTABLE_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE, wchar_t)
1738*349cc55cSDimitry Andric#   endif
17395ffd83dbSDimitry Andric#else
17405ffd83dbSDimitry Andric    _LIBCPP_STRING_V1_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE, char)
1741*349cc55cSDimitry Andric#   ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
17425ffd83dbSDimitry Andric        _LIBCPP_STRING_V1_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE, wchar_t)
17435ffd83dbSDimitry Andric#   endif
1744*349cc55cSDimitry Andric#endif
17455ffd83dbSDimitry Andric
17465ffd83dbSDimitry Andric
1747*349cc55cSDimitry Andric#if _LIBCPP_STD_VER >= 17
17480b57cec5SDimitry Andrictemplate<class _InputIterator,
1749fe6060f1SDimitry Andric         class _CharT = __iter_value_type<_InputIterator>,
17500b57cec5SDimitry Andric         class _Allocator = allocator<_CharT>,
1751*349cc55cSDimitry Andric         class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
1752*349cc55cSDimitry Andric         class = enable_if_t<__is_allocator<_Allocator>::value>
17530b57cec5SDimitry Andric         >
17540b57cec5SDimitry Andricbasic_string(_InputIterator, _InputIterator, _Allocator = _Allocator())
17550b57cec5SDimitry Andric  -> basic_string<_CharT, char_traits<_CharT>, _Allocator>;
17560b57cec5SDimitry Andric
17570b57cec5SDimitry Andrictemplate<class _CharT,
17580b57cec5SDimitry Andric         class _Traits,
17590b57cec5SDimitry Andric         class _Allocator = allocator<_CharT>,
1760*349cc55cSDimitry Andric         class = enable_if_t<__is_allocator<_Allocator>::value>
17610b57cec5SDimitry Andric         >
17620b57cec5SDimitry Andricexplicit basic_string(basic_string_view<_CharT, _Traits>, const _Allocator& = _Allocator())
17630b57cec5SDimitry Andric  -> basic_string<_CharT, _Traits, _Allocator>;
17640b57cec5SDimitry Andric
17650b57cec5SDimitry Andrictemplate<class _CharT,
17660b57cec5SDimitry Andric         class _Traits,
17670b57cec5SDimitry Andric         class _Allocator = allocator<_CharT>,
1768*349cc55cSDimitry Andric         class = enable_if_t<__is_allocator<_Allocator>::value>,
17690b57cec5SDimitry Andric         class _Sz = typename allocator_traits<_Allocator>::size_type
17700b57cec5SDimitry Andric         >
17710b57cec5SDimitry Andricbasic_string(basic_string_view<_CharT, _Traits>, _Sz, _Sz, const _Allocator& = _Allocator())
17720b57cec5SDimitry Andric  -> basic_string<_CharT, _Traits, _Allocator>;
17730b57cec5SDimitry Andric#endif
17740b57cec5SDimitry Andric
17750b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
17760b57cec5SDimitry Andricinline
17770b57cec5SDimitry Andricvoid
17780b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::__invalidate_all_iterators()
17790b57cec5SDimitry Andric{
1780e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2
17810b57cec5SDimitry Andric    __get_db()->__invalidate_all(this);
1782e8d8bef9SDimitry Andric#endif
17830b57cec5SDimitry Andric}
17840b57cec5SDimitry Andric
17850b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
17860b57cec5SDimitry Andricinline
17870b57cec5SDimitry Andricvoid
1788fe6060f1SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::__invalidate_iterators_past(size_type __pos)
17890b57cec5SDimitry Andric{
1790e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2
17910b57cec5SDimitry Andric    __c_node* __c = __get_db()->__find_c_and_lock(this);
17920b57cec5SDimitry Andric    if (__c)
17930b57cec5SDimitry Andric    {
17940b57cec5SDimitry Andric        const_pointer __new_last = __get_pointer() + __pos;
17950b57cec5SDimitry Andric        for (__i_node** __p = __c->end_; __p != __c->beg_; )
17960b57cec5SDimitry Andric        {
17970b57cec5SDimitry Andric            --__p;
17980b57cec5SDimitry Andric            const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_);
17990b57cec5SDimitry Andric            if (__i->base() > __new_last)
18000b57cec5SDimitry Andric            {
18010b57cec5SDimitry Andric                (*__p)->__c_ = nullptr;
18020b57cec5SDimitry Andric                if (--__c->end_ != __p)
1803e8d8bef9SDimitry Andric                    _VSTD::memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
18040b57cec5SDimitry Andric            }
18050b57cec5SDimitry Andric        }
18060b57cec5SDimitry Andric        __get_db()->unlock();
18070b57cec5SDimitry Andric    }
1808fe6060f1SDimitry Andric#else
1809fe6060f1SDimitry Andric    (void)__pos;
1810e8d8bef9SDimitry Andric#endif // _LIBCPP_DEBUG_LEVEL == 2
18110b57cec5SDimitry Andric}
18120b57cec5SDimitry Andric
18130b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
18140b57cec5SDimitry Andricinline
18150b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::basic_string()
18160b57cec5SDimitry Andric    _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
1817480093f4SDimitry Andric     : __r_(__default_init_tag(), __default_init_tag())
18180b57cec5SDimitry Andric{
1819e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2
18200b57cec5SDimitry Andric    __get_db()->__insert_c(this);
18210b57cec5SDimitry Andric#endif
18220b57cec5SDimitry Andric    __zero();
18230b57cec5SDimitry Andric}
18240b57cec5SDimitry Andric
18250b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
18260b57cec5SDimitry Andricinline
18270b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::basic_string(const allocator_type& __a)
18280b57cec5SDimitry Andric#if _LIBCPP_STD_VER <= 14
18290b57cec5SDimitry Andric        _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value)
18300b57cec5SDimitry Andric#else
18310b57cec5SDimitry Andric        _NOEXCEPT
18320b57cec5SDimitry Andric#endif
1833480093f4SDimitry Andric: __r_(__default_init_tag(), __a)
18340b57cec5SDimitry Andric{
1835e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2
18360b57cec5SDimitry Andric    __get_db()->__insert_c(this);
18370b57cec5SDimitry Andric#endif
18380b57cec5SDimitry Andric    __zero();
18390b57cec5SDimitry Andric}
18400b57cec5SDimitry Andric
18410b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
18420b57cec5SDimitry Andricvoid basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s,
18430b57cec5SDimitry Andric                                                       size_type __sz,
18440b57cec5SDimitry Andric                                                       size_type __reserve)
18450b57cec5SDimitry Andric{
18460b57cec5SDimitry Andric    if (__reserve > max_size())
18470b57cec5SDimitry Andric        this->__throw_length_error();
18480b57cec5SDimitry Andric    pointer __p;
18490b57cec5SDimitry Andric    if (__reserve < __min_cap)
18500b57cec5SDimitry Andric    {
18510b57cec5SDimitry Andric        __set_short_size(__sz);
18520b57cec5SDimitry Andric        __p = __get_short_pointer();
18530b57cec5SDimitry Andric    }
18540b57cec5SDimitry Andric    else
18550b57cec5SDimitry Andric    {
18560b57cec5SDimitry Andric        size_type __cap = __recommend(__reserve);
18570b57cec5SDimitry Andric        __p = __alloc_traits::allocate(__alloc(), __cap+1);
18580b57cec5SDimitry Andric        __set_long_pointer(__p);
18590b57cec5SDimitry Andric        __set_long_cap(__cap+1);
18600b57cec5SDimitry Andric        __set_long_size(__sz);
18610b57cec5SDimitry Andric    }
1862480093f4SDimitry Andric    traits_type::copy(_VSTD::__to_address(__p), __s, __sz);
18630b57cec5SDimitry Andric    traits_type::assign(__p[__sz], value_type());
18640b57cec5SDimitry Andric}
18650b57cec5SDimitry Andric
18660b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
18670b57cec5SDimitry Andricvoid
18680b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, size_type __sz)
18690b57cec5SDimitry Andric{
18700b57cec5SDimitry Andric    if (__sz > max_size())
18710b57cec5SDimitry Andric        this->__throw_length_error();
18720b57cec5SDimitry Andric    pointer __p;
18730b57cec5SDimitry Andric    if (__sz < __min_cap)
18740b57cec5SDimitry Andric    {
18750b57cec5SDimitry Andric        __set_short_size(__sz);
18760b57cec5SDimitry Andric        __p = __get_short_pointer();
18770b57cec5SDimitry Andric    }
18780b57cec5SDimitry Andric    else
18790b57cec5SDimitry Andric    {
18800b57cec5SDimitry Andric        size_type __cap = __recommend(__sz);
18810b57cec5SDimitry Andric        __p = __alloc_traits::allocate(__alloc(), __cap+1);
18820b57cec5SDimitry Andric        __set_long_pointer(__p);
18830b57cec5SDimitry Andric        __set_long_cap(__cap+1);
18840b57cec5SDimitry Andric        __set_long_size(__sz);
18850b57cec5SDimitry Andric    }
1886480093f4SDimitry Andric    traits_type::copy(_VSTD::__to_address(__p), __s, __sz);
18870b57cec5SDimitry Andric    traits_type::assign(__p[__sz], value_type());
18880b57cec5SDimitry Andric}
18890b57cec5SDimitry Andric
18900b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
18910b57cec5SDimitry Andrictemplate <class>
18920b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, const _Allocator& __a)
1893480093f4SDimitry Andric    : __r_(__default_init_tag(), __a)
18940b57cec5SDimitry Andric{
18950b57cec5SDimitry Andric    _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*, allocator) detected nullptr");
18960b57cec5SDimitry Andric    __init(__s, traits_type::length(__s));
1897e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2
18980b57cec5SDimitry Andric    __get_db()->__insert_c(this);
18990b57cec5SDimitry Andric#endif
19000b57cec5SDimitry Andric}
19010b57cec5SDimitry Andric
19020b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
19030b57cec5SDimitry Andricinline
19040b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, size_type __n)
1905480093f4SDimitry Andric     : __r_(__default_init_tag(), __default_init_tag())
19060b57cec5SDimitry Andric{
19070b57cec5SDimitry Andric    _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n) detected nullptr");
19080b57cec5SDimitry Andric    __init(__s, __n);
1909e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2
19100b57cec5SDimitry Andric    __get_db()->__insert_c(this);
19110b57cec5SDimitry Andric#endif
19120b57cec5SDimitry Andric}
19130b57cec5SDimitry Andric
19140b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
19150b57cec5SDimitry Andricinline
19160b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, size_type __n, const _Allocator& __a)
1917480093f4SDimitry Andric    : __r_(__default_init_tag(), __a)
19180b57cec5SDimitry Andric{
19190b57cec5SDimitry Andric    _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n, allocator) detected nullptr");
19200b57cec5SDimitry Andric    __init(__s, __n);
1921e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2
19220b57cec5SDimitry Andric    __get_db()->__insert_c(this);
19230b57cec5SDimitry Andric#endif
19240b57cec5SDimitry Andric}
19250b57cec5SDimitry Andric
19260b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
19270b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str)
1928480093f4SDimitry Andric    : __r_(__default_init_tag(), __alloc_traits::select_on_container_copy_construction(__str.__alloc()))
19290b57cec5SDimitry Andric{
19300b57cec5SDimitry Andric    if (!__str.__is_long())
19310b57cec5SDimitry Andric        __r_.first().__r = __str.__r_.first().__r;
19320b57cec5SDimitry Andric    else
19335ffd83dbSDimitry Andric        __init_copy_ctor_external(_VSTD::__to_address(__str.__get_long_pointer()),
19345ffd83dbSDimitry Andric                                  __str.__get_long_size());
19355ffd83dbSDimitry Andric
1936e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2
19370b57cec5SDimitry Andric    __get_db()->__insert_c(this);
19380b57cec5SDimitry Andric#endif
19390b57cec5SDimitry Andric}
19400b57cec5SDimitry Andric
19410b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
19420b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::basic_string(
19430b57cec5SDimitry Andric    const basic_string& __str, const allocator_type& __a)
1944480093f4SDimitry Andric    : __r_(__default_init_tag(), __a)
19450b57cec5SDimitry Andric{
19460b57cec5SDimitry Andric    if (!__str.__is_long())
19470b57cec5SDimitry Andric        __r_.first().__r = __str.__r_.first().__r;
19480b57cec5SDimitry Andric    else
19495ffd83dbSDimitry Andric        __init_copy_ctor_external(_VSTD::__to_address(__str.__get_long_pointer()),
19505ffd83dbSDimitry Andric                                  __str.__get_long_size());
1951e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2
19520b57cec5SDimitry Andric    __get_db()->__insert_c(this);
19530b57cec5SDimitry Andric#endif
19540b57cec5SDimitry Andric}
19550b57cec5SDimitry Andric
19565ffd83dbSDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
19575ffd83dbSDimitry Andricvoid basic_string<_CharT, _Traits, _Allocator>::__init_copy_ctor_external(
19585ffd83dbSDimitry Andric    const value_type* __s, size_type __sz) {
19595ffd83dbSDimitry Andric  pointer __p;
19605ffd83dbSDimitry Andric  if (__sz < __min_cap) {
19615ffd83dbSDimitry Andric    __p = __get_short_pointer();
19625ffd83dbSDimitry Andric    __set_short_size(__sz);
19635ffd83dbSDimitry Andric  } else {
19645ffd83dbSDimitry Andric    if (__sz > max_size())
19655ffd83dbSDimitry Andric      this->__throw_length_error();
19665ffd83dbSDimitry Andric    size_t __cap = __recommend(__sz);
19675ffd83dbSDimitry Andric    __p = __alloc_traits::allocate(__alloc(), __cap + 1);
19685ffd83dbSDimitry Andric    __set_long_pointer(__p);
19695ffd83dbSDimitry Andric    __set_long_cap(__cap + 1);
19705ffd83dbSDimitry Andric    __set_long_size(__sz);
19715ffd83dbSDimitry Andric  }
19725ffd83dbSDimitry Andric  traits_type::copy(_VSTD::__to_address(__p), __s, __sz + 1);
19735ffd83dbSDimitry Andric}
19745ffd83dbSDimitry Andric
19750b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
19760b57cec5SDimitry Andric
19770b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
19780b57cec5SDimitry Andricinline
19790b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str)
19800b57cec5SDimitry Andric#if _LIBCPP_STD_VER <= 14
19810b57cec5SDimitry Andric        _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
19820b57cec5SDimitry Andric#else
19830b57cec5SDimitry Andric        _NOEXCEPT
19840b57cec5SDimitry Andric#endif
19850b57cec5SDimitry Andric    : __r_(_VSTD::move(__str.__r_))
19860b57cec5SDimitry Andric{
19870b57cec5SDimitry Andric    __str.__zero();
1988e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2
19890b57cec5SDimitry Andric    __get_db()->__insert_c(this);
19900b57cec5SDimitry Andric    if (__is_long())
19910b57cec5SDimitry Andric        __get_db()->swap(this, &__str);
19920b57cec5SDimitry Andric#endif
19930b57cec5SDimitry Andric}
19940b57cec5SDimitry Andric
19950b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
19960b57cec5SDimitry Andricinline
19970b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str, const allocator_type& __a)
1998480093f4SDimitry Andric    : __r_(__default_init_tag(), __a)
19990b57cec5SDimitry Andric{
20000b57cec5SDimitry Andric    if (__str.__is_long() && __a != __str.__alloc()) // copy, not move
2001480093f4SDimitry Andric        __init(_VSTD::__to_address(__str.__get_long_pointer()), __str.__get_long_size());
20020b57cec5SDimitry Andric    else
20030b57cec5SDimitry Andric    {
20040b57cec5SDimitry Andric        __r_.first().__r = __str.__r_.first().__r;
20050b57cec5SDimitry Andric        __str.__zero();
20060b57cec5SDimitry Andric    }
2007e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2
20080b57cec5SDimitry Andric    __get_db()->__insert_c(this);
20090b57cec5SDimitry Andric    if (__is_long())
20100b57cec5SDimitry Andric        __get_db()->swap(this, &__str);
20110b57cec5SDimitry Andric#endif
20120b57cec5SDimitry Andric}
20130b57cec5SDimitry Andric
20140b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG
20150b57cec5SDimitry Andric
20160b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
20170b57cec5SDimitry Andricvoid
20180b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::__init(size_type __n, value_type __c)
20190b57cec5SDimitry Andric{
20200b57cec5SDimitry Andric    if (__n > max_size())
20210b57cec5SDimitry Andric        this->__throw_length_error();
20220b57cec5SDimitry Andric    pointer __p;
20230b57cec5SDimitry Andric    if (__n < __min_cap)
20240b57cec5SDimitry Andric    {
20250b57cec5SDimitry Andric        __set_short_size(__n);
20260b57cec5SDimitry Andric        __p = __get_short_pointer();
20270b57cec5SDimitry Andric    }
20280b57cec5SDimitry Andric    else
20290b57cec5SDimitry Andric    {
20300b57cec5SDimitry Andric        size_type __cap = __recommend(__n);
20310b57cec5SDimitry Andric        __p = __alloc_traits::allocate(__alloc(), __cap+1);
20320b57cec5SDimitry Andric        __set_long_pointer(__p);
20330b57cec5SDimitry Andric        __set_long_cap(__cap+1);
20340b57cec5SDimitry Andric        __set_long_size(__n);
20350b57cec5SDimitry Andric    }
2036480093f4SDimitry Andric    traits_type::assign(_VSTD::__to_address(__p), __n, __c);
20370b57cec5SDimitry Andric    traits_type::assign(__p[__n], value_type());
20380b57cec5SDimitry Andric}
20390b57cec5SDimitry Andric
20400b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
20410b57cec5SDimitry Andricinline
20420b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, _CharT __c)
2043480093f4SDimitry Andric     : __r_(__default_init_tag(), __default_init_tag())
20440b57cec5SDimitry Andric{
20450b57cec5SDimitry Andric    __init(__n, __c);
2046e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2
20470b57cec5SDimitry Andric    __get_db()->__insert_c(this);
20480b57cec5SDimitry Andric#endif
20490b57cec5SDimitry Andric}
20500b57cec5SDimitry Andric
20510b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
20520b57cec5SDimitry Andrictemplate <class>
20530b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, _CharT __c, const _Allocator& __a)
2054480093f4SDimitry Andric    : __r_(__default_init_tag(), __a)
20550b57cec5SDimitry Andric{
20560b57cec5SDimitry Andric    __init(__n, __c);
2057e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2
20580b57cec5SDimitry Andric    __get_db()->__insert_c(this);
20590b57cec5SDimitry Andric#endif
20600b57cec5SDimitry Andric}
20610b57cec5SDimitry Andric
20620b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
20630b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str,
20640b57cec5SDimitry Andric                                                        size_type __pos, size_type __n,
20650b57cec5SDimitry Andric                                                        const _Allocator& __a)
2066480093f4SDimitry Andric    : __r_(__default_init_tag(), __a)
20670b57cec5SDimitry Andric{
20680b57cec5SDimitry Andric    size_type __str_sz = __str.size();
20690b57cec5SDimitry Andric    if (__pos > __str_sz)
20700b57cec5SDimitry Andric        this->__throw_out_of_range();
20710b57cec5SDimitry Andric    __init(__str.data() + __pos, _VSTD::min(__n, __str_sz - __pos));
2072e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2
20730b57cec5SDimitry Andric    __get_db()->__insert_c(this);
20740b57cec5SDimitry Andric#endif
20750b57cec5SDimitry Andric}
20760b57cec5SDimitry Andric
20770b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
20780b57cec5SDimitry Andricinline
20790b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str, size_type __pos,
20800b57cec5SDimitry Andric                                                        const _Allocator& __a)
2081480093f4SDimitry Andric    : __r_(__default_init_tag(), __a)
20820b57cec5SDimitry Andric{
20830b57cec5SDimitry Andric    size_type __str_sz = __str.size();
20840b57cec5SDimitry Andric    if (__pos > __str_sz)
20850b57cec5SDimitry Andric        this->__throw_out_of_range();
20860b57cec5SDimitry Andric    __init(__str.data() + __pos, __str_sz - __pos);
2087e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2
20880b57cec5SDimitry Andric    __get_db()->__insert_c(this);
20890b57cec5SDimitry Andric#endif
20900b57cec5SDimitry Andric}
20910b57cec5SDimitry Andric
20920b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
20930b57cec5SDimitry Andrictemplate <class _Tp, class>
20940b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::basic_string(
20950b57cec5SDimitry Andric             const _Tp& __t, size_type __pos, size_type __n, const allocator_type& __a)
2096480093f4SDimitry Andric    : __r_(__default_init_tag(), __a)
20970b57cec5SDimitry Andric{
20980b57cec5SDimitry Andric    __self_view __sv0 = __t;
20990b57cec5SDimitry Andric    __self_view __sv = __sv0.substr(__pos, __n);
21000b57cec5SDimitry Andric    __init(__sv.data(), __sv.size());
2101e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2
21020b57cec5SDimitry Andric    __get_db()->__insert_c(this);
21030b57cec5SDimitry Andric#endif
21040b57cec5SDimitry Andric}
21050b57cec5SDimitry Andric
21060b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
21070b57cec5SDimitry Andrictemplate <class _Tp, class>
21080b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::basic_string(const _Tp & __t)
2109480093f4SDimitry Andric     : __r_(__default_init_tag(), __default_init_tag())
21100b57cec5SDimitry Andric{
21110b57cec5SDimitry Andric    __self_view __sv = __t;
21120b57cec5SDimitry Andric    __init(__sv.data(), __sv.size());
2113e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2
21140b57cec5SDimitry Andric    __get_db()->__insert_c(this);
21150b57cec5SDimitry Andric#endif
21160b57cec5SDimitry Andric}
21170b57cec5SDimitry Andric
21180b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
21190b57cec5SDimitry Andrictemplate <class _Tp, class>
21200b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::basic_string(const _Tp & __t, const _Allocator& __a)
2121480093f4SDimitry Andric    : __r_(__default_init_tag(), __a)
21220b57cec5SDimitry Andric{
21230b57cec5SDimitry Andric    __self_view __sv = __t;
21240b57cec5SDimitry Andric    __init(__sv.data(), __sv.size());
2125e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2
21260b57cec5SDimitry Andric    __get_db()->__insert_c(this);
21270b57cec5SDimitry Andric#endif
21280b57cec5SDimitry Andric}
21290b57cec5SDimitry Andric
21300b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
21310b57cec5SDimitry Andrictemplate <class _InputIterator>
2132*349cc55cSDimitry Andric__enable_if_t
21330b57cec5SDimitry Andric<
21345ffd83dbSDimitry Andric    __is_exactly_cpp17_input_iterator<_InputIterator>::value
21355ffd83dbSDimitry Andric>
21360b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::__init(_InputIterator __first, _InputIterator __last)
21370b57cec5SDimitry Andric{
21380b57cec5SDimitry Andric    __zero();
21390b57cec5SDimitry Andric#ifndef _LIBCPP_NO_EXCEPTIONS
21400b57cec5SDimitry Andric    try
21410b57cec5SDimitry Andric    {
21420b57cec5SDimitry Andric#endif // _LIBCPP_NO_EXCEPTIONS
21430b57cec5SDimitry Andric    for (; __first != __last; ++__first)
21440b57cec5SDimitry Andric        push_back(*__first);
21450b57cec5SDimitry Andric#ifndef _LIBCPP_NO_EXCEPTIONS
21460b57cec5SDimitry Andric    }
21470b57cec5SDimitry Andric    catch (...)
21480b57cec5SDimitry Andric    {
21490b57cec5SDimitry Andric        if (__is_long())
21500b57cec5SDimitry Andric            __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
21510b57cec5SDimitry Andric        throw;
21520b57cec5SDimitry Andric    }
21530b57cec5SDimitry Andric#endif // _LIBCPP_NO_EXCEPTIONS
21540b57cec5SDimitry Andric}
21550b57cec5SDimitry Andric
21560b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
21570b57cec5SDimitry Andrictemplate <class _ForwardIterator>
2158*349cc55cSDimitry Andric__enable_if_t
21590b57cec5SDimitry Andric<
21605ffd83dbSDimitry Andric    __is_cpp17_forward_iterator<_ForwardIterator>::value
21615ffd83dbSDimitry Andric>
21620b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::__init(_ForwardIterator __first, _ForwardIterator __last)
21630b57cec5SDimitry Andric{
21640b57cec5SDimitry Andric    size_type __sz = static_cast<size_type>(_VSTD::distance(__first, __last));
21650b57cec5SDimitry Andric    if (__sz > max_size())
21660b57cec5SDimitry Andric        this->__throw_length_error();
21670b57cec5SDimitry Andric    pointer __p;
21680b57cec5SDimitry Andric    if (__sz < __min_cap)
21690b57cec5SDimitry Andric    {
21700b57cec5SDimitry Andric        __set_short_size(__sz);
21710b57cec5SDimitry Andric        __p = __get_short_pointer();
21720b57cec5SDimitry Andric    }
21730b57cec5SDimitry Andric    else
21740b57cec5SDimitry Andric    {
21750b57cec5SDimitry Andric        size_type __cap = __recommend(__sz);
21760b57cec5SDimitry Andric        __p = __alloc_traits::allocate(__alloc(), __cap+1);
21770b57cec5SDimitry Andric        __set_long_pointer(__p);
21780b57cec5SDimitry Andric        __set_long_cap(__cap+1);
21790b57cec5SDimitry Andric        __set_long_size(__sz);
21800b57cec5SDimitry Andric    }
2181fe6060f1SDimitry Andric
2182fe6060f1SDimitry Andric#ifndef _LIBCPP_NO_EXCEPTIONS
2183fe6060f1SDimitry Andric    try
2184fe6060f1SDimitry Andric    {
2185fe6060f1SDimitry Andric#endif  // _LIBCPP_NO_EXCEPTIONS
21860b57cec5SDimitry Andric    for (; __first != __last; ++__first, (void) ++__p)
21870b57cec5SDimitry Andric        traits_type::assign(*__p, *__first);
21880b57cec5SDimitry Andric    traits_type::assign(*__p, value_type());
2189fe6060f1SDimitry Andric#ifndef _LIBCPP_NO_EXCEPTIONS
2190fe6060f1SDimitry Andric    }
2191fe6060f1SDimitry Andric    catch (...)
2192fe6060f1SDimitry Andric    {
2193fe6060f1SDimitry Andric        if (__is_long())
2194fe6060f1SDimitry Andric            __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
2195fe6060f1SDimitry Andric        throw;
2196fe6060f1SDimitry Andric    }
2197fe6060f1SDimitry Andric#endif  // _LIBCPP_NO_EXCEPTIONS
21980b57cec5SDimitry Andric}
21990b57cec5SDimitry Andric
22000b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
22010b57cec5SDimitry Andrictemplate<class _InputIterator, class>
22020b57cec5SDimitry Andricinline
22030b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last)
2204480093f4SDimitry Andric     : __r_(__default_init_tag(), __default_init_tag())
22050b57cec5SDimitry Andric{
22060b57cec5SDimitry Andric    __init(__first, __last);
2207e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2
22080b57cec5SDimitry Andric    __get_db()->__insert_c(this);
22090b57cec5SDimitry Andric#endif
22100b57cec5SDimitry Andric}
22110b57cec5SDimitry Andric
22120b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
22130b57cec5SDimitry Andrictemplate<class _InputIterator, class>
22140b57cec5SDimitry Andricinline
22150b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last,
22160b57cec5SDimitry Andric                                                        const allocator_type& __a)
2217480093f4SDimitry Andric    : __r_(__default_init_tag(), __a)
22180b57cec5SDimitry Andric{
22190b57cec5SDimitry Andric    __init(__first, __last);
2220e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2
22210b57cec5SDimitry Andric    __get_db()->__insert_c(this);
22220b57cec5SDimitry Andric#endif
22230b57cec5SDimitry Andric}
22240b57cec5SDimitry Andric
22250b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
22260b57cec5SDimitry Andric
22270b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
22280b57cec5SDimitry Andricinline
22290b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::basic_string(
22300b57cec5SDimitry Andric    initializer_list<_CharT> __il)
2231480093f4SDimitry Andric     : __r_(__default_init_tag(), __default_init_tag())
22320b57cec5SDimitry Andric{
22330b57cec5SDimitry Andric    __init(__il.begin(), __il.end());
2234e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2
22350b57cec5SDimitry Andric    __get_db()->__insert_c(this);
22360b57cec5SDimitry Andric#endif
22370b57cec5SDimitry Andric}
22380b57cec5SDimitry Andric
22390b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
22400b57cec5SDimitry Andricinline
22410b57cec5SDimitry Andric
22420b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::basic_string(
22430b57cec5SDimitry Andric    initializer_list<_CharT> __il, const _Allocator& __a)
2244480093f4SDimitry Andric    : __r_(__default_init_tag(), __a)
22450b57cec5SDimitry Andric{
22460b57cec5SDimitry Andric    __init(__il.begin(), __il.end());
2247e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2
22480b57cec5SDimitry Andric    __get_db()->__insert_c(this);
22490b57cec5SDimitry Andric#endif
22500b57cec5SDimitry Andric}
22510b57cec5SDimitry Andric
22520b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG
22530b57cec5SDimitry Andric
22540b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
22550b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::~basic_string()
22560b57cec5SDimitry Andric{
2257e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2
22580b57cec5SDimitry Andric    __get_db()->__erase_c(this);
22590b57cec5SDimitry Andric#endif
22600b57cec5SDimitry Andric    if (__is_long())
22610b57cec5SDimitry Andric        __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
22620b57cec5SDimitry Andric}
22630b57cec5SDimitry Andric
22640b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
22650b57cec5SDimitry Andricvoid
22660b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::__grow_by_and_replace
22670b57cec5SDimitry Andric    (size_type __old_cap, size_type __delta_cap, size_type __old_sz,
22680b57cec5SDimitry Andric     size_type __n_copy,  size_type __n_del,     size_type __n_add, const value_type* __p_new_stuff)
22690b57cec5SDimitry Andric{
22700b57cec5SDimitry Andric    size_type __ms = max_size();
22710b57cec5SDimitry Andric    if (__delta_cap > __ms - __old_cap - 1)
22720b57cec5SDimitry Andric        this->__throw_length_error();
22730b57cec5SDimitry Andric    pointer __old_p = __get_pointer();
22740b57cec5SDimitry Andric    size_type __cap = __old_cap < __ms / 2 - __alignment ?
22750b57cec5SDimitry Andric                          __recommend(_VSTD::max(__old_cap + __delta_cap, 2 * __old_cap)) :
22760b57cec5SDimitry Andric                          __ms - 1;
22770b57cec5SDimitry Andric    pointer __p = __alloc_traits::allocate(__alloc(), __cap+1);
22780b57cec5SDimitry Andric    __invalidate_all_iterators();
22790b57cec5SDimitry Andric    if (__n_copy != 0)
2280480093f4SDimitry Andric        traits_type::copy(_VSTD::__to_address(__p),
2281480093f4SDimitry Andric                          _VSTD::__to_address(__old_p), __n_copy);
22820b57cec5SDimitry Andric    if (__n_add != 0)
2283480093f4SDimitry Andric        traits_type::copy(_VSTD::__to_address(__p) + __n_copy, __p_new_stuff, __n_add);
22840b57cec5SDimitry Andric    size_type __sec_cp_sz = __old_sz - __n_del - __n_copy;
22850b57cec5SDimitry Andric    if (__sec_cp_sz != 0)
2286480093f4SDimitry Andric        traits_type::copy(_VSTD::__to_address(__p) + __n_copy + __n_add,
2287480093f4SDimitry Andric                          _VSTD::__to_address(__old_p) + __n_copy + __n_del, __sec_cp_sz);
22880b57cec5SDimitry Andric    if (__old_cap+1 != __min_cap)
22890b57cec5SDimitry Andric        __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1);
22900b57cec5SDimitry Andric    __set_long_pointer(__p);
22910b57cec5SDimitry Andric    __set_long_cap(__cap+1);
22920b57cec5SDimitry Andric    __old_sz = __n_copy + __n_add + __sec_cp_sz;
22930b57cec5SDimitry Andric    __set_long_size(__old_sz);
22940b57cec5SDimitry Andric    traits_type::assign(__p[__old_sz], value_type());
22950b57cec5SDimitry Andric}
22960b57cec5SDimitry Andric
22970b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
22980b57cec5SDimitry Andricvoid
22990b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::__grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
23000b57cec5SDimitry Andric                                                     size_type __n_copy,  size_type __n_del,     size_type __n_add)
23010b57cec5SDimitry Andric{
23020b57cec5SDimitry Andric    size_type __ms = max_size();
23030b57cec5SDimitry Andric    if (__delta_cap > __ms - __old_cap)
23040b57cec5SDimitry Andric        this->__throw_length_error();
23050b57cec5SDimitry Andric    pointer __old_p = __get_pointer();
23060b57cec5SDimitry Andric    size_type __cap = __old_cap < __ms / 2 - __alignment ?
23070b57cec5SDimitry Andric                          __recommend(_VSTD::max(__old_cap + __delta_cap, 2 * __old_cap)) :
23080b57cec5SDimitry Andric                          __ms - 1;
23090b57cec5SDimitry Andric    pointer __p = __alloc_traits::allocate(__alloc(), __cap+1);
23100b57cec5SDimitry Andric    __invalidate_all_iterators();
23110b57cec5SDimitry Andric    if (__n_copy != 0)
2312480093f4SDimitry Andric        traits_type::copy(_VSTD::__to_address(__p),
2313480093f4SDimitry Andric                          _VSTD::__to_address(__old_p), __n_copy);
23140b57cec5SDimitry Andric    size_type __sec_cp_sz = __old_sz - __n_del - __n_copy;
23150b57cec5SDimitry Andric    if (__sec_cp_sz != 0)
2316480093f4SDimitry Andric        traits_type::copy(_VSTD::__to_address(__p) + __n_copy + __n_add,
2317480093f4SDimitry Andric                          _VSTD::__to_address(__old_p) + __n_copy + __n_del,
23180b57cec5SDimitry Andric                          __sec_cp_sz);
23190b57cec5SDimitry Andric    if (__old_cap+1 != __min_cap)
23200b57cec5SDimitry Andric        __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1);
23210b57cec5SDimitry Andric    __set_long_pointer(__p);
23220b57cec5SDimitry Andric    __set_long_cap(__cap+1);
23230b57cec5SDimitry Andric}
23240b57cec5SDimitry Andric
23250b57cec5SDimitry Andric// assign
23260b57cec5SDimitry Andric
23270b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
23285ffd83dbSDimitry Andrictemplate <bool __is_short>
23290b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>&
23305ffd83dbSDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::__assign_no_alias(
23315ffd83dbSDimitry Andric    const value_type* __s, size_type __n) {
23325ffd83dbSDimitry Andric  size_type __cap = __is_short ? __min_cap : __get_long_cap();
23335ffd83dbSDimitry Andric  if (__n < __cap) {
23345ffd83dbSDimitry Andric    pointer __p = __is_short ? __get_short_pointer() : __get_long_pointer();
23355ffd83dbSDimitry Andric    __is_short ? __set_short_size(__n) : __set_long_size(__n);
23365ffd83dbSDimitry Andric    traits_type::copy(_VSTD::__to_address(__p), __s, __n);
23375ffd83dbSDimitry Andric    traits_type::assign(__p[__n], value_type());
23385ffd83dbSDimitry Andric    __invalidate_iterators_past(__n);
23395ffd83dbSDimitry Andric  } else {
23405ffd83dbSDimitry Andric    size_type __sz = __is_short ? __get_short_size() : __get_long_size();
23415ffd83dbSDimitry Andric    __grow_by_and_replace(__cap - 1, __n - __cap + 1, __sz, 0, __sz, __n, __s);
23425ffd83dbSDimitry Andric  }
23435ffd83dbSDimitry Andric  return *this;
23445ffd83dbSDimitry Andric}
23455ffd83dbSDimitry Andric
23465ffd83dbSDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
23475ffd83dbSDimitry Andricbasic_string<_CharT, _Traits, _Allocator>&
23485ffd83dbSDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::__assign_external(
23495ffd83dbSDimitry Andric    const value_type* __s, size_type __n) {
23500b57cec5SDimitry Andric  size_type __cap = capacity();
23515ffd83dbSDimitry Andric  if (__cap >= __n) {
2352480093f4SDimitry Andric    value_type* __p = _VSTD::__to_address(__get_pointer());
23530b57cec5SDimitry Andric    traits_type::move(__p, __s, __n);
23540b57cec5SDimitry Andric    traits_type::assign(__p[__n], value_type());
23550b57cec5SDimitry Andric    __set_size(__n);
23560b57cec5SDimitry Andric    __invalidate_iterators_past(__n);
23575ffd83dbSDimitry Andric  } else {
23580b57cec5SDimitry Andric    size_type __sz = size();
23590b57cec5SDimitry Andric    __grow_by_and_replace(__cap, __n - __cap, __sz, 0, __sz, __n, __s);
23600b57cec5SDimitry Andric  }
23610b57cec5SDimitry Andric  return *this;
23620b57cec5SDimitry Andric}
23630b57cec5SDimitry Andric
23640b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
23650b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>&
23665ffd83dbSDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s, size_type __n)
23675ffd83dbSDimitry Andric{
23685ffd83dbSDimitry Andric    _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::assign received nullptr");
2369*349cc55cSDimitry Andric    return (__builtin_constant_p(__n) && __n < __min_cap)
23705ffd83dbSDimitry Andric               ? __assign_short(__s, __n)
23715ffd83dbSDimitry Andric               : __assign_external(__s, __n);
23725ffd83dbSDimitry Andric}
23735ffd83dbSDimitry Andric
23745ffd83dbSDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
23755ffd83dbSDimitry Andricbasic_string<_CharT, _Traits, _Allocator>&
23760b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::assign(size_type __n, value_type __c)
23770b57cec5SDimitry Andric{
23780b57cec5SDimitry Andric    size_type __cap = capacity();
23790b57cec5SDimitry Andric    if (__cap < __n)
23800b57cec5SDimitry Andric    {
23810b57cec5SDimitry Andric        size_type __sz = size();
23820b57cec5SDimitry Andric        __grow_by(__cap, __n - __cap, __sz, 0, __sz);
23830b57cec5SDimitry Andric    }
2384480093f4SDimitry Andric    value_type* __p = _VSTD::__to_address(__get_pointer());
23850b57cec5SDimitry Andric    traits_type::assign(__p, __n, __c);
23860b57cec5SDimitry Andric    traits_type::assign(__p[__n], value_type());
23870b57cec5SDimitry Andric    __set_size(__n);
2388fe6060f1SDimitry Andric    __invalidate_iterators_past(__n);
23890b57cec5SDimitry Andric    return *this;
23900b57cec5SDimitry Andric}
23910b57cec5SDimitry Andric
23920b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
23930b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>&
23940b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::operator=(value_type __c)
23950b57cec5SDimitry Andric{
23960b57cec5SDimitry Andric    pointer __p;
23970b57cec5SDimitry Andric    if (__is_long())
23980b57cec5SDimitry Andric    {
23990b57cec5SDimitry Andric        __p = __get_long_pointer();
24000b57cec5SDimitry Andric        __set_long_size(1);
24010b57cec5SDimitry Andric    }
24020b57cec5SDimitry Andric    else
24030b57cec5SDimitry Andric    {
24040b57cec5SDimitry Andric        __p = __get_short_pointer();
24050b57cec5SDimitry Andric        __set_short_size(1);
24060b57cec5SDimitry Andric    }
24070b57cec5SDimitry Andric    traits_type::assign(*__p, __c);
24080b57cec5SDimitry Andric    traits_type::assign(*++__p, value_type());
24090b57cec5SDimitry Andric    __invalidate_iterators_past(1);
24100b57cec5SDimitry Andric    return *this;
24110b57cec5SDimitry Andric}
24120b57cec5SDimitry Andric
24130b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
24140b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>&
24150b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::operator=(const basic_string& __str)
24160b57cec5SDimitry Andric{
24175ffd83dbSDimitry Andric  if (this != &__str) {
24180b57cec5SDimitry Andric    __copy_assign_alloc(__str);
24195ffd83dbSDimitry Andric    if (!__is_long()) {
24205ffd83dbSDimitry Andric      if (!__str.__is_long()) {
24215ffd83dbSDimitry Andric        __r_.first().__r = __str.__r_.first().__r;
24225ffd83dbSDimitry Andric      } else {
24235ffd83dbSDimitry Andric        return __assign_no_alias<true>(__str.data(), __str.size());
24245ffd83dbSDimitry Andric      }
24255ffd83dbSDimitry Andric    } else {
24265ffd83dbSDimitry Andric      return __assign_no_alias<false>(__str.data(), __str.size());
24275ffd83dbSDimitry Andric    }
24280b57cec5SDimitry Andric  }
24290b57cec5SDimitry Andric  return *this;
24300b57cec5SDimitry Andric}
24310b57cec5SDimitry Andric
24320b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
24330b57cec5SDimitry Andric
24340b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
24350b57cec5SDimitry Andricinline
24360b57cec5SDimitry Andricvoid
24370b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, false_type)
24380b57cec5SDimitry Andric    _NOEXCEPT_(__alloc_traits::is_always_equal::value)
24390b57cec5SDimitry Andric{
24400b57cec5SDimitry Andric    if (__alloc() != __str.__alloc())
24410b57cec5SDimitry Andric        assign(__str);
24420b57cec5SDimitry Andric    else
24430b57cec5SDimitry Andric        __move_assign(__str, true_type());
24440b57cec5SDimitry Andric}
24450b57cec5SDimitry Andric
24460b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
24470b57cec5SDimitry Andricinline
24480b57cec5SDimitry Andricvoid
24490b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, true_type)
24500b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 14
24510b57cec5SDimitry Andric    _NOEXCEPT
24520b57cec5SDimitry Andric#else
24530b57cec5SDimitry Andric    _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
24540b57cec5SDimitry Andric#endif
24550b57cec5SDimitry Andric{
2456480093f4SDimitry Andric  if (__is_long()) {
2457480093f4SDimitry Andric    __alloc_traits::deallocate(__alloc(), __get_long_pointer(),
2458480093f4SDimitry Andric                               __get_long_cap());
2459480093f4SDimitry Andric#if _LIBCPP_STD_VER <= 14
2460480093f4SDimitry Andric    if (!is_nothrow_move_assignable<allocator_type>::value) {
2461480093f4SDimitry Andric      __set_short_size(0);
2462480093f4SDimitry Andric      traits_type::assign(__get_short_pointer()[0], value_type());
2463480093f4SDimitry Andric    }
2464480093f4SDimitry Andric#endif
2465480093f4SDimitry Andric  }
24660b57cec5SDimitry Andric  __move_assign_alloc(__str);
2467480093f4SDimitry Andric  __r_.first() = __str.__r_.first();
2468480093f4SDimitry Andric  __str.__set_short_size(0);
2469480093f4SDimitry Andric  traits_type::assign(__str.__get_short_pointer()[0], value_type());
24700b57cec5SDimitry Andric}
24710b57cec5SDimitry Andric
24720b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
24730b57cec5SDimitry Andricinline
24740b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>&
24750b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::operator=(basic_string&& __str)
24760b57cec5SDimitry Andric    _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value))
24770b57cec5SDimitry Andric{
24780b57cec5SDimitry Andric    __move_assign(__str, integral_constant<bool,
24790b57cec5SDimitry Andric          __alloc_traits::propagate_on_container_move_assignment::value>());
24800b57cec5SDimitry Andric    return *this;
24810b57cec5SDimitry Andric}
24820b57cec5SDimitry Andric
24830b57cec5SDimitry Andric#endif
24840b57cec5SDimitry Andric
24850b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
24860b57cec5SDimitry Andrictemplate<class _InputIterator>
2487*349cc55cSDimitry Andric__enable_if_t
24880b57cec5SDimitry Andric<
2489fe6060f1SDimitry Andric     __is_exactly_cpp17_input_iterator<_InputIterator>::value,
24900b57cec5SDimitry Andric    basic_string<_CharT, _Traits, _Allocator>&
24915ffd83dbSDimitry Andric>
24920b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
24930b57cec5SDimitry Andric{
24940b57cec5SDimitry Andric    const basic_string __temp(__first, __last, __alloc());
24950b57cec5SDimitry Andric    assign(__temp.data(), __temp.size());
24960b57cec5SDimitry Andric    return *this;
24970b57cec5SDimitry Andric}
24980b57cec5SDimitry Andric
24990b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
25000b57cec5SDimitry Andrictemplate<class _ForwardIterator>
2501*349cc55cSDimitry Andric__enable_if_t
25020b57cec5SDimitry Andric<
2503fe6060f1SDimitry Andric    __is_cpp17_forward_iterator<_ForwardIterator>::value,
25040b57cec5SDimitry Andric    basic_string<_CharT, _Traits, _Allocator>&
25055ffd83dbSDimitry Andric>
25060b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last)
25070b57cec5SDimitry Andric{
25080b57cec5SDimitry Andric    size_type __cap = capacity();
2509fe6060f1SDimitry Andric    size_type __n = __string_is_trivial_iterator<_ForwardIterator>::value ?
2510fe6060f1SDimitry Andric        static_cast<size_type>(_VSTD::distance(__first, __last)) : 0;
2511fe6060f1SDimitry Andric
2512fe6060f1SDimitry Andric    if (__string_is_trivial_iterator<_ForwardIterator>::value &&
2513fe6060f1SDimitry Andric        (__cap >= __n || !__addr_in_range(*__first)))
2514fe6060f1SDimitry Andric    {
25150b57cec5SDimitry Andric        if (__cap < __n)
25160b57cec5SDimitry Andric        {
25170b57cec5SDimitry Andric            size_type __sz = size();
25180b57cec5SDimitry Andric            __grow_by(__cap, __n - __cap, __sz, 0, __sz);
25190b57cec5SDimitry Andric        }
25200b57cec5SDimitry Andric        pointer __p = __get_pointer();
2521*349cc55cSDimitry Andric        for (; __first != __last; ++__p, (void) ++__first)
25220b57cec5SDimitry Andric            traits_type::assign(*__p, *__first);
25230b57cec5SDimitry Andric        traits_type::assign(*__p, value_type());
25240b57cec5SDimitry Andric        __set_size(__n);
2525fe6060f1SDimitry Andric        __invalidate_iterators_past(__n);
2526fe6060f1SDimitry Andric    }
2527fe6060f1SDimitry Andric    else
2528fe6060f1SDimitry Andric    {
2529fe6060f1SDimitry Andric        const basic_string __temp(__first, __last, __alloc());
2530fe6060f1SDimitry Andric        assign(__temp.data(), __temp.size());
2531fe6060f1SDimitry Andric    }
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>::assign(const basic_string& __str, size_type __pos, size_type __n)
25380b57cec5SDimitry Andric{
25390b57cec5SDimitry Andric    size_type __sz = __str.size();
25400b57cec5SDimitry Andric    if (__pos > __sz)
25410b57cec5SDimitry Andric        this->__throw_out_of_range();
25420b57cec5SDimitry Andric    return assign(__str.data() + __pos, _VSTD::min(__n, __sz - __pos));
25430b57cec5SDimitry Andric}
25440b57cec5SDimitry Andric
25450b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
25460b57cec5SDimitry Andrictemplate <class _Tp>
2547*349cc55cSDimitry Andric__enable_if_t
25480b57cec5SDimitry Andric<
25495ffd83dbSDimitry Andric    __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value
25505ffd83dbSDimitry Andric    && !__is_same_uncvref<_Tp, basic_string<_CharT, _Traits, _Allocator> >::value,
25510b57cec5SDimitry Andric    basic_string<_CharT, _Traits, _Allocator>&
25525ffd83dbSDimitry Andric>
25530b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::assign(const _Tp & __t, size_type __pos, size_type __n)
25540b57cec5SDimitry Andric{
25550b57cec5SDimitry Andric    __self_view __sv = __t;
25560b57cec5SDimitry Andric    size_type __sz = __sv.size();
25570b57cec5SDimitry Andric    if (__pos > __sz)
25580b57cec5SDimitry Andric        this->__throw_out_of_range();
25590b57cec5SDimitry Andric    return assign(__sv.data() + __pos, _VSTD::min(__n, __sz - __pos));
25600b57cec5SDimitry Andric}
25610b57cec5SDimitry Andric
25620b57cec5SDimitry Andric
25630b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
25640b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>&
25655ffd83dbSDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::__assign_external(const value_type* __s) {
25665ffd83dbSDimitry Andric  return __assign_external(__s, traits_type::length(__s));
25675ffd83dbSDimitry Andric}
25685ffd83dbSDimitry Andric
25695ffd83dbSDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
25705ffd83dbSDimitry Andricbasic_string<_CharT, _Traits, _Allocator>&
25710b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s)
25720b57cec5SDimitry Andric{
25730b57cec5SDimitry Andric    _LIBCPP_ASSERT(__s != nullptr, "string::assign received nullptr");
2574*349cc55cSDimitry Andric    return __builtin_constant_p(*__s)
25755ffd83dbSDimitry Andric               ? (traits_type::length(__s) < __min_cap
25765ffd83dbSDimitry Andric                      ? __assign_short(__s, traits_type::length(__s))
25775ffd83dbSDimitry Andric                      : __assign_external(__s, traits_type::length(__s)))
25785ffd83dbSDimitry Andric               : __assign_external(__s);
25790b57cec5SDimitry Andric}
25800b57cec5SDimitry Andric// append
25810b57cec5SDimitry Andric
25820b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
25830b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>&
25840b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s, size_type __n)
25850b57cec5SDimitry Andric{
25860b57cec5SDimitry Andric    _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::append received nullptr");
25870b57cec5SDimitry Andric    size_type __cap = capacity();
25880b57cec5SDimitry Andric    size_type __sz = size();
25890b57cec5SDimitry Andric    if (__cap - __sz >= __n)
25900b57cec5SDimitry Andric    {
25910b57cec5SDimitry Andric        if (__n)
25920b57cec5SDimitry Andric        {
2593480093f4SDimitry Andric            value_type* __p = _VSTD::__to_address(__get_pointer());
25940b57cec5SDimitry Andric            traits_type::copy(__p + __sz, __s, __n);
25950b57cec5SDimitry Andric            __sz += __n;
25960b57cec5SDimitry Andric            __set_size(__sz);
25970b57cec5SDimitry Andric            traits_type::assign(__p[__sz], value_type());
25980b57cec5SDimitry Andric        }
25990b57cec5SDimitry Andric    }
26000b57cec5SDimitry Andric    else
26010b57cec5SDimitry Andric        __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __sz, 0, __n, __s);
26020b57cec5SDimitry Andric    return *this;
26030b57cec5SDimitry Andric}
26040b57cec5SDimitry Andric
26050b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
26060b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>&
26070b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::append(size_type __n, value_type __c)
26080b57cec5SDimitry Andric{
26090b57cec5SDimitry Andric    if (__n)
26100b57cec5SDimitry Andric    {
26110b57cec5SDimitry Andric        size_type __cap = capacity();
26120b57cec5SDimitry Andric        size_type __sz = size();
26130b57cec5SDimitry Andric        if (__cap - __sz < __n)
26140b57cec5SDimitry Andric            __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
26150b57cec5SDimitry Andric        pointer __p = __get_pointer();
2616480093f4SDimitry Andric        traits_type::assign(_VSTD::__to_address(__p) + __sz, __n, __c);
26170b57cec5SDimitry Andric        __sz += __n;
26180b57cec5SDimitry Andric        __set_size(__sz);
26190b57cec5SDimitry Andric        traits_type::assign(__p[__sz], value_type());
26200b57cec5SDimitry Andric    }
26210b57cec5SDimitry Andric    return *this;
26220b57cec5SDimitry Andric}
26230b57cec5SDimitry Andric
26240b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
26250b57cec5SDimitry Andricinline void
26260b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::__append_default_init(size_type __n)
26270b57cec5SDimitry Andric{
26280b57cec5SDimitry Andric    if (__n)
26290b57cec5SDimitry Andric    {
26300b57cec5SDimitry Andric        size_type __cap = capacity();
26310b57cec5SDimitry Andric        size_type __sz = size();
26320b57cec5SDimitry Andric        if (__cap - __sz < __n)
26330b57cec5SDimitry Andric            __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
26340b57cec5SDimitry Andric        pointer __p = __get_pointer();
26350b57cec5SDimitry Andric        __sz += __n;
26360b57cec5SDimitry Andric        __set_size(__sz);
26370b57cec5SDimitry Andric        traits_type::assign(__p[__sz], value_type());
26380b57cec5SDimitry Andric    }
26390b57cec5SDimitry Andric}
26400b57cec5SDimitry Andric
26410b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
26420b57cec5SDimitry Andricvoid
26430b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::push_back(value_type __c)
26440b57cec5SDimitry Andric{
26450b57cec5SDimitry Andric    bool __is_short = !__is_long();
26460b57cec5SDimitry Andric    size_type __cap;
26470b57cec5SDimitry Andric    size_type __sz;
26480b57cec5SDimitry Andric    if (__is_short)
26490b57cec5SDimitry Andric    {
26500b57cec5SDimitry Andric        __cap = __min_cap - 1;
26510b57cec5SDimitry Andric        __sz = __get_short_size();
26520b57cec5SDimitry Andric    }
26530b57cec5SDimitry Andric    else
26540b57cec5SDimitry Andric    {
26550b57cec5SDimitry Andric        __cap = __get_long_cap() - 1;
26560b57cec5SDimitry Andric        __sz = __get_long_size();
26570b57cec5SDimitry Andric    }
26580b57cec5SDimitry Andric    if (__sz == __cap)
26590b57cec5SDimitry Andric    {
26600b57cec5SDimitry Andric        __grow_by(__cap, 1, __sz, __sz, 0);
2661*349cc55cSDimitry Andric        __is_short = false; // the string is always long after __grow_by
26620b57cec5SDimitry Andric    }
26630b57cec5SDimitry Andric    pointer __p;
26640b57cec5SDimitry Andric    if (__is_short)
26650b57cec5SDimitry Andric    {
26660b57cec5SDimitry Andric        __p = __get_short_pointer() + __sz;
26670b57cec5SDimitry Andric        __set_short_size(__sz+1);
26680b57cec5SDimitry Andric    }
26690b57cec5SDimitry Andric    else
26700b57cec5SDimitry Andric    {
26710b57cec5SDimitry Andric        __p = __get_long_pointer() + __sz;
26720b57cec5SDimitry Andric        __set_long_size(__sz+1);
26730b57cec5SDimitry Andric    }
26740b57cec5SDimitry Andric    traits_type::assign(*__p, __c);
26750b57cec5SDimitry Andric    traits_type::assign(*++__p, value_type());
26760b57cec5SDimitry Andric}
26770b57cec5SDimitry Andric
26780b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
26790b57cec5SDimitry Andrictemplate<class _ForwardIterator>
2680*349cc55cSDimitry Andric__enable_if_t
2681fe6060f1SDimitry Andric<
2682fe6060f1SDimitry Andric    __is_cpp17_forward_iterator<_ForwardIterator>::value,
26830b57cec5SDimitry Andric    basic_string<_CharT, _Traits, _Allocator>&
2684fe6060f1SDimitry Andric>
2685fe6060f1SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::append(
26860b57cec5SDimitry Andric    _ForwardIterator __first, _ForwardIterator __last)
26870b57cec5SDimitry Andric{
26880b57cec5SDimitry Andric    size_type __sz = size();
26890b57cec5SDimitry Andric    size_type __cap = capacity();
26900b57cec5SDimitry Andric    size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
26910b57cec5SDimitry Andric    if (__n)
26920b57cec5SDimitry Andric    {
2693fe6060f1SDimitry Andric        if (__string_is_trivial_iterator<_ForwardIterator>::value &&
2694fe6060f1SDimitry Andric            !__addr_in_range(*__first))
26950b57cec5SDimitry Andric        {
26960b57cec5SDimitry Andric            if (__cap - __sz < __n)
26970b57cec5SDimitry Andric                __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
26980b57cec5SDimitry Andric            pointer __p = __get_pointer() + __sz;
2699*349cc55cSDimitry Andric            for (; __first != __last; ++__p, (void) ++__first)
27000b57cec5SDimitry Andric                traits_type::assign(*__p, *__first);
27010b57cec5SDimitry Andric            traits_type::assign(*__p, value_type());
27020b57cec5SDimitry Andric            __set_size(__sz + __n);
27030b57cec5SDimitry Andric        }
2704fe6060f1SDimitry Andric        else
2705fe6060f1SDimitry Andric        {
2706fe6060f1SDimitry Andric            const basic_string __temp(__first, __last, __alloc());
2707fe6060f1SDimitry Andric            append(__temp.data(), __temp.size());
2708fe6060f1SDimitry Andric        }
27090b57cec5SDimitry Andric    }
27100b57cec5SDimitry Andric    return *this;
27110b57cec5SDimitry Andric}
27120b57cec5SDimitry Andric
27130b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
27140b57cec5SDimitry Andricinline
27150b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>&
27160b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str)
27170b57cec5SDimitry Andric{
27180b57cec5SDimitry Andric    return append(__str.data(), __str.size());
27190b57cec5SDimitry Andric}
27200b57cec5SDimitry Andric
27210b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
27220b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>&
27230b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str, size_type __pos, size_type __n)
27240b57cec5SDimitry Andric{
27250b57cec5SDimitry Andric    size_type __sz = __str.size();
27260b57cec5SDimitry Andric    if (__pos > __sz)
27270b57cec5SDimitry Andric        this->__throw_out_of_range();
27280b57cec5SDimitry Andric    return append(__str.data() + __pos, _VSTD::min(__n, __sz - __pos));
27290b57cec5SDimitry Andric}
27300b57cec5SDimitry Andric
27310b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
27320b57cec5SDimitry Andrictemplate <class _Tp>
2733*349cc55cSDimitry Andric    __enable_if_t
27340b57cec5SDimitry Andric    <
27355ffd83dbSDimitry Andric        __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value  && !__is_same_uncvref<_Tp, basic_string<_CharT, _Traits, _Allocator> >::value,
27360b57cec5SDimitry Andric        basic_string<_CharT, _Traits, _Allocator>&
27375ffd83dbSDimitry Andric    >
27380b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::append(const _Tp & __t, size_type __pos, size_type __n)
27390b57cec5SDimitry Andric{
27400b57cec5SDimitry Andric    __self_view __sv = __t;
27410b57cec5SDimitry Andric    size_type __sz = __sv.size();
27420b57cec5SDimitry Andric    if (__pos > __sz)
27430b57cec5SDimitry Andric        this->__throw_out_of_range();
27440b57cec5SDimitry Andric    return append(__sv.data() + __pos, _VSTD::min(__n, __sz - __pos));
27450b57cec5SDimitry Andric}
27460b57cec5SDimitry Andric
27470b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
27480b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>&
27490b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s)
27500b57cec5SDimitry Andric{
27510b57cec5SDimitry Andric    _LIBCPP_ASSERT(__s != nullptr, "string::append received nullptr");
27520b57cec5SDimitry Andric    return append(__s, traits_type::length(__s));
27530b57cec5SDimitry Andric}
27540b57cec5SDimitry Andric
27550b57cec5SDimitry Andric// insert
27560b57cec5SDimitry Andric
27570b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
27580b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>&
27590b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s, size_type __n)
27600b57cec5SDimitry Andric{
27610b57cec5SDimitry Andric    _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::insert received nullptr");
27620b57cec5SDimitry Andric    size_type __sz = size();
27630b57cec5SDimitry Andric    if (__pos > __sz)
27640b57cec5SDimitry Andric        this->__throw_out_of_range();
27650b57cec5SDimitry Andric    size_type __cap = capacity();
27660b57cec5SDimitry Andric    if (__cap - __sz >= __n)
27670b57cec5SDimitry Andric    {
27680b57cec5SDimitry Andric        if (__n)
27690b57cec5SDimitry Andric        {
2770480093f4SDimitry Andric            value_type* __p = _VSTD::__to_address(__get_pointer());
27710b57cec5SDimitry Andric            size_type __n_move = __sz - __pos;
27720b57cec5SDimitry Andric            if (__n_move != 0)
27730b57cec5SDimitry Andric            {
27740b57cec5SDimitry Andric                if (__p + __pos <= __s && __s < __p + __sz)
27750b57cec5SDimitry Andric                    __s += __n;
27760b57cec5SDimitry Andric                traits_type::move(__p + __pos + __n, __p + __pos, __n_move);
27770b57cec5SDimitry Andric            }
27780b57cec5SDimitry Andric            traits_type::move(__p + __pos, __s, __n);
27790b57cec5SDimitry Andric            __sz += __n;
27800b57cec5SDimitry Andric            __set_size(__sz);
27810b57cec5SDimitry Andric            traits_type::assign(__p[__sz], value_type());
27820b57cec5SDimitry Andric        }
27830b57cec5SDimitry Andric    }
27840b57cec5SDimitry Andric    else
27850b57cec5SDimitry Andric        __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __pos, 0, __n, __s);
27860b57cec5SDimitry Andric    return *this;
27870b57cec5SDimitry Andric}
27880b57cec5SDimitry Andric
27890b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
27900b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>&
27910b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, size_type __n, value_type __c)
27920b57cec5SDimitry Andric{
27930b57cec5SDimitry Andric    size_type __sz = size();
27940b57cec5SDimitry Andric    if (__pos > __sz)
27950b57cec5SDimitry Andric        this->__throw_out_of_range();
27960b57cec5SDimitry Andric    if (__n)
27970b57cec5SDimitry Andric    {
27980b57cec5SDimitry Andric        size_type __cap = capacity();
27990b57cec5SDimitry Andric        value_type* __p;
28000b57cec5SDimitry Andric        if (__cap - __sz >= __n)
28010b57cec5SDimitry Andric        {
2802480093f4SDimitry Andric            __p = _VSTD::__to_address(__get_pointer());
28030b57cec5SDimitry Andric            size_type __n_move = __sz - __pos;
28040b57cec5SDimitry Andric            if (__n_move != 0)
28050b57cec5SDimitry Andric                traits_type::move(__p + __pos + __n, __p + __pos, __n_move);
28060b57cec5SDimitry Andric        }
28070b57cec5SDimitry Andric        else
28080b57cec5SDimitry Andric        {
28090b57cec5SDimitry Andric            __grow_by(__cap, __sz + __n - __cap, __sz, __pos, 0, __n);
2810480093f4SDimitry Andric            __p = _VSTD::__to_address(__get_long_pointer());
28110b57cec5SDimitry Andric        }
28120b57cec5SDimitry Andric        traits_type::assign(__p + __pos, __n, __c);
28130b57cec5SDimitry Andric        __sz += __n;
28140b57cec5SDimitry Andric        __set_size(__sz);
28150b57cec5SDimitry Andric        traits_type::assign(__p[__sz], value_type());
28160b57cec5SDimitry Andric    }
28170b57cec5SDimitry Andric    return *this;
28180b57cec5SDimitry Andric}
28190b57cec5SDimitry Andric
28200b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
28210b57cec5SDimitry Andrictemplate<class _InputIterator>
2822*349cc55cSDimitry Andric__enable_if_t
28230b57cec5SDimitry Andric<
2824fe6060f1SDimitry Andric   __is_exactly_cpp17_input_iterator<_InputIterator>::value,
28250b57cec5SDimitry Andric   typename basic_string<_CharT, _Traits, _Allocator>::iterator
28265ffd83dbSDimitry Andric>
28270b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _InputIterator __first, _InputIterator __last)
28280b57cec5SDimitry Andric{
2829e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2
28300b57cec5SDimitry Andric    _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
28310b57cec5SDimitry Andric        "string::insert(iterator, range) called with an iterator not"
28320b57cec5SDimitry Andric        " referring to this string");
28330b57cec5SDimitry Andric#endif
28340b57cec5SDimitry Andric    const basic_string __temp(__first, __last, __alloc());
28350b57cec5SDimitry Andric    return insert(__pos, __temp.data(), __temp.data() + __temp.size());
28360b57cec5SDimitry Andric}
28370b57cec5SDimitry Andric
28380b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
28390b57cec5SDimitry Andrictemplate<class _ForwardIterator>
2840*349cc55cSDimitry Andric__enable_if_t
28410b57cec5SDimitry Andric<
2842fe6060f1SDimitry Andric    __is_cpp17_forward_iterator<_ForwardIterator>::value,
28430b57cec5SDimitry Andric    typename basic_string<_CharT, _Traits, _Allocator>::iterator
28445ffd83dbSDimitry Andric>
28450b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last)
28460b57cec5SDimitry Andric{
2847e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2
28480b57cec5SDimitry Andric    _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
28490b57cec5SDimitry Andric        "string::insert(iterator, range) called with an iterator not"
28500b57cec5SDimitry Andric        " referring to this string");
28510b57cec5SDimitry Andric#endif
28520b57cec5SDimitry Andric    size_type __ip = static_cast<size_type>(__pos - begin());
28530b57cec5SDimitry Andric    size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
28540b57cec5SDimitry Andric    if (__n)
28550b57cec5SDimitry Andric    {
2856fe6060f1SDimitry Andric        if (__string_is_trivial_iterator<_ForwardIterator>::value &&
2857fe6060f1SDimitry Andric            !__addr_in_range(*__first))
28580b57cec5SDimitry Andric        {
28590b57cec5SDimitry Andric            size_type __sz = size();
28600b57cec5SDimitry Andric            size_type __cap = capacity();
28610b57cec5SDimitry Andric            value_type* __p;
28620b57cec5SDimitry Andric            if (__cap - __sz >= __n)
28630b57cec5SDimitry Andric            {
2864480093f4SDimitry Andric                __p = _VSTD::__to_address(__get_pointer());
28650b57cec5SDimitry Andric                size_type __n_move = __sz - __ip;
28660b57cec5SDimitry Andric                if (__n_move != 0)
28670b57cec5SDimitry Andric                    traits_type::move(__p + __ip + __n, __p + __ip, __n_move);
28680b57cec5SDimitry Andric            }
28690b57cec5SDimitry Andric            else
28700b57cec5SDimitry Andric            {
28710b57cec5SDimitry Andric                __grow_by(__cap, __sz + __n - __cap, __sz, __ip, 0, __n);
2872480093f4SDimitry Andric                __p = _VSTD::__to_address(__get_long_pointer());
28730b57cec5SDimitry Andric            }
28740b57cec5SDimitry Andric            __sz += __n;
28750b57cec5SDimitry Andric            __set_size(__sz);
28760b57cec5SDimitry Andric            traits_type::assign(__p[__sz], value_type());
2877*349cc55cSDimitry Andric            for (__p += __ip; __first != __last; ++__p, (void) ++__first)
28780b57cec5SDimitry Andric                traits_type::assign(*__p, *__first);
28790b57cec5SDimitry Andric        }
2880fe6060f1SDimitry Andric        else
2881fe6060f1SDimitry Andric        {
2882fe6060f1SDimitry Andric            const basic_string __temp(__first, __last, __alloc());
2883fe6060f1SDimitry Andric            return insert(__pos, __temp.data(), __temp.data() + __temp.size());
2884fe6060f1SDimitry Andric        }
2885fe6060f1SDimitry Andric    }
28860b57cec5SDimitry Andric    return begin() + __ip;
28870b57cec5SDimitry Andric}
28880b57cec5SDimitry Andric
28890b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
28900b57cec5SDimitry Andricinline
28910b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>&
28920b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str)
28930b57cec5SDimitry Andric{
28940b57cec5SDimitry Andric    return insert(__pos1, __str.data(), __str.size());
28950b57cec5SDimitry Andric}
28960b57cec5SDimitry Andric
28970b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
28980b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>&
28990b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str,
29000b57cec5SDimitry Andric                                                  size_type __pos2, size_type __n)
29010b57cec5SDimitry Andric{
29020b57cec5SDimitry Andric    size_type __str_sz = __str.size();
29030b57cec5SDimitry Andric    if (__pos2 > __str_sz)
29040b57cec5SDimitry Andric        this->__throw_out_of_range();
29050b57cec5SDimitry Andric    return insert(__pos1, __str.data() + __pos2, _VSTD::min(__n, __str_sz - __pos2));
29060b57cec5SDimitry Andric}
29070b57cec5SDimitry Andric
29080b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
29090b57cec5SDimitry Andrictemplate <class _Tp>
2910*349cc55cSDimitry Andric__enable_if_t
29110b57cec5SDimitry Andric<
29125ffd83dbSDimitry Andric    __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value  && !__is_same_uncvref<_Tp, basic_string<_CharT, _Traits, _Allocator> >::value,
29130b57cec5SDimitry Andric    basic_string<_CharT, _Traits, _Allocator>&
29145ffd83dbSDimitry Andric>
29150b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const _Tp& __t,
29160b57cec5SDimitry Andric                                                  size_type __pos2, size_type __n)
29170b57cec5SDimitry Andric{
29180b57cec5SDimitry Andric    __self_view __sv = __t;
29190b57cec5SDimitry Andric    size_type __str_sz = __sv.size();
29200b57cec5SDimitry Andric    if (__pos2 > __str_sz)
29210b57cec5SDimitry Andric        this->__throw_out_of_range();
29220b57cec5SDimitry Andric    return insert(__pos1, __sv.data() + __pos2, _VSTD::min(__n, __str_sz - __pos2));
29230b57cec5SDimitry Andric}
29240b57cec5SDimitry Andric
29250b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
29260b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>&
29270b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s)
29280b57cec5SDimitry Andric{
29290b57cec5SDimitry Andric    _LIBCPP_ASSERT(__s != nullptr, "string::insert received nullptr");
29300b57cec5SDimitry Andric    return insert(__pos, __s, traits_type::length(__s));
29310b57cec5SDimitry Andric}
29320b57cec5SDimitry Andric
29330b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
29340b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::iterator
29350b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, value_type __c)
29360b57cec5SDimitry Andric{
29370b57cec5SDimitry Andric    size_type __ip = static_cast<size_type>(__pos - begin());
29380b57cec5SDimitry Andric    size_type __sz = size();
29390b57cec5SDimitry Andric    size_type __cap = capacity();
29400b57cec5SDimitry Andric    value_type* __p;
29410b57cec5SDimitry Andric    if (__cap == __sz)
29420b57cec5SDimitry Andric    {
29430b57cec5SDimitry Andric        __grow_by(__cap, 1, __sz, __ip, 0, 1);
2944480093f4SDimitry Andric        __p = _VSTD::__to_address(__get_long_pointer());
29450b57cec5SDimitry Andric    }
29460b57cec5SDimitry Andric    else
29470b57cec5SDimitry Andric    {
2948480093f4SDimitry Andric        __p = _VSTD::__to_address(__get_pointer());
29490b57cec5SDimitry Andric        size_type __n_move = __sz - __ip;
29500b57cec5SDimitry Andric        if (__n_move != 0)
29510b57cec5SDimitry Andric            traits_type::move(__p + __ip + 1, __p + __ip, __n_move);
29520b57cec5SDimitry Andric    }
29530b57cec5SDimitry Andric    traits_type::assign(__p[__ip], __c);
29540b57cec5SDimitry Andric    traits_type::assign(__p[++__sz], value_type());
29550b57cec5SDimitry Andric    __set_size(__sz);
29560b57cec5SDimitry Andric    return begin() + static_cast<difference_type>(__ip);
29570b57cec5SDimitry Andric}
29580b57cec5SDimitry Andric
29590b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
29600b57cec5SDimitry Andricinline
29610b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::iterator
29620b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, size_type __n, value_type __c)
29630b57cec5SDimitry Andric{
2964e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2
29650b57cec5SDimitry Andric    _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
29660b57cec5SDimitry Andric        "string::insert(iterator, n, value) called with an iterator not"
29670b57cec5SDimitry Andric        " referring to this string");
29680b57cec5SDimitry Andric#endif
29690b57cec5SDimitry Andric    difference_type __p = __pos - begin();
29700b57cec5SDimitry Andric    insert(static_cast<size_type>(__p), __n, __c);
29710b57cec5SDimitry Andric    return begin() + __p;
29720b57cec5SDimitry Andric}
29730b57cec5SDimitry Andric
29740b57cec5SDimitry Andric// replace
29750b57cec5SDimitry Andric
29760b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
29770b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>&
29780b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, const value_type* __s, size_type __n2)
29790b57cec5SDimitry Andric    _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
29800b57cec5SDimitry Andric{
29810b57cec5SDimitry Andric    _LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::replace received nullptr");
29820b57cec5SDimitry Andric    size_type __sz = size();
29830b57cec5SDimitry Andric    if (__pos > __sz)
29840b57cec5SDimitry Andric        this->__throw_out_of_range();
29850b57cec5SDimitry Andric    __n1 = _VSTD::min(__n1, __sz - __pos);
29860b57cec5SDimitry Andric    size_type __cap = capacity();
29870b57cec5SDimitry Andric    if (__cap - __sz + __n1 >= __n2)
29880b57cec5SDimitry Andric    {
2989480093f4SDimitry Andric        value_type* __p = _VSTD::__to_address(__get_pointer());
29900b57cec5SDimitry Andric        if (__n1 != __n2)
29910b57cec5SDimitry Andric        {
29920b57cec5SDimitry Andric            size_type __n_move = __sz - __pos - __n1;
29930b57cec5SDimitry Andric            if (__n_move != 0)
29940b57cec5SDimitry Andric            {
29950b57cec5SDimitry Andric                if (__n1 > __n2)
29960b57cec5SDimitry Andric                {
29970b57cec5SDimitry Andric                    traits_type::move(__p + __pos, __s, __n2);
29980b57cec5SDimitry Andric                    traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
29990b57cec5SDimitry Andric                    goto __finish;
30000b57cec5SDimitry Andric                }
30010b57cec5SDimitry Andric                if (__p + __pos < __s && __s < __p + __sz)
30020b57cec5SDimitry Andric                {
30030b57cec5SDimitry Andric                    if (__p + __pos + __n1 <= __s)
30040b57cec5SDimitry Andric                        __s += __n2 - __n1;
30050b57cec5SDimitry Andric                    else // __p + __pos < __s < __p + __pos + __n1
30060b57cec5SDimitry Andric                    {
30070b57cec5SDimitry Andric                        traits_type::move(__p + __pos, __s, __n1);
30080b57cec5SDimitry Andric                        __pos += __n1;
30090b57cec5SDimitry Andric                        __s += __n2;
30100b57cec5SDimitry Andric                        __n2 -= __n1;
30110b57cec5SDimitry Andric                        __n1 = 0;
30120b57cec5SDimitry Andric                    }
30130b57cec5SDimitry Andric                }
30140b57cec5SDimitry Andric                traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
30150b57cec5SDimitry Andric            }
30160b57cec5SDimitry Andric        }
30170b57cec5SDimitry Andric        traits_type::move(__p + __pos, __s, __n2);
30180b57cec5SDimitry Andric__finish:
30195ffd83dbSDimitry Andric// __sz += __n2 - __n1; in this and the below function below can cause unsigned
30205ffd83dbSDimitry Andric// integer overflow, but this is a safe operation, so we disable the check.
30210b57cec5SDimitry Andric        __sz += __n2 - __n1;
30220b57cec5SDimitry Andric        __set_size(__sz);
30230b57cec5SDimitry Andric        __invalidate_iterators_past(__sz);
30240b57cec5SDimitry Andric        traits_type::assign(__p[__sz], value_type());
30250b57cec5SDimitry Andric    }
30260b57cec5SDimitry Andric    else
30270b57cec5SDimitry Andric        __grow_by_and_replace(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2, __s);
30280b57cec5SDimitry Andric    return *this;
30290b57cec5SDimitry Andric}
30300b57cec5SDimitry Andric
30310b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
30320b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>&
30330b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, size_type __n2, value_type __c)
30340b57cec5SDimitry Andric    _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
30350b57cec5SDimitry Andric{
30360b57cec5SDimitry Andric    size_type __sz = size();
30370b57cec5SDimitry Andric    if (__pos > __sz)
30380b57cec5SDimitry Andric        this->__throw_out_of_range();
30390b57cec5SDimitry Andric    __n1 = _VSTD::min(__n1, __sz - __pos);
30400b57cec5SDimitry Andric    size_type __cap = capacity();
30410b57cec5SDimitry Andric    value_type* __p;
30420b57cec5SDimitry Andric    if (__cap - __sz + __n1 >= __n2)
30430b57cec5SDimitry Andric    {
3044480093f4SDimitry Andric        __p = _VSTD::__to_address(__get_pointer());
30450b57cec5SDimitry Andric        if (__n1 != __n2)
30460b57cec5SDimitry Andric        {
30470b57cec5SDimitry Andric            size_type __n_move = __sz - __pos - __n1;
30480b57cec5SDimitry Andric            if (__n_move != 0)
30490b57cec5SDimitry Andric                traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
30500b57cec5SDimitry Andric        }
30510b57cec5SDimitry Andric    }
30520b57cec5SDimitry Andric    else
30530b57cec5SDimitry Andric    {
30540b57cec5SDimitry Andric        __grow_by(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2);
3055480093f4SDimitry Andric        __p = _VSTD::__to_address(__get_long_pointer());
30560b57cec5SDimitry Andric    }
30570b57cec5SDimitry Andric    traits_type::assign(__p + __pos, __n2, __c);
30580b57cec5SDimitry Andric    __sz += __n2 - __n1;
30590b57cec5SDimitry Andric    __set_size(__sz);
30600b57cec5SDimitry Andric    __invalidate_iterators_past(__sz);
30610b57cec5SDimitry Andric    traits_type::assign(__p[__sz], value_type());
30620b57cec5SDimitry Andric    return *this;
30630b57cec5SDimitry Andric}
30640b57cec5SDimitry Andric
30650b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
30660b57cec5SDimitry Andrictemplate<class _InputIterator>
3067*349cc55cSDimitry Andric__enable_if_t
30680b57cec5SDimitry Andric<
3069480093f4SDimitry Andric    __is_cpp17_input_iterator<_InputIterator>::value,
30700b57cec5SDimitry Andric    basic_string<_CharT, _Traits, _Allocator>&
30715ffd83dbSDimitry Andric>
30720b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2,
30730b57cec5SDimitry Andric                                                   _InputIterator __j1, _InputIterator __j2)
30740b57cec5SDimitry Andric{
30750b57cec5SDimitry Andric    const basic_string __temp(__j1, __j2, __alloc());
30760b57cec5SDimitry Andric    return this->replace(__i1, __i2, __temp);
30770b57cec5SDimitry Andric}
30780b57cec5SDimitry Andric
30790b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
30800b57cec5SDimitry Andricinline
30810b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>&
30820b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str)
30830b57cec5SDimitry Andric{
30840b57cec5SDimitry Andric    return replace(__pos1, __n1, __str.data(), __str.size());
30850b57cec5SDimitry Andric}
30860b57cec5SDimitry Andric
30870b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
30880b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>&
30890b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str,
30900b57cec5SDimitry Andric                                                   size_type __pos2, size_type __n2)
30910b57cec5SDimitry Andric{
30920b57cec5SDimitry Andric    size_type __str_sz = __str.size();
30930b57cec5SDimitry Andric    if (__pos2 > __str_sz)
30940b57cec5SDimitry Andric        this->__throw_out_of_range();
30950b57cec5SDimitry Andric    return replace(__pos1, __n1, __str.data() + __pos2, _VSTD::min(__n2, __str_sz - __pos2));
30960b57cec5SDimitry Andric}
30970b57cec5SDimitry Andric
30980b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
30990b57cec5SDimitry Andrictemplate <class _Tp>
3100*349cc55cSDimitry Andric__enable_if_t
31010b57cec5SDimitry Andric<
31025ffd83dbSDimitry Andric    __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && !__is_same_uncvref<_Tp, basic_string<_CharT, _Traits, _Allocator> >::value,
31030b57cec5SDimitry Andric    basic_string<_CharT, _Traits, _Allocator>&
31045ffd83dbSDimitry Andric>
31050b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const _Tp& __t,
31060b57cec5SDimitry Andric                                                   size_type __pos2, size_type __n2)
31070b57cec5SDimitry Andric{
31080b57cec5SDimitry Andric    __self_view __sv = __t;
31090b57cec5SDimitry Andric    size_type __str_sz = __sv.size();
31100b57cec5SDimitry Andric    if (__pos2 > __str_sz)
31110b57cec5SDimitry Andric        this->__throw_out_of_range();
31120b57cec5SDimitry Andric    return replace(__pos1, __n1, __sv.data() + __pos2, _VSTD::min(__n2, __str_sz - __pos2));
31130b57cec5SDimitry Andric}
31140b57cec5SDimitry Andric
31150b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
31160b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>&
31170b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, const value_type* __s)
31180b57cec5SDimitry Andric{
31190b57cec5SDimitry Andric    _LIBCPP_ASSERT(__s != nullptr, "string::replace received nullptr");
31200b57cec5SDimitry Andric    return replace(__pos, __n1, __s, traits_type::length(__s));
31210b57cec5SDimitry Andric}
31220b57cec5SDimitry Andric
31230b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
31240b57cec5SDimitry Andricinline
31250b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>&
31260b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const basic_string& __str)
31270b57cec5SDimitry Andric{
31280b57cec5SDimitry Andric    return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1),
31290b57cec5SDimitry Andric                   __str.data(), __str.size());
31300b57cec5SDimitry Andric}
31310b57cec5SDimitry Andric
31320b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
31330b57cec5SDimitry Andricinline
31340b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>&
31350b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const value_type* __s, size_type __n)
31360b57cec5SDimitry Andric{
31370b57cec5SDimitry Andric    return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s, __n);
31380b57cec5SDimitry Andric}
31390b57cec5SDimitry Andric
31400b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
31410b57cec5SDimitry Andricinline
31420b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>&
31430b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const value_type* __s)
31440b57cec5SDimitry Andric{
31450b57cec5SDimitry Andric    return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s);
31460b57cec5SDimitry Andric}
31470b57cec5SDimitry Andric
31480b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
31490b57cec5SDimitry Andricinline
31500b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>&
31510b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c)
31520b57cec5SDimitry Andric{
31530b57cec5SDimitry Andric    return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __n, __c);
31540b57cec5SDimitry Andric}
31550b57cec5SDimitry Andric
31560b57cec5SDimitry Andric// erase
31570b57cec5SDimitry Andric
31585ffd83dbSDimitry Andric// 'externally instantiated' erase() implementation, called when __n != npos.
31595ffd83dbSDimitry Andric// Does not check __pos against size()
31600b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
31615ffd83dbSDimitry Andricvoid
31625ffd83dbSDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::__erase_external_with_move(
31635ffd83dbSDimitry Andric    size_type __pos, size_type __n)
31640b57cec5SDimitry Andric{
31650b57cec5SDimitry Andric    if (__n)
31660b57cec5SDimitry Andric    {
31675ffd83dbSDimitry Andric        size_type __sz = size();
3168480093f4SDimitry Andric        value_type* __p = _VSTD::__to_address(__get_pointer());
31690b57cec5SDimitry Andric        __n = _VSTD::min(__n, __sz - __pos);
31700b57cec5SDimitry Andric        size_type __n_move = __sz - __pos - __n;
31710b57cec5SDimitry Andric        if (__n_move != 0)
31720b57cec5SDimitry Andric            traits_type::move(__p + __pos, __p + __pos + __n, __n_move);
31730b57cec5SDimitry Andric        __sz -= __n;
31740b57cec5SDimitry Andric        __set_size(__sz);
31750b57cec5SDimitry Andric        __invalidate_iterators_past(__sz);
31760b57cec5SDimitry Andric        traits_type::assign(__p[__sz], value_type());
31770b57cec5SDimitry Andric    }
31785ffd83dbSDimitry Andric}
31795ffd83dbSDimitry Andric
31805ffd83dbSDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
31815ffd83dbSDimitry Andricbasic_string<_CharT, _Traits, _Allocator>&
31825ffd83dbSDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::erase(size_type __pos,
31835ffd83dbSDimitry Andric                                                 size_type __n) {
31845ffd83dbSDimitry Andric  if (__pos > size()) this->__throw_out_of_range();
31855ffd83dbSDimitry Andric  if (__n == npos) {
31865ffd83dbSDimitry Andric    __erase_to_end(__pos);
31875ffd83dbSDimitry Andric  } else {
31885ffd83dbSDimitry Andric    __erase_external_with_move(__pos, __n);
31895ffd83dbSDimitry Andric  }
31900b57cec5SDimitry Andric  return *this;
31910b57cec5SDimitry Andric}
31920b57cec5SDimitry Andric
31930b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
31940b57cec5SDimitry Andricinline
31950b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::iterator
31960b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __pos)
31970b57cec5SDimitry Andric{
3198e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2
31990b57cec5SDimitry Andric    _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
32000b57cec5SDimitry Andric        "string::erase(iterator) called with an iterator not"
32010b57cec5SDimitry Andric        " referring to this string");
32020b57cec5SDimitry Andric#endif
32030b57cec5SDimitry Andric    _LIBCPP_ASSERT(__pos != end(),
32040b57cec5SDimitry Andric        "string::erase(iterator) called with a non-dereferenceable iterator");
32050b57cec5SDimitry Andric    iterator __b = begin();
32060b57cec5SDimitry Andric    size_type __r = static_cast<size_type>(__pos - __b);
32070b57cec5SDimitry Andric    erase(__r, 1);
32080b57cec5SDimitry Andric    return __b + static_cast<difference_type>(__r);
32090b57cec5SDimitry Andric}
32100b57cec5SDimitry Andric
32110b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
32120b57cec5SDimitry Andricinline
32130b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::iterator
32140b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __first, const_iterator __last)
32150b57cec5SDimitry Andric{
3216e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2
32170b57cec5SDimitry Andric    _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__first) == this,
32180b57cec5SDimitry Andric        "string::erase(iterator,  iterator) called with an iterator not"
32190b57cec5SDimitry Andric        " referring to this string");
32200b57cec5SDimitry Andric#endif
32210b57cec5SDimitry Andric    _LIBCPP_ASSERT(__first <= __last, "string::erase(first, last) called with invalid range");
32220b57cec5SDimitry Andric    iterator __b = begin();
32230b57cec5SDimitry Andric    size_type __r = static_cast<size_type>(__first - __b);
32240b57cec5SDimitry Andric    erase(__r, static_cast<size_type>(__last - __first));
32250b57cec5SDimitry Andric    return __b + static_cast<difference_type>(__r);
32260b57cec5SDimitry Andric}
32270b57cec5SDimitry Andric
32280b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
32290b57cec5SDimitry Andricinline
32300b57cec5SDimitry Andricvoid
32310b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::pop_back()
32320b57cec5SDimitry Andric{
32330b57cec5SDimitry Andric    _LIBCPP_ASSERT(!empty(), "string::pop_back(): string is already empty");
32340b57cec5SDimitry Andric    size_type __sz;
32350b57cec5SDimitry Andric    if (__is_long())
32360b57cec5SDimitry Andric    {
32370b57cec5SDimitry Andric        __sz = __get_long_size() - 1;
32380b57cec5SDimitry Andric        __set_long_size(__sz);
32390b57cec5SDimitry Andric        traits_type::assign(*(__get_long_pointer() + __sz), value_type());
32400b57cec5SDimitry Andric    }
32410b57cec5SDimitry Andric    else
32420b57cec5SDimitry Andric    {
32430b57cec5SDimitry Andric        __sz = __get_short_size() - 1;
32440b57cec5SDimitry Andric        __set_short_size(__sz);
32450b57cec5SDimitry Andric        traits_type::assign(*(__get_short_pointer() + __sz), value_type());
32460b57cec5SDimitry Andric    }
32470b57cec5SDimitry Andric    __invalidate_iterators_past(__sz);
32480b57cec5SDimitry Andric}
32490b57cec5SDimitry Andric
32500b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
32510b57cec5SDimitry Andricinline
32520b57cec5SDimitry Andricvoid
32530b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::clear() _NOEXCEPT
32540b57cec5SDimitry Andric{
32550b57cec5SDimitry Andric    __invalidate_all_iterators();
32560b57cec5SDimitry Andric    if (__is_long())
32570b57cec5SDimitry Andric    {
32580b57cec5SDimitry Andric        traits_type::assign(*__get_long_pointer(), value_type());
32590b57cec5SDimitry Andric        __set_long_size(0);
32600b57cec5SDimitry Andric    }
32610b57cec5SDimitry Andric    else
32620b57cec5SDimitry Andric    {
32630b57cec5SDimitry Andric        traits_type::assign(*__get_short_pointer(), value_type());
32640b57cec5SDimitry Andric        __set_short_size(0);
32650b57cec5SDimitry Andric    }
32660b57cec5SDimitry Andric}
32670b57cec5SDimitry Andric
32680b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
32690b57cec5SDimitry Andricinline
32700b57cec5SDimitry Andricvoid
32710b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::__erase_to_end(size_type __pos)
32720b57cec5SDimitry Andric{
32730b57cec5SDimitry Andric    if (__is_long())
32740b57cec5SDimitry Andric    {
32750b57cec5SDimitry Andric        traits_type::assign(*(__get_long_pointer() + __pos), value_type());
32760b57cec5SDimitry Andric        __set_long_size(__pos);
32770b57cec5SDimitry Andric    }
32780b57cec5SDimitry Andric    else
32790b57cec5SDimitry Andric    {
32800b57cec5SDimitry Andric        traits_type::assign(*(__get_short_pointer() + __pos), value_type());
32810b57cec5SDimitry Andric        __set_short_size(__pos);
32820b57cec5SDimitry Andric    }
32830b57cec5SDimitry Andric    __invalidate_iterators_past(__pos);
32840b57cec5SDimitry Andric}
32850b57cec5SDimitry Andric
32860b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
32870b57cec5SDimitry Andricvoid
32880b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::resize(size_type __n, value_type __c)
32890b57cec5SDimitry Andric{
32900b57cec5SDimitry Andric    size_type __sz = size();
32910b57cec5SDimitry Andric    if (__n > __sz)
32920b57cec5SDimitry Andric        append(__n - __sz, __c);
32930b57cec5SDimitry Andric    else
32940b57cec5SDimitry Andric        __erase_to_end(__n);
32950b57cec5SDimitry Andric}
32960b57cec5SDimitry Andric
32970b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
32980b57cec5SDimitry Andricinline void
32990b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::__resize_default_init(size_type __n)
33000b57cec5SDimitry Andric{
33010b57cec5SDimitry Andric    size_type __sz = size();
33020b57cec5SDimitry Andric    if (__n > __sz) {
33030b57cec5SDimitry Andric       __append_default_init(__n - __sz);
33040b57cec5SDimitry Andric    } else
33050b57cec5SDimitry Andric        __erase_to_end(__n);
33060b57cec5SDimitry Andric}
33070b57cec5SDimitry Andric
33080b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
33090b57cec5SDimitry Andricinline
33100b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::size_type
33110b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::max_size() const _NOEXCEPT
33120b57cec5SDimitry Andric{
33130b57cec5SDimitry Andric    size_type __m = __alloc_traits::max_size(__alloc());
33140b57cec5SDimitry Andric#ifdef _LIBCPP_BIG_ENDIAN
33150b57cec5SDimitry Andric    return (__m <= ~__long_mask ? __m : __m/2) - __alignment;
33160b57cec5SDimitry Andric#else
33170b57cec5SDimitry Andric    return __m - __alignment;
33180b57cec5SDimitry Andric#endif
33190b57cec5SDimitry Andric}
33200b57cec5SDimitry Andric
33210b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
33220b57cec5SDimitry Andricvoid
3323e8d8bef9SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::reserve(size_type __requested_capacity)
33240b57cec5SDimitry Andric{
3325e8d8bef9SDimitry Andric    if (__requested_capacity > max_size())
33260b57cec5SDimitry Andric        this->__throw_length_error();
3327e8d8bef9SDimitry Andric
3328e8d8bef9SDimitry Andric#if _LIBCPP_STD_VER > 17
3329e8d8bef9SDimitry Andric    // Reserve never shrinks as of C++20.
3330e8d8bef9SDimitry Andric    if (__requested_capacity <= capacity()) return;
3331e8d8bef9SDimitry Andric#endif
3332e8d8bef9SDimitry Andric
3333e8d8bef9SDimitry Andric    size_type __target_capacity = _VSTD::max(__requested_capacity, size());
3334e8d8bef9SDimitry Andric    __target_capacity = __recommend(__target_capacity);
3335e8d8bef9SDimitry Andric    if (__target_capacity == capacity()) return;
3336e8d8bef9SDimitry Andric
3337e8d8bef9SDimitry Andric    __shrink_or_extend(__target_capacity);
3338e8d8bef9SDimitry Andric}
3339e8d8bef9SDimitry Andric
3340e8d8bef9SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
3341e8d8bef9SDimitry Andricvoid
3342e8d8bef9SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::shrink_to_fit() _NOEXCEPT
3343e8d8bef9SDimitry Andric{
3344e8d8bef9SDimitry Andric    size_type __target_capacity = __recommend(size());
3345e8d8bef9SDimitry Andric    if (__target_capacity == capacity()) return;
3346e8d8bef9SDimitry Andric
3347e8d8bef9SDimitry Andric    __shrink_or_extend(__target_capacity);
3348e8d8bef9SDimitry Andric}
3349e8d8bef9SDimitry Andric
3350e8d8bef9SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
3351e8d8bef9SDimitry Andricvoid
3352e8d8bef9SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::__shrink_or_extend(size_type __target_capacity)
3353e8d8bef9SDimitry Andric{
33540b57cec5SDimitry Andric    size_type __cap = capacity();
33550b57cec5SDimitry Andric    size_type __sz = size();
3356e8d8bef9SDimitry Andric
33570b57cec5SDimitry Andric    pointer __new_data, __p;
33580b57cec5SDimitry Andric    bool __was_long, __now_long;
3359e8d8bef9SDimitry Andric    if (__target_capacity == __min_cap - 1)
33600b57cec5SDimitry Andric    {
33610b57cec5SDimitry Andric        __was_long = true;
33620b57cec5SDimitry Andric        __now_long = false;
33630b57cec5SDimitry Andric        __new_data = __get_short_pointer();
33640b57cec5SDimitry Andric        __p = __get_long_pointer();
33650b57cec5SDimitry Andric    }
33660b57cec5SDimitry Andric    else
33670b57cec5SDimitry Andric    {
3368e8d8bef9SDimitry Andric        if (__target_capacity > __cap)
3369e8d8bef9SDimitry Andric            __new_data = __alloc_traits::allocate(__alloc(), __target_capacity+1);
33700b57cec5SDimitry Andric        else
33710b57cec5SDimitry Andric        {
33720b57cec5SDimitry Andric        #ifndef _LIBCPP_NO_EXCEPTIONS
33730b57cec5SDimitry Andric            try
33740b57cec5SDimitry Andric            {
33750b57cec5SDimitry Andric        #endif // _LIBCPP_NO_EXCEPTIONS
3376e8d8bef9SDimitry Andric                __new_data = __alloc_traits::allocate(__alloc(), __target_capacity+1);
33770b57cec5SDimitry Andric        #ifndef _LIBCPP_NO_EXCEPTIONS
33780b57cec5SDimitry Andric            }
33790b57cec5SDimitry Andric            catch (...)
33800b57cec5SDimitry Andric            {
33810b57cec5SDimitry Andric                return;
33820b57cec5SDimitry Andric            }
33830b57cec5SDimitry Andric        #else  // _LIBCPP_NO_EXCEPTIONS
33840b57cec5SDimitry Andric            if (__new_data == nullptr)
33850b57cec5SDimitry Andric                return;
33860b57cec5SDimitry Andric        #endif // _LIBCPP_NO_EXCEPTIONS
33870b57cec5SDimitry Andric        }
33880b57cec5SDimitry Andric        __now_long = true;
33890b57cec5SDimitry Andric        __was_long = __is_long();
33900b57cec5SDimitry Andric        __p = __get_pointer();
33910b57cec5SDimitry Andric    }
3392480093f4SDimitry Andric    traits_type::copy(_VSTD::__to_address(__new_data),
3393480093f4SDimitry Andric                        _VSTD::__to_address(__p), size()+1);
33940b57cec5SDimitry Andric    if (__was_long)
33950b57cec5SDimitry Andric        __alloc_traits::deallocate(__alloc(), __p, __cap+1);
33960b57cec5SDimitry Andric    if (__now_long)
33970b57cec5SDimitry Andric    {
3398e8d8bef9SDimitry Andric        __set_long_cap(__target_capacity+1);
33990b57cec5SDimitry Andric        __set_long_size(__sz);
34000b57cec5SDimitry Andric        __set_long_pointer(__new_data);
34010b57cec5SDimitry Andric    }
34020b57cec5SDimitry Andric    else
34030b57cec5SDimitry Andric        __set_short_size(__sz);
34040b57cec5SDimitry Andric    __invalidate_all_iterators();
34050b57cec5SDimitry Andric}
34060b57cec5SDimitry Andric
34070b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
34080b57cec5SDimitry Andricinline
34090b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::const_reference
34100b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos) const _NOEXCEPT
34110b57cec5SDimitry Andric{
34120b57cec5SDimitry Andric    _LIBCPP_ASSERT(__pos <= size(), "string index out of bounds");
34130b57cec5SDimitry Andric    return *(data() + __pos);
34140b57cec5SDimitry Andric}
34150b57cec5SDimitry Andric
34160b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
34170b57cec5SDimitry Andricinline
34180b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::reference
34190b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos) _NOEXCEPT
34200b57cec5SDimitry Andric{
34210b57cec5SDimitry Andric    _LIBCPP_ASSERT(__pos <= size(), "string index out of bounds");
34220b57cec5SDimitry Andric    return *(__get_pointer() + __pos);
34230b57cec5SDimitry Andric}
34240b57cec5SDimitry Andric
34250b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
34260b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::const_reference
34270b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::at(size_type __n) const
34280b57cec5SDimitry Andric{
34290b57cec5SDimitry Andric    if (__n >= size())
34300b57cec5SDimitry Andric        this->__throw_out_of_range();
34310b57cec5SDimitry Andric    return (*this)[__n];
34320b57cec5SDimitry Andric}
34330b57cec5SDimitry Andric
34340b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
34350b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::reference
34360b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::at(size_type __n)
34370b57cec5SDimitry Andric{
34380b57cec5SDimitry Andric    if (__n >= size())
34390b57cec5SDimitry Andric        this->__throw_out_of_range();
34400b57cec5SDimitry Andric    return (*this)[__n];
34410b57cec5SDimitry Andric}
34420b57cec5SDimitry Andric
34430b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
34440b57cec5SDimitry Andricinline
34450b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::reference
34460b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::front() _NOEXCEPT
34470b57cec5SDimitry Andric{
34480b57cec5SDimitry Andric    _LIBCPP_ASSERT(!empty(), "string::front(): string is empty");
34490b57cec5SDimitry Andric    return *__get_pointer();
34500b57cec5SDimitry Andric}
34510b57cec5SDimitry Andric
34520b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
34530b57cec5SDimitry Andricinline
34540b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::const_reference
34550b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::front() const _NOEXCEPT
34560b57cec5SDimitry Andric{
34570b57cec5SDimitry Andric    _LIBCPP_ASSERT(!empty(), "string::front(): string is empty");
34580b57cec5SDimitry Andric    return *data();
34590b57cec5SDimitry Andric}
34600b57cec5SDimitry Andric
34610b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
34620b57cec5SDimitry Andricinline
34630b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::reference
34640b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::back() _NOEXCEPT
34650b57cec5SDimitry Andric{
34660b57cec5SDimitry Andric    _LIBCPP_ASSERT(!empty(), "string::back(): string is empty");
34670b57cec5SDimitry Andric    return *(__get_pointer() + size() - 1);
34680b57cec5SDimitry Andric}
34690b57cec5SDimitry Andric
34700b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
34710b57cec5SDimitry Andricinline
34720b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::const_reference
34730b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::back() const _NOEXCEPT
34740b57cec5SDimitry Andric{
34750b57cec5SDimitry Andric    _LIBCPP_ASSERT(!empty(), "string::back(): string is empty");
34760b57cec5SDimitry Andric    return *(data() + size() - 1);
34770b57cec5SDimitry Andric}
34780b57cec5SDimitry Andric
34790b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
34800b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::size_type
34810b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::copy(value_type* __s, size_type __n, size_type __pos) const
34820b57cec5SDimitry Andric{
34830b57cec5SDimitry Andric    size_type __sz = size();
34840b57cec5SDimitry Andric    if (__pos > __sz)
34850b57cec5SDimitry Andric        this->__throw_out_of_range();
34860b57cec5SDimitry Andric    size_type __rlen = _VSTD::min(__n, __sz - __pos);
34870b57cec5SDimitry Andric    traits_type::copy(__s, data() + __pos, __rlen);
34880b57cec5SDimitry Andric    return __rlen;
34890b57cec5SDimitry Andric}
34900b57cec5SDimitry Andric
34910b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
34920b57cec5SDimitry Andricinline
34930b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>
34940b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::substr(size_type __pos, size_type __n) const
34950b57cec5SDimitry Andric{
34960b57cec5SDimitry Andric    return basic_string(*this, __pos, __n, __alloc());
34970b57cec5SDimitry Andric}
34980b57cec5SDimitry Andric
34990b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
35000b57cec5SDimitry Andricinline
35010b57cec5SDimitry Andricvoid
35020b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::swap(basic_string& __str)
35030b57cec5SDimitry Andric#if _LIBCPP_STD_VER >= 14
35040b57cec5SDimitry Andric        _NOEXCEPT
35050b57cec5SDimitry Andric#else
35060b57cec5SDimitry Andric        _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
35070b57cec5SDimitry Andric                    __is_nothrow_swappable<allocator_type>::value)
35080b57cec5SDimitry Andric#endif
35090b57cec5SDimitry Andric{
3510e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2
35110b57cec5SDimitry Andric    if (!__is_long())
35120b57cec5SDimitry Andric        __get_db()->__invalidate_all(this);
35130b57cec5SDimitry Andric    if (!__str.__is_long())
35140b57cec5SDimitry Andric        __get_db()->__invalidate_all(&__str);
35150b57cec5SDimitry Andric    __get_db()->swap(this, &__str);
35160b57cec5SDimitry Andric#endif
35170b57cec5SDimitry Andric    _LIBCPP_ASSERT(
35180b57cec5SDimitry Andric        __alloc_traits::propagate_on_container_swap::value ||
35190b57cec5SDimitry Andric        __alloc_traits::is_always_equal::value ||
35200b57cec5SDimitry Andric        __alloc() == __str.__alloc(), "swapping non-equal allocators");
35210b57cec5SDimitry Andric    _VSTD::swap(__r_.first(), __str.__r_.first());
3522e8d8bef9SDimitry Andric    _VSTD::__swap_allocator(__alloc(), __str.__alloc());
35230b57cec5SDimitry Andric}
35240b57cec5SDimitry Andric
35250b57cec5SDimitry Andric// find
35260b57cec5SDimitry Andric
35270b57cec5SDimitry Andrictemplate <class _Traits>
35280b57cec5SDimitry Andricstruct _LIBCPP_HIDDEN __traits_eq
35290b57cec5SDimitry Andric{
35300b57cec5SDimitry Andric    typedef typename _Traits::char_type char_type;
35310b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
35320b57cec5SDimitry Andric    bool operator()(const char_type& __x, const char_type& __y) _NOEXCEPT
35330b57cec5SDimitry Andric        {return _Traits::eq(__x, __y);}
35340b57cec5SDimitry Andric};
35350b57cec5SDimitry Andric
35360b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
35370b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::size_type
35380b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s,
35390b57cec5SDimitry Andric                                                size_type __pos,
35400b57cec5SDimitry Andric                                                size_type __n) const _NOEXCEPT
35410b57cec5SDimitry Andric{
35420b57cec5SDimitry Andric    _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find(): received nullptr");
35430b57cec5SDimitry Andric    return __str_find<value_type, size_type, traits_type, npos>
35440b57cec5SDimitry Andric        (data(), size(), __s, __pos, __n);
35450b57cec5SDimitry Andric}
35460b57cec5SDimitry Andric
35470b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
35480b57cec5SDimitry Andricinline
35490b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::size_type
35500b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::find(const basic_string& __str,
35510b57cec5SDimitry Andric                                                size_type __pos) const _NOEXCEPT
35520b57cec5SDimitry Andric{
35530b57cec5SDimitry Andric    return __str_find<value_type, size_type, traits_type, npos>
35540b57cec5SDimitry Andric        (data(), size(), __str.data(), __pos, __str.size());
35550b57cec5SDimitry Andric}
35560b57cec5SDimitry Andric
35570b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
35580b57cec5SDimitry Andrictemplate <class _Tp>
3559*349cc55cSDimitry Andric__enable_if_t
35600b57cec5SDimitry Andric<
35610b57cec5SDimitry Andric    __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
35620b57cec5SDimitry Andric    typename basic_string<_CharT, _Traits, _Allocator>::size_type
35635ffd83dbSDimitry Andric>
35640b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::find(const _Tp &__t,
3565fe6060f1SDimitry Andric                                                size_type __pos) const _NOEXCEPT
35660b57cec5SDimitry Andric{
35670b57cec5SDimitry Andric    __self_view __sv = __t;
35680b57cec5SDimitry Andric    return __str_find<value_type, size_type, traits_type, npos>
35690b57cec5SDimitry Andric        (data(), size(), __sv.data(), __pos, __sv.size());
35700b57cec5SDimitry Andric}
35710b57cec5SDimitry Andric
35720b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
35730b57cec5SDimitry Andricinline
35740b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::size_type
35750b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s,
35760b57cec5SDimitry Andric                                                size_type __pos) const _NOEXCEPT
35770b57cec5SDimitry Andric{
35780b57cec5SDimitry Andric    _LIBCPP_ASSERT(__s != nullptr, "string::find(): received nullptr");
35790b57cec5SDimitry Andric    return __str_find<value_type, size_type, traits_type, npos>
35800b57cec5SDimitry Andric        (data(), size(), __s, __pos, traits_type::length(__s));
35810b57cec5SDimitry Andric}
35820b57cec5SDimitry Andric
35830b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
35840b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::size_type
35850b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::find(value_type __c,
35860b57cec5SDimitry Andric                                                size_type __pos) const _NOEXCEPT
35870b57cec5SDimitry Andric{
35880b57cec5SDimitry Andric    return __str_find<value_type, size_type, traits_type, npos>
35890b57cec5SDimitry Andric        (data(), size(), __c, __pos);
35900b57cec5SDimitry Andric}
35910b57cec5SDimitry Andric
35920b57cec5SDimitry Andric// rfind
35930b57cec5SDimitry Andric
35940b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
35950b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::size_type
35960b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s,
35970b57cec5SDimitry Andric                                                 size_type __pos,
35980b57cec5SDimitry Andric                                                 size_type __n) const _NOEXCEPT
35990b57cec5SDimitry Andric{
36000b57cec5SDimitry Andric    _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::rfind(): received nullptr");
36010b57cec5SDimitry Andric    return __str_rfind<value_type, size_type, traits_type, npos>
36020b57cec5SDimitry Andric        (data(), size(), __s, __pos, __n);
36030b57cec5SDimitry Andric}
36040b57cec5SDimitry Andric
36050b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
36060b57cec5SDimitry Andricinline
36070b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::size_type
36080b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::rfind(const basic_string& __str,
36090b57cec5SDimitry Andric                                                 size_type __pos) const _NOEXCEPT
36100b57cec5SDimitry Andric{
36110b57cec5SDimitry Andric    return __str_rfind<value_type, size_type, traits_type, npos>
36120b57cec5SDimitry Andric        (data(), size(), __str.data(), __pos, __str.size());
36130b57cec5SDimitry Andric}
36140b57cec5SDimitry Andric
36150b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
36160b57cec5SDimitry Andrictemplate <class _Tp>
3617*349cc55cSDimitry Andric__enable_if_t
36180b57cec5SDimitry Andric<
36190b57cec5SDimitry Andric    __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
36200b57cec5SDimitry Andric    typename basic_string<_CharT, _Traits, _Allocator>::size_type
36215ffd83dbSDimitry Andric>
36220b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::rfind(const _Tp& __t,
3623fe6060f1SDimitry Andric                                                size_type __pos) const _NOEXCEPT
36240b57cec5SDimitry Andric{
36250b57cec5SDimitry Andric    __self_view __sv = __t;
36260b57cec5SDimitry Andric    return __str_rfind<value_type, size_type, traits_type, npos>
36270b57cec5SDimitry Andric        (data(), size(), __sv.data(), __pos, __sv.size());
36280b57cec5SDimitry Andric}
36290b57cec5SDimitry Andric
36300b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
36310b57cec5SDimitry Andricinline
36320b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::size_type
36330b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s,
36340b57cec5SDimitry Andric                                                 size_type __pos) const _NOEXCEPT
36350b57cec5SDimitry Andric{
36360b57cec5SDimitry Andric    _LIBCPP_ASSERT(__s != nullptr, "string::rfind(): received nullptr");
36370b57cec5SDimitry Andric    return __str_rfind<value_type, size_type, traits_type, npos>
36380b57cec5SDimitry Andric        (data(), size(), __s, __pos, traits_type::length(__s));
36390b57cec5SDimitry Andric}
36400b57cec5SDimitry Andric
36410b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
36420b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::size_type
36430b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::rfind(value_type __c,
36440b57cec5SDimitry Andric                                                 size_type __pos) const _NOEXCEPT
36450b57cec5SDimitry Andric{
36460b57cec5SDimitry Andric    return __str_rfind<value_type, size_type, traits_type, npos>
36470b57cec5SDimitry Andric        (data(), size(), __c, __pos);
36480b57cec5SDimitry Andric}
36490b57cec5SDimitry Andric
36500b57cec5SDimitry Andric// find_first_of
36510b57cec5SDimitry Andric
36520b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
36530b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::size_type
36540b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s,
36550b57cec5SDimitry Andric                                                         size_type __pos,
36560b57cec5SDimitry Andric                                                         size_type __n) const _NOEXCEPT
36570b57cec5SDimitry Andric{
36580b57cec5SDimitry Andric    _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_of(): received nullptr");
36590b57cec5SDimitry Andric    return __str_find_first_of<value_type, size_type, traits_type, npos>
36600b57cec5SDimitry Andric        (data(), size(), __s, __pos, __n);
36610b57cec5SDimitry Andric}
36620b57cec5SDimitry Andric
36630b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
36640b57cec5SDimitry Andricinline
36650b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::size_type
36660b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::find_first_of(const basic_string& __str,
36670b57cec5SDimitry Andric                                                         size_type __pos) const _NOEXCEPT
36680b57cec5SDimitry Andric{
36690b57cec5SDimitry Andric    return __str_find_first_of<value_type, size_type, traits_type, npos>
36700b57cec5SDimitry Andric        (data(), size(), __str.data(), __pos, __str.size());
36710b57cec5SDimitry Andric}
36720b57cec5SDimitry Andric
36730b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
36740b57cec5SDimitry Andrictemplate <class _Tp>
3675*349cc55cSDimitry Andric__enable_if_t
36760b57cec5SDimitry Andric<
36770b57cec5SDimitry Andric    __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
36780b57cec5SDimitry Andric    typename basic_string<_CharT, _Traits, _Allocator>::size_type
36795ffd83dbSDimitry Andric>
36800b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::find_first_of(const _Tp& __t,
3681fe6060f1SDimitry Andric                                                size_type __pos) const _NOEXCEPT
36820b57cec5SDimitry Andric{
36830b57cec5SDimitry Andric    __self_view __sv = __t;
36840b57cec5SDimitry Andric    return __str_find_first_of<value_type, size_type, traits_type, npos>
36850b57cec5SDimitry Andric        (data(), size(), __sv.data(), __pos, __sv.size());
36860b57cec5SDimitry Andric}
36870b57cec5SDimitry Andric
36880b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
36890b57cec5SDimitry Andricinline
36900b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::size_type
36910b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s,
36920b57cec5SDimitry Andric                                                         size_type __pos) const _NOEXCEPT
36930b57cec5SDimitry Andric{
36940b57cec5SDimitry Andric    _LIBCPP_ASSERT(__s != nullptr, "string::find_first_of(): received nullptr");
36950b57cec5SDimitry Andric    return __str_find_first_of<value_type, size_type, traits_type, npos>
36960b57cec5SDimitry Andric        (data(), size(), __s, __pos, traits_type::length(__s));
36970b57cec5SDimitry Andric}
36980b57cec5SDimitry Andric
36990b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
37000b57cec5SDimitry Andricinline
37010b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::size_type
37020b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::find_first_of(value_type __c,
37030b57cec5SDimitry Andric                                                         size_type __pos) const _NOEXCEPT
37040b57cec5SDimitry Andric{
37050b57cec5SDimitry Andric    return find(__c, __pos);
37060b57cec5SDimitry Andric}
37070b57cec5SDimitry Andric
37080b57cec5SDimitry Andric// find_last_of
37090b57cec5SDimitry Andric
37100b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
37110b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::size_type
37120b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s,
37130b57cec5SDimitry Andric                                                        size_type __pos,
37140b57cec5SDimitry Andric                                                        size_type __n) const _NOEXCEPT
37150b57cec5SDimitry Andric{
37160b57cec5SDimitry Andric    _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_of(): received nullptr");
37170b57cec5SDimitry Andric    return __str_find_last_of<value_type, size_type, traits_type, npos>
37180b57cec5SDimitry Andric        (data(), size(), __s, __pos, __n);
37190b57cec5SDimitry Andric}
37200b57cec5SDimitry Andric
37210b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
37220b57cec5SDimitry Andricinline
37230b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::size_type
37240b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::find_last_of(const basic_string& __str,
37250b57cec5SDimitry Andric                                                        size_type __pos) const _NOEXCEPT
37260b57cec5SDimitry Andric{
37270b57cec5SDimitry Andric    return __str_find_last_of<value_type, size_type, traits_type, npos>
37280b57cec5SDimitry Andric        (data(), size(), __str.data(), __pos, __str.size());
37290b57cec5SDimitry Andric}
37300b57cec5SDimitry Andric
37310b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
37320b57cec5SDimitry Andrictemplate <class _Tp>
3733*349cc55cSDimitry Andric__enable_if_t
37340b57cec5SDimitry Andric<
37350b57cec5SDimitry Andric    __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
37360b57cec5SDimitry Andric    typename basic_string<_CharT, _Traits, _Allocator>::size_type
37375ffd83dbSDimitry Andric>
37380b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::find_last_of(const _Tp& __t,
3739fe6060f1SDimitry Andric                                                size_type __pos) const _NOEXCEPT
37400b57cec5SDimitry Andric{
37410b57cec5SDimitry Andric    __self_view __sv = __t;
37420b57cec5SDimitry Andric    return __str_find_last_of<value_type, size_type, traits_type, npos>
37430b57cec5SDimitry Andric        (data(), size(), __sv.data(), __pos, __sv.size());
37440b57cec5SDimitry Andric}
37450b57cec5SDimitry Andric
37460b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
37470b57cec5SDimitry Andricinline
37480b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::size_type
37490b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s,
37500b57cec5SDimitry Andric                                                        size_type __pos) const _NOEXCEPT
37510b57cec5SDimitry Andric{
37520b57cec5SDimitry Andric    _LIBCPP_ASSERT(__s != nullptr, "string::find_last_of(): received nullptr");
37530b57cec5SDimitry Andric    return __str_find_last_of<value_type, size_type, traits_type, npos>
37540b57cec5SDimitry Andric        (data(), size(), __s, __pos, traits_type::length(__s));
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_of(value_type __c,
37610b57cec5SDimitry Andric                                                        size_type __pos) const _NOEXCEPT
37620b57cec5SDimitry Andric{
37630b57cec5SDimitry Andric    return rfind(__c, __pos);
37640b57cec5SDimitry Andric}
37650b57cec5SDimitry Andric
37660b57cec5SDimitry Andric// find_first_not_of
37670b57cec5SDimitry Andric
37680b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
37690b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::size_type
37700b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* __s,
37710b57cec5SDimitry Andric                                                             size_type __pos,
37720b57cec5SDimitry Andric                                                             size_type __n) const _NOEXCEPT
37730b57cec5SDimitry Andric{
37740b57cec5SDimitry Andric    _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_not_of(): received nullptr");
37750b57cec5SDimitry Andric    return __str_find_first_not_of<value_type, size_type, traits_type, npos>
37760b57cec5SDimitry Andric        (data(), size(), __s, __pos, __n);
37770b57cec5SDimitry Andric}
37780b57cec5SDimitry Andric
37790b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
37800b57cec5SDimitry Andricinline
37810b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::size_type
37820b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const basic_string& __str,
37830b57cec5SDimitry Andric                                                             size_type __pos) const _NOEXCEPT
37840b57cec5SDimitry Andric{
37850b57cec5SDimitry Andric    return __str_find_first_not_of<value_type, size_type, traits_type, npos>
37860b57cec5SDimitry Andric        (data(), size(), __str.data(), __pos, __str.size());
37870b57cec5SDimitry Andric}
37880b57cec5SDimitry Andric
37890b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
37900b57cec5SDimitry Andrictemplate <class _Tp>
3791*349cc55cSDimitry Andric__enable_if_t
37920b57cec5SDimitry Andric<
37930b57cec5SDimitry Andric    __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
37940b57cec5SDimitry Andric    typename basic_string<_CharT, _Traits, _Allocator>::size_type
37955ffd83dbSDimitry Andric>
37960b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const _Tp& __t,
3797fe6060f1SDimitry Andric                                                size_type __pos) const _NOEXCEPT
37980b57cec5SDimitry Andric{
37990b57cec5SDimitry Andric    __self_view __sv = __t;
38000b57cec5SDimitry Andric    return __str_find_first_not_of<value_type, size_type, traits_type, npos>
38010b57cec5SDimitry Andric        (data(), size(), __sv.data(), __pos, __sv.size());
38020b57cec5SDimitry Andric}
38030b57cec5SDimitry Andric
38040b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
38050b57cec5SDimitry Andricinline
38060b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::size_type
38070b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* __s,
38080b57cec5SDimitry Andric                                                             size_type __pos) const _NOEXCEPT
38090b57cec5SDimitry Andric{
38100b57cec5SDimitry Andric    _LIBCPP_ASSERT(__s != nullptr, "string::find_first_not_of(): received nullptr");
38110b57cec5SDimitry Andric    return __str_find_first_not_of<value_type, size_type, traits_type, npos>
38120b57cec5SDimitry Andric        (data(), size(), __s, __pos, traits_type::length(__s));
38130b57cec5SDimitry Andric}
38140b57cec5SDimitry Andric
38150b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
38160b57cec5SDimitry Andricinline
38170b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::size_type
38180b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::find_first_not_of(value_type __c,
38190b57cec5SDimitry Andric                                                             size_type __pos) const _NOEXCEPT
38200b57cec5SDimitry Andric{
38210b57cec5SDimitry Andric    return __str_find_first_not_of<value_type, size_type, traits_type, npos>
38220b57cec5SDimitry Andric        (data(), size(), __c, __pos);
38230b57cec5SDimitry Andric}
38240b57cec5SDimitry Andric
38250b57cec5SDimitry Andric// find_last_not_of
38260b57cec5SDimitry Andric
38270b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
38280b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::size_type
38290b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __s,
38300b57cec5SDimitry Andric                                                            size_type __pos,
38310b57cec5SDimitry Andric                                                            size_type __n) const _NOEXCEPT
38320b57cec5SDimitry Andric{
38330b57cec5SDimitry Andric    _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_not_of(): received nullptr");
38340b57cec5SDimitry Andric    return __str_find_last_not_of<value_type, size_type, traits_type, npos>
38350b57cec5SDimitry Andric        (data(), size(), __s, __pos, __n);
38360b57cec5SDimitry Andric}
38370b57cec5SDimitry Andric
38380b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
38390b57cec5SDimitry Andricinline
38400b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::size_type
38410b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const basic_string& __str,
38420b57cec5SDimitry Andric                                                            size_type __pos) const _NOEXCEPT
38430b57cec5SDimitry Andric{
38440b57cec5SDimitry Andric    return __str_find_last_not_of<value_type, size_type, traits_type, npos>
38450b57cec5SDimitry Andric        (data(), size(), __str.data(), __pos, __str.size());
38460b57cec5SDimitry Andric}
38470b57cec5SDimitry Andric
38480b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
38490b57cec5SDimitry Andrictemplate <class _Tp>
3850*349cc55cSDimitry Andric__enable_if_t
38510b57cec5SDimitry Andric<
38520b57cec5SDimitry Andric    __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
38530b57cec5SDimitry Andric    typename basic_string<_CharT, _Traits, _Allocator>::size_type
38545ffd83dbSDimitry Andric>
38550b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const _Tp& __t,
3856fe6060f1SDimitry Andric                                                size_type __pos) const _NOEXCEPT
38570b57cec5SDimitry Andric{
38580b57cec5SDimitry Andric    __self_view __sv = __t;
38590b57cec5SDimitry Andric    return __str_find_last_not_of<value_type, size_type, traits_type, npos>
38600b57cec5SDimitry Andric        (data(), size(), __sv.data(), __pos, __sv.size());
38610b57cec5SDimitry Andric}
38620b57cec5SDimitry Andric
38630b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
38640b57cec5SDimitry Andricinline
38650b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::size_type
38660b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __s,
38670b57cec5SDimitry Andric                                                            size_type __pos) const _NOEXCEPT
38680b57cec5SDimitry Andric{
38690b57cec5SDimitry Andric    _LIBCPP_ASSERT(__s != nullptr, "string::find_last_not_of(): received nullptr");
38700b57cec5SDimitry Andric    return __str_find_last_not_of<value_type, size_type, traits_type, npos>
38710b57cec5SDimitry Andric        (data(), size(), __s, __pos, traits_type::length(__s));
38720b57cec5SDimitry Andric}
38730b57cec5SDimitry Andric
38740b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
38750b57cec5SDimitry Andricinline
38760b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::size_type
38770b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::find_last_not_of(value_type __c,
38780b57cec5SDimitry Andric                                                            size_type __pos) const _NOEXCEPT
38790b57cec5SDimitry Andric{
38800b57cec5SDimitry Andric    return __str_find_last_not_of<value_type, size_type, traits_type, npos>
38810b57cec5SDimitry Andric        (data(), size(), __c, __pos);
38820b57cec5SDimitry Andric}
38830b57cec5SDimitry Andric
38840b57cec5SDimitry Andric// compare
38850b57cec5SDimitry Andric
38860b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
38870b57cec5SDimitry Andrictemplate <class _Tp>
3888*349cc55cSDimitry Andric__enable_if_t
38890b57cec5SDimitry Andric<
38900b57cec5SDimitry Andric    __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
38910b57cec5SDimitry Andric    int
38925ffd83dbSDimitry Andric>
3893fe6060f1SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::compare(const _Tp& __t) const _NOEXCEPT
38940b57cec5SDimitry Andric{
38950b57cec5SDimitry Andric    __self_view __sv = __t;
38960b57cec5SDimitry Andric    size_t __lhs_sz = size();
38970b57cec5SDimitry Andric    size_t __rhs_sz = __sv.size();
38980b57cec5SDimitry Andric    int __result = traits_type::compare(data(), __sv.data(),
38990b57cec5SDimitry Andric                                        _VSTD::min(__lhs_sz, __rhs_sz));
39000b57cec5SDimitry Andric    if (__result != 0)
39010b57cec5SDimitry Andric        return __result;
39020b57cec5SDimitry Andric    if (__lhs_sz < __rhs_sz)
39030b57cec5SDimitry Andric        return -1;
39040b57cec5SDimitry Andric    if (__lhs_sz > __rhs_sz)
39050b57cec5SDimitry Andric        return 1;
39060b57cec5SDimitry Andric    return 0;
39070b57cec5SDimitry Andric}
39080b57cec5SDimitry Andric
39090b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
39100b57cec5SDimitry Andricinline
39110b57cec5SDimitry Andricint
39120b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::compare(const basic_string& __str) const _NOEXCEPT
39130b57cec5SDimitry Andric{
39140b57cec5SDimitry Andric    return compare(__self_view(__str));
39150b57cec5SDimitry Andric}
39160b57cec5SDimitry Andric
39170b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
39180b57cec5SDimitry Andricint
39190b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
39200b57cec5SDimitry Andric                                                   size_type __n1,
39210b57cec5SDimitry Andric                                                   const value_type* __s,
39220b57cec5SDimitry Andric                                                   size_type __n2) const
39230b57cec5SDimitry Andric{
39240b57cec5SDimitry Andric    _LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::compare(): received nullptr");
39250b57cec5SDimitry Andric    size_type __sz = size();
39260b57cec5SDimitry Andric    if (__pos1 > __sz || __n2 == npos)
39270b57cec5SDimitry Andric        this->__throw_out_of_range();
39280b57cec5SDimitry Andric    size_type __rlen = _VSTD::min(__n1, __sz - __pos1);
39290b57cec5SDimitry Andric    int __r = traits_type::compare(data() + __pos1, __s, _VSTD::min(__rlen, __n2));
39300b57cec5SDimitry Andric    if (__r == 0)
39310b57cec5SDimitry Andric    {
39320b57cec5SDimitry Andric        if (__rlen < __n2)
39330b57cec5SDimitry Andric            __r = -1;
39340b57cec5SDimitry Andric        else if (__rlen > __n2)
39350b57cec5SDimitry Andric            __r = 1;
39360b57cec5SDimitry Andric    }
39370b57cec5SDimitry Andric    return __r;
39380b57cec5SDimitry Andric}
39390b57cec5SDimitry Andric
39400b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
39410b57cec5SDimitry Andrictemplate <class _Tp>
3942*349cc55cSDimitry Andric__enable_if_t
39430b57cec5SDimitry Andric<
39440b57cec5SDimitry Andric    __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
39450b57cec5SDimitry Andric    int
39465ffd83dbSDimitry Andric>
39470b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
39480b57cec5SDimitry Andric                                                   size_type __n1,
39490b57cec5SDimitry Andric                                                   const _Tp& __t) const
39500b57cec5SDimitry Andric{
39510b57cec5SDimitry Andric    __self_view __sv = __t;
39520b57cec5SDimitry Andric    return compare(__pos1, __n1, __sv.data(), __sv.size());
39530b57cec5SDimitry Andric}
39540b57cec5SDimitry Andric
39550b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
39560b57cec5SDimitry Andricinline
39570b57cec5SDimitry Andricint
39580b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
39590b57cec5SDimitry Andric                                                   size_type __n1,
39600b57cec5SDimitry Andric                                                   const basic_string& __str) const
39610b57cec5SDimitry Andric{
39620b57cec5SDimitry Andric    return compare(__pos1, __n1, __str.data(), __str.size());
39630b57cec5SDimitry Andric}
39640b57cec5SDimitry Andric
39650b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
39660b57cec5SDimitry Andrictemplate <class _Tp>
3967*349cc55cSDimitry Andric__enable_if_t
39680b57cec5SDimitry Andric<
39695ffd83dbSDimitry Andric    __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value
39705ffd83dbSDimitry Andric    && !__is_same_uncvref<_Tp, basic_string<_CharT, _Traits, _Allocator> >::value,
39710b57cec5SDimitry Andric    int
39725ffd83dbSDimitry Andric>
39730b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
39740b57cec5SDimitry Andric                                                   size_type __n1,
39750b57cec5SDimitry Andric                                                   const _Tp& __t,
39760b57cec5SDimitry Andric                                                   size_type __pos2,
39770b57cec5SDimitry Andric                                                   size_type __n2) const
39780b57cec5SDimitry Andric{
39790b57cec5SDimitry Andric    __self_view __sv = __t;
39800b57cec5SDimitry Andric    return __self_view(*this).substr(__pos1, __n1).compare(__sv.substr(__pos2, __n2));
39810b57cec5SDimitry Andric}
39820b57cec5SDimitry Andric
39830b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
39840b57cec5SDimitry Andricint
39850b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
39860b57cec5SDimitry Andric                                                   size_type __n1,
39870b57cec5SDimitry Andric                                                   const basic_string& __str,
39880b57cec5SDimitry Andric                                                   size_type __pos2,
39890b57cec5SDimitry Andric                                                   size_type __n2) const
39900b57cec5SDimitry Andric{
39910b57cec5SDimitry Andric        return compare(__pos1, __n1, __self_view(__str), __pos2, __n2);
39920b57cec5SDimitry Andric}
39930b57cec5SDimitry Andric
39940b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
39950b57cec5SDimitry Andricint
39960b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::compare(const value_type* __s) const _NOEXCEPT
39970b57cec5SDimitry Andric{
39980b57cec5SDimitry Andric    _LIBCPP_ASSERT(__s != nullptr, "string::compare(): received nullptr");
39990b57cec5SDimitry Andric    return compare(0, npos, __s, traits_type::length(__s));
40000b57cec5SDimitry Andric}
40010b57cec5SDimitry Andric
40020b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
40030b57cec5SDimitry Andricint
40040b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
40050b57cec5SDimitry Andric                                                   size_type __n1,
40060b57cec5SDimitry Andric                                                   const value_type* __s) const
40070b57cec5SDimitry Andric{
40080b57cec5SDimitry Andric    _LIBCPP_ASSERT(__s != nullptr, "string::compare(): received nullptr");
40090b57cec5SDimitry Andric    return compare(__pos1, __n1, __s, traits_type::length(__s));
40100b57cec5SDimitry Andric}
40110b57cec5SDimitry Andric
40120b57cec5SDimitry Andric// __invariants
40130b57cec5SDimitry Andric
40140b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
40150b57cec5SDimitry Andricinline
40160b57cec5SDimitry Andricbool
40170b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::__invariants() const
40180b57cec5SDimitry Andric{
40190b57cec5SDimitry Andric    if (size() > capacity())
40200b57cec5SDimitry Andric        return false;
40210b57cec5SDimitry Andric    if (capacity() < __min_cap - 1)
40220b57cec5SDimitry Andric        return false;
4023e8d8bef9SDimitry Andric    if (data() == nullptr)
40240b57cec5SDimitry Andric        return false;
4025e8d8bef9SDimitry Andric    if (data()[size()] != value_type())
40260b57cec5SDimitry Andric        return false;
40270b57cec5SDimitry Andric    return true;
40280b57cec5SDimitry Andric}
40290b57cec5SDimitry Andric
40300b57cec5SDimitry Andric// __clear_and_shrink
40310b57cec5SDimitry Andric
40320b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
40330b57cec5SDimitry Andricinline
40340b57cec5SDimitry Andricvoid
40350b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::__clear_and_shrink() _NOEXCEPT
40360b57cec5SDimitry Andric{
40370b57cec5SDimitry Andric    clear();
40380b57cec5SDimitry Andric    if(__is_long())
40390b57cec5SDimitry Andric    {
40400b57cec5SDimitry Andric        __alloc_traits::deallocate(__alloc(), __get_long_pointer(), capacity() + 1);
40410b57cec5SDimitry Andric        __set_long_cap(0);
40420b57cec5SDimitry Andric        __set_short_size(0);
4043e8d8bef9SDimitry Andric        traits_type::assign(*__get_short_pointer(), value_type());
40440b57cec5SDimitry Andric    }
40450b57cec5SDimitry Andric}
40460b57cec5SDimitry Andric
40470b57cec5SDimitry Andric// operator==
40480b57cec5SDimitry Andric
40490b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
40500b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
40510b57cec5SDimitry Andricbool
40520b57cec5SDimitry Andricoperator==(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
40530b57cec5SDimitry Andric           const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
40540b57cec5SDimitry Andric{
40550b57cec5SDimitry Andric    size_t __lhs_sz = __lhs.size();
40560b57cec5SDimitry Andric    return __lhs_sz == __rhs.size() && _Traits::compare(__lhs.data(),
40570b57cec5SDimitry Andric                                                        __rhs.data(),
40580b57cec5SDimitry Andric                                                        __lhs_sz) == 0;
40590b57cec5SDimitry Andric}
40600b57cec5SDimitry Andric
40610b57cec5SDimitry Andrictemplate<class _Allocator>
40620b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
40630b57cec5SDimitry Andricbool
40640b57cec5SDimitry Andricoperator==(const basic_string<char, char_traits<char>, _Allocator>& __lhs,
40650b57cec5SDimitry Andric           const basic_string<char, char_traits<char>, _Allocator>& __rhs) _NOEXCEPT
40660b57cec5SDimitry Andric{
40670b57cec5SDimitry Andric    size_t __lhs_sz = __lhs.size();
40680b57cec5SDimitry Andric    if (__lhs_sz != __rhs.size())
40690b57cec5SDimitry Andric        return false;
40700b57cec5SDimitry Andric    const char* __lp = __lhs.data();
40710b57cec5SDimitry Andric    const char* __rp = __rhs.data();
40720b57cec5SDimitry Andric    if (__lhs.__is_long())
40730b57cec5SDimitry Andric        return char_traits<char>::compare(__lp, __rp, __lhs_sz) == 0;
40740b57cec5SDimitry Andric    for (; __lhs_sz != 0; --__lhs_sz, ++__lp, ++__rp)
40750b57cec5SDimitry Andric        if (*__lp != *__rp)
40760b57cec5SDimitry Andric            return false;
40770b57cec5SDimitry Andric    return true;
40780b57cec5SDimitry Andric}
40790b57cec5SDimitry Andric
40800b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
40810b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
40820b57cec5SDimitry Andricbool
40830b57cec5SDimitry Andricoperator==(const _CharT* __lhs,
40840b57cec5SDimitry Andric           const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
40850b57cec5SDimitry Andric{
40860b57cec5SDimitry Andric    typedef basic_string<_CharT, _Traits, _Allocator> _String;
40870b57cec5SDimitry Andric    _LIBCPP_ASSERT(__lhs != nullptr, "operator==(char*, basic_string): received nullptr");
40880b57cec5SDimitry Andric    size_t __lhs_len = _Traits::length(__lhs);
40890b57cec5SDimitry Andric    if (__lhs_len != __rhs.size()) return false;
40900b57cec5SDimitry Andric    return __rhs.compare(0, _String::npos, __lhs, __lhs_len) == 0;
40910b57cec5SDimitry Andric}
40920b57cec5SDimitry Andric
40930b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
40940b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
40950b57cec5SDimitry Andricbool
40960b57cec5SDimitry Andricoperator==(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
40970b57cec5SDimitry Andric           const _CharT* __rhs) _NOEXCEPT
40980b57cec5SDimitry Andric{
40990b57cec5SDimitry Andric    typedef basic_string<_CharT, _Traits, _Allocator> _String;
41000b57cec5SDimitry Andric    _LIBCPP_ASSERT(__rhs != nullptr, "operator==(basic_string, char*): received nullptr");
41010b57cec5SDimitry Andric    size_t __rhs_len = _Traits::length(__rhs);
41020b57cec5SDimitry Andric    if (__rhs_len != __lhs.size()) return false;
41030b57cec5SDimitry Andric    return __lhs.compare(0, _String::npos, __rhs, __rhs_len) == 0;
41040b57cec5SDimitry Andric}
41050b57cec5SDimitry Andric
41060b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
41070b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
41080b57cec5SDimitry Andricbool
41090b57cec5SDimitry Andricoperator!=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
41100b57cec5SDimitry Andric           const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
41110b57cec5SDimitry Andric{
41120b57cec5SDimitry Andric    return !(__lhs == __rhs);
41130b57cec5SDimitry Andric}
41140b57cec5SDimitry Andric
41150b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
41160b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
41170b57cec5SDimitry Andricbool
41180b57cec5SDimitry Andricoperator!=(const _CharT* __lhs,
41190b57cec5SDimitry Andric           const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
41200b57cec5SDimitry Andric{
41210b57cec5SDimitry Andric    return !(__lhs == __rhs);
41220b57cec5SDimitry Andric}
41230b57cec5SDimitry Andric
41240b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
41250b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
41260b57cec5SDimitry Andricbool
41270b57cec5SDimitry Andricoperator!=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
41280b57cec5SDimitry Andric           const _CharT* __rhs) _NOEXCEPT
41290b57cec5SDimitry Andric{
41300b57cec5SDimitry Andric    return !(__lhs == __rhs);
41310b57cec5SDimitry Andric}
41320b57cec5SDimitry Andric
41330b57cec5SDimitry Andric// operator<
41340b57cec5SDimitry Andric
41350b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
41360b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
41370b57cec5SDimitry Andricbool
41380b57cec5SDimitry Andricoperator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
41390b57cec5SDimitry Andric           const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
41400b57cec5SDimitry Andric{
41410b57cec5SDimitry Andric    return __lhs.compare(__rhs) < 0;
41420b57cec5SDimitry Andric}
41430b57cec5SDimitry Andric
41440b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
41450b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
41460b57cec5SDimitry Andricbool
41470b57cec5SDimitry Andricoperator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
41480b57cec5SDimitry Andric           const _CharT* __rhs) _NOEXCEPT
41490b57cec5SDimitry Andric{
41500b57cec5SDimitry Andric    return __lhs.compare(__rhs) < 0;
41510b57cec5SDimitry Andric}
41520b57cec5SDimitry Andric
41530b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
41540b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
41550b57cec5SDimitry Andricbool
41560b57cec5SDimitry Andricoperator< (const _CharT* __lhs,
41570b57cec5SDimitry Andric           const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
41580b57cec5SDimitry Andric{
41590b57cec5SDimitry Andric    return __rhs.compare(__lhs) > 0;
41600b57cec5SDimitry Andric}
41610b57cec5SDimitry Andric
41620b57cec5SDimitry Andric// operator>
41630b57cec5SDimitry Andric
41640b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
41650b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
41660b57cec5SDimitry Andricbool
41670b57cec5SDimitry Andricoperator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
41680b57cec5SDimitry Andric           const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
41690b57cec5SDimitry Andric{
41700b57cec5SDimitry Andric    return __rhs < __lhs;
41710b57cec5SDimitry Andric}
41720b57cec5SDimitry Andric
41730b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
41740b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
41750b57cec5SDimitry Andricbool
41760b57cec5SDimitry Andricoperator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
41770b57cec5SDimitry Andric           const _CharT* __rhs) _NOEXCEPT
41780b57cec5SDimitry Andric{
41790b57cec5SDimitry Andric    return __rhs < __lhs;
41800b57cec5SDimitry Andric}
41810b57cec5SDimitry Andric
41820b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
41830b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
41840b57cec5SDimitry Andricbool
41850b57cec5SDimitry Andricoperator> (const _CharT* __lhs,
41860b57cec5SDimitry Andric           const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
41870b57cec5SDimitry Andric{
41880b57cec5SDimitry Andric    return __rhs < __lhs;
41890b57cec5SDimitry Andric}
41900b57cec5SDimitry Andric
41910b57cec5SDimitry Andric// operator<=
41920b57cec5SDimitry Andric
41930b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
41940b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
41950b57cec5SDimitry Andricbool
41960b57cec5SDimitry Andricoperator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
41970b57cec5SDimitry Andric           const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
41980b57cec5SDimitry Andric{
41990b57cec5SDimitry Andric    return !(__rhs < __lhs);
42000b57cec5SDimitry Andric}
42010b57cec5SDimitry Andric
42020b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
42030b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
42040b57cec5SDimitry Andricbool
42050b57cec5SDimitry Andricoperator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
42060b57cec5SDimitry Andric           const _CharT* __rhs) _NOEXCEPT
42070b57cec5SDimitry Andric{
42080b57cec5SDimitry Andric    return !(__rhs < __lhs);
42090b57cec5SDimitry Andric}
42100b57cec5SDimitry Andric
42110b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
42120b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
42130b57cec5SDimitry Andricbool
42140b57cec5SDimitry Andricoperator<=(const _CharT* __lhs,
42150b57cec5SDimitry Andric           const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
42160b57cec5SDimitry Andric{
42170b57cec5SDimitry Andric    return !(__rhs < __lhs);
42180b57cec5SDimitry Andric}
42190b57cec5SDimitry Andric
42200b57cec5SDimitry Andric// operator>=
42210b57cec5SDimitry Andric
42220b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
42230b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
42240b57cec5SDimitry Andricbool
42250b57cec5SDimitry Andricoperator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
42260b57cec5SDimitry Andric           const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
42270b57cec5SDimitry Andric{
42280b57cec5SDimitry Andric    return !(__lhs < __rhs);
42290b57cec5SDimitry Andric}
42300b57cec5SDimitry Andric
42310b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
42320b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
42330b57cec5SDimitry Andricbool
42340b57cec5SDimitry Andricoperator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
42350b57cec5SDimitry Andric           const _CharT* __rhs) _NOEXCEPT
42360b57cec5SDimitry Andric{
42370b57cec5SDimitry Andric    return !(__lhs < __rhs);
42380b57cec5SDimitry Andric}
42390b57cec5SDimitry Andric
42400b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
42410b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
42420b57cec5SDimitry Andricbool
42430b57cec5SDimitry Andricoperator>=(const _CharT* __lhs,
42440b57cec5SDimitry Andric           const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
42450b57cec5SDimitry Andric{
42460b57cec5SDimitry Andric    return !(__lhs < __rhs);
42470b57cec5SDimitry Andric}
42480b57cec5SDimitry Andric
42490b57cec5SDimitry Andric// operator +
42500b57cec5SDimitry Andric
42510b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
42520b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>
42530b57cec5SDimitry Andricoperator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
42540b57cec5SDimitry Andric          const basic_string<_CharT, _Traits, _Allocator>& __rhs)
42550b57cec5SDimitry Andric{
42560b57cec5SDimitry Andric    basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
42570b57cec5SDimitry Andric    typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
42580b57cec5SDimitry Andric    typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
42590b57cec5SDimitry Andric    __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + __rhs_sz);
42600b57cec5SDimitry Andric    __r.append(__rhs.data(), __rhs_sz);
42610b57cec5SDimitry Andric    return __r;
42620b57cec5SDimitry Andric}
42630b57cec5SDimitry Andric
42640b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
42650b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>
42660b57cec5SDimitry Andricoperator+(const _CharT* __lhs , const basic_string<_CharT,_Traits,_Allocator>& __rhs)
42670b57cec5SDimitry Andric{
42680b57cec5SDimitry Andric    basic_string<_CharT, _Traits, _Allocator> __r(__rhs.get_allocator());
42690b57cec5SDimitry Andric    typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = _Traits::length(__lhs);
42700b57cec5SDimitry Andric    typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
42710b57cec5SDimitry Andric    __r.__init(__lhs, __lhs_sz, __lhs_sz + __rhs_sz);
42720b57cec5SDimitry Andric    __r.append(__rhs.data(), __rhs_sz);
42730b57cec5SDimitry Andric    return __r;
42740b57cec5SDimitry Andric}
42750b57cec5SDimitry Andric
42760b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
42770b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>
42780b57cec5SDimitry Andricoperator+(_CharT __lhs, const basic_string<_CharT,_Traits,_Allocator>& __rhs)
42790b57cec5SDimitry Andric{
42800b57cec5SDimitry Andric    basic_string<_CharT, _Traits, _Allocator> __r(__rhs.get_allocator());
42810b57cec5SDimitry Andric    typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
42820b57cec5SDimitry Andric    __r.__init(&__lhs, 1, 1 + __rhs_sz);
42830b57cec5SDimitry Andric    __r.append(__rhs.data(), __rhs_sz);
42840b57cec5SDimitry Andric    return __r;
42850b57cec5SDimitry Andric}
42860b57cec5SDimitry Andric
42870b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
42880b57cec5SDimitry Andricinline
42890b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>
42900b57cec5SDimitry Andricoperator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, const _CharT* __rhs)
42910b57cec5SDimitry Andric{
42920b57cec5SDimitry Andric    basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
42930b57cec5SDimitry Andric    typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
42940b57cec5SDimitry Andric    typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = _Traits::length(__rhs);
42950b57cec5SDimitry Andric    __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + __rhs_sz);
42960b57cec5SDimitry Andric    __r.append(__rhs, __rhs_sz);
42970b57cec5SDimitry Andric    return __r;
42980b57cec5SDimitry Andric}
42990b57cec5SDimitry Andric
43000b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
43010b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>
43020b57cec5SDimitry Andricoperator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, _CharT __rhs)
43030b57cec5SDimitry Andric{
43040b57cec5SDimitry Andric    basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
43050b57cec5SDimitry Andric    typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
43060b57cec5SDimitry Andric    __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + 1);
43070b57cec5SDimitry Andric    __r.push_back(__rhs);
43080b57cec5SDimitry Andric    return __r;
43090b57cec5SDimitry Andric}
43100b57cec5SDimitry Andric
43110b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
43120b57cec5SDimitry Andric
43130b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
43140b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
43150b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>
43160b57cec5SDimitry Andricoperator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const basic_string<_CharT, _Traits, _Allocator>& __rhs)
43170b57cec5SDimitry Andric{
43180b57cec5SDimitry Andric    return _VSTD::move(__lhs.append(__rhs));
43190b57cec5SDimitry Andric}
43200b57cec5SDimitry Andric
43210b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
43220b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
43230b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>
43240b57cec5SDimitry Andricoperator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs)
43250b57cec5SDimitry Andric{
43260b57cec5SDimitry Andric    return _VSTD::move(__rhs.insert(0, __lhs));
43270b57cec5SDimitry Andric}
43280b57cec5SDimitry Andric
43290b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
43300b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
43310b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>
43320b57cec5SDimitry Andricoperator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs)
43330b57cec5SDimitry Andric{
43340b57cec5SDimitry Andric    return _VSTD::move(__lhs.append(__rhs));
43350b57cec5SDimitry Andric}
43360b57cec5SDimitry Andric
43370b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
43380b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
43390b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>
43400b57cec5SDimitry Andricoperator+(const _CharT* __lhs , basic_string<_CharT,_Traits,_Allocator>&& __rhs)
43410b57cec5SDimitry Andric{
43420b57cec5SDimitry Andric    return _VSTD::move(__rhs.insert(0, __lhs));
43430b57cec5SDimitry Andric}
43440b57cec5SDimitry Andric
43450b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
43460b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
43470b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>
43480b57cec5SDimitry Andricoperator+(_CharT __lhs, basic_string<_CharT,_Traits,_Allocator>&& __rhs)
43490b57cec5SDimitry Andric{
43500b57cec5SDimitry Andric    __rhs.insert(__rhs.begin(), __lhs);
43510b57cec5SDimitry Andric    return _VSTD::move(__rhs);
43520b57cec5SDimitry Andric}
43530b57cec5SDimitry Andric
43540b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
43550b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
43560b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>
43570b57cec5SDimitry Andricoperator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const _CharT* __rhs)
43580b57cec5SDimitry Andric{
43590b57cec5SDimitry Andric    return _VSTD::move(__lhs.append(__rhs));
43600b57cec5SDimitry Andric}
43610b57cec5SDimitry Andric
43620b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
43630b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
43640b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>
43650b57cec5SDimitry Andricoperator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, _CharT __rhs)
43660b57cec5SDimitry Andric{
43670b57cec5SDimitry Andric    __lhs.push_back(__rhs);
43680b57cec5SDimitry Andric    return _VSTD::move(__lhs);
43690b57cec5SDimitry Andric}
43700b57cec5SDimitry Andric
43710b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG
43720b57cec5SDimitry Andric
43730b57cec5SDimitry Andric// swap
43740b57cec5SDimitry Andric
43750b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
43760b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
43770b57cec5SDimitry Andricvoid
43780b57cec5SDimitry Andricswap(basic_string<_CharT, _Traits, _Allocator>& __lhs,
43790b57cec5SDimitry Andric     basic_string<_CharT, _Traits, _Allocator>& __rhs)
43800b57cec5SDimitry Andric     _NOEXCEPT_(_NOEXCEPT_(__lhs.swap(__rhs)))
43810b57cec5SDimitry Andric{
43820b57cec5SDimitry Andric    __lhs.swap(__rhs);
43830b57cec5SDimitry Andric}
43840b57cec5SDimitry Andric
4385e8d8bef9SDimitry Andric_LIBCPP_FUNC_VIS int                stoi  (const string& __str, size_t* __idx = nullptr, int __base = 10);
4386e8d8bef9SDimitry Andric_LIBCPP_FUNC_VIS long               stol  (const string& __str, size_t* __idx = nullptr, int __base = 10);
4387e8d8bef9SDimitry Andric_LIBCPP_FUNC_VIS unsigned long      stoul (const string& __str, size_t* __idx = nullptr, int __base = 10);
4388e8d8bef9SDimitry Andric_LIBCPP_FUNC_VIS long long          stoll (const string& __str, size_t* __idx = nullptr, int __base = 10);
4389e8d8bef9SDimitry Andric_LIBCPP_FUNC_VIS unsigned long long stoull(const string& __str, size_t* __idx = nullptr, int __base = 10);
43900b57cec5SDimitry Andric
4391e8d8bef9SDimitry Andric_LIBCPP_FUNC_VIS float       stof (const string& __str, size_t* __idx = nullptr);
4392e8d8bef9SDimitry Andric_LIBCPP_FUNC_VIS double      stod (const string& __str, size_t* __idx = nullptr);
4393e8d8bef9SDimitry Andric_LIBCPP_FUNC_VIS long double stold(const string& __str, size_t* __idx = nullptr);
43940b57cec5SDimitry Andric
43950b57cec5SDimitry Andric_LIBCPP_FUNC_VIS string to_string(int __val);
43960b57cec5SDimitry Andric_LIBCPP_FUNC_VIS string to_string(unsigned __val);
43970b57cec5SDimitry Andric_LIBCPP_FUNC_VIS string to_string(long __val);
43980b57cec5SDimitry Andric_LIBCPP_FUNC_VIS string to_string(unsigned long __val);
43990b57cec5SDimitry Andric_LIBCPP_FUNC_VIS string to_string(long long __val);
44000b57cec5SDimitry Andric_LIBCPP_FUNC_VIS string to_string(unsigned long long __val);
44010b57cec5SDimitry Andric_LIBCPP_FUNC_VIS string to_string(float __val);
44020b57cec5SDimitry Andric_LIBCPP_FUNC_VIS string to_string(double __val);
44030b57cec5SDimitry Andric_LIBCPP_FUNC_VIS string to_string(long double __val);
44040b57cec5SDimitry Andric
4405*349cc55cSDimitry Andric#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
4406e8d8bef9SDimitry Andric_LIBCPP_FUNC_VIS int                stoi  (const wstring& __str, size_t* __idx = nullptr, int __base = 10);
4407e8d8bef9SDimitry Andric_LIBCPP_FUNC_VIS long               stol  (const wstring& __str, size_t* __idx = nullptr, int __base = 10);
4408e8d8bef9SDimitry Andric_LIBCPP_FUNC_VIS unsigned long      stoul (const wstring& __str, size_t* __idx = nullptr, int __base = 10);
4409e8d8bef9SDimitry Andric_LIBCPP_FUNC_VIS long long          stoll (const wstring& __str, size_t* __idx = nullptr, int __base = 10);
4410e8d8bef9SDimitry Andric_LIBCPP_FUNC_VIS unsigned long long stoull(const wstring& __str, size_t* __idx = nullptr, int __base = 10);
44110b57cec5SDimitry Andric
4412e8d8bef9SDimitry Andric_LIBCPP_FUNC_VIS float       stof (const wstring& __str, size_t* __idx = nullptr);
4413e8d8bef9SDimitry Andric_LIBCPP_FUNC_VIS double      stod (const wstring& __str, size_t* __idx = nullptr);
4414e8d8bef9SDimitry Andric_LIBCPP_FUNC_VIS long double stold(const wstring& __str, size_t* __idx = nullptr);
44150b57cec5SDimitry Andric
44160b57cec5SDimitry Andric_LIBCPP_FUNC_VIS wstring to_wstring(int __val);
44170b57cec5SDimitry Andric_LIBCPP_FUNC_VIS wstring to_wstring(unsigned __val);
44180b57cec5SDimitry Andric_LIBCPP_FUNC_VIS wstring to_wstring(long __val);
44190b57cec5SDimitry Andric_LIBCPP_FUNC_VIS wstring to_wstring(unsigned long __val);
44200b57cec5SDimitry Andric_LIBCPP_FUNC_VIS wstring to_wstring(long long __val);
44210b57cec5SDimitry Andric_LIBCPP_FUNC_VIS wstring to_wstring(unsigned long long __val);
44220b57cec5SDimitry Andric_LIBCPP_FUNC_VIS wstring to_wstring(float __val);
44230b57cec5SDimitry Andric_LIBCPP_FUNC_VIS wstring to_wstring(double __val);
44240b57cec5SDimitry Andric_LIBCPP_FUNC_VIS wstring to_wstring(long double __val);
4425*349cc55cSDimitry Andric#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
44260b57cec5SDimitry Andric
44270b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
4428fe6060f1SDimitry Andric_LIBCPP_TEMPLATE_DATA_VIS
44290b57cec5SDimitry Andricconst typename basic_string<_CharT, _Traits, _Allocator>::size_type
44300b57cec5SDimitry Andric               basic_string<_CharT, _Traits, _Allocator>::npos;
44310b57cec5SDimitry Andric
44320b57cec5SDimitry Andrictemplate <class _CharT, class _Allocator>
44330b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS
44340b57cec5SDimitry Andric    hash<basic_string<_CharT, char_traits<_CharT>, _Allocator> >
44350b57cec5SDimitry Andric    : public unary_function<
44360b57cec5SDimitry Andric          basic_string<_CharT, char_traits<_CharT>, _Allocator>, size_t>
44370b57cec5SDimitry Andric{
44380b57cec5SDimitry Andric    size_t
44390b57cec5SDimitry Andric    operator()(const basic_string<_CharT, char_traits<_CharT>, _Allocator>& __val) const _NOEXCEPT
44400b57cec5SDimitry Andric    { return __do_string_hash(__val.data(), __val.data() + __val.size()); }
44410b57cec5SDimitry Andric};
44420b57cec5SDimitry Andric
44430b57cec5SDimitry Andric
44440b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
44450b57cec5SDimitry Andricbasic_ostream<_CharT, _Traits>&
44460b57cec5SDimitry Andricoperator<<(basic_ostream<_CharT, _Traits>& __os,
44470b57cec5SDimitry Andric           const basic_string<_CharT, _Traits, _Allocator>& __str);
44480b57cec5SDimitry Andric
44490b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
44500b57cec5SDimitry Andricbasic_istream<_CharT, _Traits>&
44510b57cec5SDimitry Andricoperator>>(basic_istream<_CharT, _Traits>& __is,
44520b57cec5SDimitry Andric           basic_string<_CharT, _Traits, _Allocator>& __str);
44530b57cec5SDimitry Andric
44540b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
44550b57cec5SDimitry Andricbasic_istream<_CharT, _Traits>&
44560b57cec5SDimitry Andricgetline(basic_istream<_CharT, _Traits>& __is,
44570b57cec5SDimitry Andric        basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm);
44580b57cec5SDimitry Andric
44590b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
44600b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
44610b57cec5SDimitry Andricbasic_istream<_CharT, _Traits>&
44620b57cec5SDimitry Andricgetline(basic_istream<_CharT, _Traits>& __is,
44630b57cec5SDimitry Andric        basic_string<_CharT, _Traits, _Allocator>& __str);
44640b57cec5SDimitry Andric
44650b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
44660b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
44670b57cec5SDimitry Andricbasic_istream<_CharT, _Traits>&
44680b57cec5SDimitry Andricgetline(basic_istream<_CharT, _Traits>&& __is,
44690b57cec5SDimitry Andric        basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm);
44700b57cec5SDimitry Andric
44710b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
44720b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
44730b57cec5SDimitry Andricbasic_istream<_CharT, _Traits>&
44740b57cec5SDimitry Andricgetline(basic_istream<_CharT, _Traits>&& __is,
44750b57cec5SDimitry Andric        basic_string<_CharT, _Traits, _Allocator>& __str);
44760b57cec5SDimitry Andric
44770b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 17
44780b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator, class _Up>
44790b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
44805ffd83dbSDimitry Andric    typename basic_string<_CharT, _Traits, _Allocator>::size_type
44815ffd83dbSDimitry Andric    erase(basic_string<_CharT, _Traits, _Allocator>& __str, const _Up& __v) {
44825ffd83dbSDimitry Andric  auto __old_size = __str.size();
44835ffd83dbSDimitry Andric  __str.erase(_VSTD::remove(__str.begin(), __str.end(), __v), __str.end());
44845ffd83dbSDimitry Andric  return __old_size - __str.size();
44855ffd83dbSDimitry Andric}
44860b57cec5SDimitry Andric
44870b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator, class _Predicate>
44880b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
44895ffd83dbSDimitry Andric    typename basic_string<_CharT, _Traits, _Allocator>::size_type
44905ffd83dbSDimitry Andric    erase_if(basic_string<_CharT, _Traits, _Allocator>& __str,
44915ffd83dbSDimitry Andric             _Predicate __pred) {
44925ffd83dbSDimitry Andric  auto __old_size = __str.size();
44935ffd83dbSDimitry Andric  __str.erase(_VSTD::remove_if(__str.begin(), __str.end(), __pred),
44945ffd83dbSDimitry Andric              __str.end());
44955ffd83dbSDimitry Andric  return __old_size - __str.size();
44965ffd83dbSDimitry Andric}
44970b57cec5SDimitry Andric#endif
44980b57cec5SDimitry Andric
4499e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2
45000b57cec5SDimitry Andric
45010b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
45020b57cec5SDimitry Andricbool
45030b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::__dereferenceable(const const_iterator* __i) const
45040b57cec5SDimitry Andric{
4505480093f4SDimitry Andric    return this->data() <= _VSTD::__to_address(__i->base()) &&
4506480093f4SDimitry Andric           _VSTD::__to_address(__i->base()) < this->data() + this->size();
45070b57cec5SDimitry Andric}
45080b57cec5SDimitry Andric
45090b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
45100b57cec5SDimitry Andricbool
45110b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::__decrementable(const const_iterator* __i) const
45120b57cec5SDimitry Andric{
4513480093f4SDimitry Andric    return this->data() < _VSTD::__to_address(__i->base()) &&
4514480093f4SDimitry Andric           _VSTD::__to_address(__i->base()) <= this->data() + this->size();
45150b57cec5SDimitry Andric}
45160b57cec5SDimitry Andric
45170b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
45180b57cec5SDimitry Andricbool
45190b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::__addable(const const_iterator* __i, ptrdiff_t __n) const
45200b57cec5SDimitry Andric{
4521480093f4SDimitry Andric    const value_type* __p = _VSTD::__to_address(__i->base()) + __n;
45220b57cec5SDimitry Andric    return this->data() <= __p && __p <= this->data() + this->size();
45230b57cec5SDimitry Andric}
45240b57cec5SDimitry Andric
45250b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator>
45260b57cec5SDimitry Andricbool
45270b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::__subscriptable(const const_iterator* __i, ptrdiff_t __n) const
45280b57cec5SDimitry Andric{
4529480093f4SDimitry Andric    const value_type* __p = _VSTD::__to_address(__i->base()) + __n;
45300b57cec5SDimitry Andric    return this->data() <= __p && __p < this->data() + this->size();
45310b57cec5SDimitry Andric}
45320b57cec5SDimitry Andric
4533e8d8bef9SDimitry Andric#endif // _LIBCPP_DEBUG_LEVEL == 2
45340b57cec5SDimitry Andric
45350b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11
45360b57cec5SDimitry Andric// Literal suffixes for basic_string [basic.string.literals]
45370b57cec5SDimitry Andricinline namespace literals
45380b57cec5SDimitry Andric{
45390b57cec5SDimitry Andric  inline namespace string_literals
45400b57cec5SDimitry Andric  {
45410b57cec5SDimitry Andric    inline _LIBCPP_INLINE_VISIBILITY
45420b57cec5SDimitry Andric    basic_string<char> operator "" s( const char *__str, size_t __len )
45430b57cec5SDimitry Andric    {
45440b57cec5SDimitry Andric        return basic_string<char> (__str, __len);
45450b57cec5SDimitry Andric    }
45460b57cec5SDimitry Andric
4547*349cc55cSDimitry Andric#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
45480b57cec5SDimitry Andric    inline _LIBCPP_INLINE_VISIBILITY
45490b57cec5SDimitry Andric    basic_string<wchar_t> operator "" s( const wchar_t *__str, size_t __len )
45500b57cec5SDimitry Andric    {
45510b57cec5SDimitry Andric        return basic_string<wchar_t> (__str, __len);
45520b57cec5SDimitry Andric    }
4553*349cc55cSDimitry Andric#endif
45540b57cec5SDimitry Andric
4555fe6060f1SDimitry Andric#ifndef _LIBCPP_HAS_NO_CHAR8_T
45560b57cec5SDimitry Andric    inline _LIBCPP_INLINE_VISIBILITY
45570b57cec5SDimitry Andric    basic_string<char8_t> operator "" s(const char8_t *__str, size_t __len) _NOEXCEPT
45580b57cec5SDimitry Andric    {
45590b57cec5SDimitry Andric        return basic_string<char8_t> (__str, __len);
45600b57cec5SDimitry Andric    }
45610b57cec5SDimitry Andric#endif
45620b57cec5SDimitry Andric
45630b57cec5SDimitry Andric    inline _LIBCPP_INLINE_VISIBILITY
45640b57cec5SDimitry Andric    basic_string<char16_t> operator "" s( const char16_t *__str, size_t __len )
45650b57cec5SDimitry Andric    {
45660b57cec5SDimitry Andric        return basic_string<char16_t> (__str, __len);
45670b57cec5SDimitry Andric    }
45680b57cec5SDimitry Andric
45690b57cec5SDimitry Andric    inline _LIBCPP_INLINE_VISIBILITY
45700b57cec5SDimitry Andric    basic_string<char32_t> operator "" s( const char32_t *__str, size_t __len )
45710b57cec5SDimitry Andric    {
45720b57cec5SDimitry Andric        return basic_string<char32_t> (__str, __len);
45730b57cec5SDimitry Andric    }
45740b57cec5SDimitry Andric  }
45750b57cec5SDimitry Andric}
45760b57cec5SDimitry Andric#endif
45770b57cec5SDimitry Andric
45780b57cec5SDimitry Andric_LIBCPP_END_NAMESPACE_STD
45790b57cec5SDimitry Andric
45800b57cec5SDimitry Andric_LIBCPP_POP_MACROS
45810b57cec5SDimitry Andric
45820b57cec5SDimitry Andric#endif // _LIBCPP_STRING
4583