[/ Copyright 2021 Peter Dimov Distributed under the Boost Software License, Version 1.0. https://boost.org/LICENSE_1_0.txt ] [section:string_view string_view] [simplesect Authors] * Peter Dimov [endsimplesect] [section Header ] The header `` defines `boost::core::string_view`, a portable and interoperable implementation of `std::string_view`. Unlike `boost::string_view`, `boost::core::string_view` has implicit conversions from and to `std::string_view`, which allows Boost libraries that support C++11/C++14 to use it in interfaces without forcing users to forgo the use of `std::string_view` in their code. [section Synopsis] `` namespace boost { namespace core { template class basic_string_view { private: Ch const* data_; std::size_t size_; public: // types typedef std::char_traits traits_type; typedef Ch value_type; typedef Ch* pointer; typedef Ch const* const_pointer; typedef Ch& reference; typedef Ch const& const_reference; typedef Ch const* const_iterator; typedef const_iterator iterator; typedef std::reverse_iterator const_reverse_iterator; typedef const_reverse_iterator reverse_iterator; typedef std::size_t size_type; typedef std::ptrdiff_t difference_type; // npos static constexpr size_type npos = static_cast( -1 ); public: // construction and assignment constexpr basic_string_view() noexcept; constexpr basic_string_view( basic_string_view const& ) noexcept = default; constexpr basic_string_view& operator=( basic_string_view const& ) noexcept & = default; constexpr basic_string_view( Ch const* str ) noexcept; constexpr basic_string_view( Ch const* str, size_type len ) noexcept; constexpr basic_string_view( Ch const* begin, Ch const* end ) noexcept; template basic_string_view( std::basic_string, A> const& str ) noexcept; basic_string_view( std::basic_string_view> const& str ) noexcept; // conversions template operator std::basic_string, A>() const; template operator std::basic_string_view() const noexcept; // iterator support constexpr const_iterator begin() const noexcept; constexpr const_iterator end() const noexcept; constexpr const_iterator cbegin() const noexcept; constexpr const_iterator cend() const noexcept; constexpr const_reverse_iterator rbegin() const noexcept; constexpr const_reverse_iterator rend() const noexcept; constexpr const_reverse_iterator crbegin() const noexcept; constexpr const_reverse_iterator crend() const noexcept; // capacity constexpr size_type size() const noexcept; constexpr size_type length() const noexcept; constexpr size_type max_size() const noexcept; constexpr bool empty() const noexcept; // element access constexpr const_reference operator[]( size_type pos ) const noexcept; constexpr const_reference at( size_type pos ) const; constexpr const_reference front() const noexcept; constexpr const_reference back() const noexcept; constexpr const_pointer data() const noexcept; // modifiers constexpr void remove_prefix( size_type n ) noexcept; constexpr void remove_suffix( size_type n ) noexcept; constexpr void swap( basic_string_view& s ) noexcept; // string operations constexpr size_type copy( Ch* s, size_type n, size_type pos = 0 ) const; constexpr basic_string_view substr( size_type pos = 0, size_type n = npos ) const; // compare constexpr int compare( basic_string_view s ) const noexcept; constexpr int compare( size_type pos1, size_type n1, basic_string_view s ) const; constexpr int compare( size_type pos1, size_type n1, basic_string_view s, size_type pos2, size_type n2 ) const; constexpr int compare( Ch const* s ) const; constexpr int compare( size_type pos1, size_type n1, Ch const* s ) const; constexpr int compare( size_type pos1, size_type n1, Ch const* s, size_type n2 ) const; // starts_with constexpr bool starts_with( basic_string_view x ) const noexcept; constexpr bool starts_with( Ch x ) const noexcept; constexpr bool starts_with( Ch const* x ) const; // ends_with constexpr bool ends_with( basic_string_view x ) const noexcept; constexpr bool ends_with( Ch x ) const noexcept; constexpr bool ends_with( Ch const* x ) const; // find constexpr size_type find( basic_string_view s, size_type pos = 0 ) const noexcept; constexpr size_type find( Ch c, size_type pos = 0 ) const noexcept; constexpr size_type find( Ch const* s, size_type pos, size_type n ) const; constexpr size_type find( Ch const* s, size_type pos = 0 ) const; // rfind constexpr size_type rfind( basic_string_view s, size_type pos = npos ) const noexcept; constexpr size_type rfind( Ch c, size_type pos = npos ) const noexcept; constexpr size_type rfind( Ch const* s, size_type pos, size_type n ) const; constexpr size_type rfind( Ch const* s, size_type pos = npos ) const; // find_first_of constexpr size_type find_first_of( basic_string_view s, size_type pos = 0 ) const noexcept; constexpr size_type find_first_of( Ch c, size_type pos = 0 ) const noexcept; constexpr size_type find_first_of( Ch const* s, size_type pos, size_type n ) const; constexpr size_type find_first_of( Ch const* s, size_type pos = 0 ) const; // find_last_of constexpr size_type find_last_of( basic_string_view s, size_type pos = npos ) const noexcept; constexpr size_type find_last_of( Ch c, size_type pos = npos ) const noexcept; constexpr size_type find_last_of( Ch const* s, size_type pos, size_type n ) const; constexpr size_type find_last_of( Ch const* s, size_type pos = npos ) const; // find_first_not_of constexpr size_type find_first_not_of( basic_string_view s, size_type pos = 0 ) const noexcept; constexpr size_type find_first_not_of( Ch c, size_type pos = 0 ) const noexcept; constexpr size_type find_first_not_of( Ch const* s, size_type pos, size_type n ) const; constexpr size_type find_first_not_of( Ch const* s, size_type pos = 0 ) const; // find_last_not_of constexpr size_type find_last_not_of( basic_string_view s, size_type pos = npos ) const noexcept; constexpr size_type find_last_not_of( Ch c, size_type pos = npos ) const noexcept; constexpr size_type find_last_not_of( Ch const* s, size_type pos, size_type n ) const; constexpr size_type find_last_not_of( Ch const* s, size_type pos = npos ) const; // contains constexpr bool contains( basic_string_view sv ) const noexcept; constexpr bool contains( Ch c ) const noexcept; constexpr bool contains( Ch const* s ) const noexcept; // relational operators constexpr friend bool operator==( basic_string_view sv1, basic_string_view sv2 ) noexcept; constexpr friend bool operator!=( basic_string_view sv1, basic_string_view sv2 ) noexcept; constexpr friend bool operator<( basic_string_view sv1, basic_string_view sv2 ) noexcept; constexpr friend bool operator<=( basic_string_view sv1, basic_string_view sv2 ) noexcept; constexpr friend bool operator>( basic_string_view sv1, basic_string_view sv2 ) noexcept; constexpr friend bool operator>=( basic_string_view sv1, basic_string_view sv2 ) noexcept; }; // stream inserter template std::basic_ostream& operator<<( std::basic_ostream& os, basic_string_view str ) // typedef names typedef basic_string_view string_view; typedef basic_string_view wstring_view; typedef basic_string_view u16string_view; typedef basic_string_view u32string_view; typedef basic_string_view u8string_view; } // namespace core } // namespace boost `` [endsect] [section Construction] [section constexpr basic_string_view() noexcept;] * *Ensures:* `data() == 0`, `size() == 0`. [endsect] [section constexpr basic_string_view( Ch const* str ) noexcept;] [endsect] [section constexpr basic_string_view( Ch const* str, size_type len ) noexcept;] [endsect] [section constexpr basic_string_view( Ch const* begin, Ch const* end ) noexcept;] [endsect] [section template basic_string_view( std::basic_string, A> const& str ) noexcept;] [endsect] [section basic_string_view( std::basic_string_view> const& str ) noexcept;] [endsect] [endsect] [section Conversions] [endsect] [section Iterator Support] [endsect] [section Capacity] [endsect] [section Element Access] [endsect] [section Modifiers] [endsect] [section String Operations] [section copy] [endsect] [section substr] [endsect] [section compare] [endsect] [section starts_with] [endsect] [section ends_with] [endsect] [endsect] [section Searching] [section find] [endsect] [section rfind] [endsect] [section find_first_of] [endsect] [section find_last_of] [endsect] [section find_first_not_of] [endsect] [section find_last_not_of] [endsect] [section contains] [endsect] [endsect] [section Relational Operators] [endsect] [section Stream Inserter] [endsect] [endsect] [endsect]