cxxomfort  rel.20211024
Simple backports for C++ - https://ryan.gulix.cl/fossil.cgi/cxxomfort/
Public Types | Public Member Functions | Static Public Attributes | List of all members
basic_string_view< CharTy, CTraits > Class Template Reference

Read-only view of a string or string-like object, from C++17. See also string/basic_string_view @ cppreference . More...

Public Types

typedef CharTy value_type
 Character type employed by the string.
 
typedef CTraits traits_type
 char_traits corresponding to the character type
 
typedef basetype::element_type element_type
 Element type representing the underlying buffer view.
 
typedef basetype::size_type size_type
 Type representing the amount of characters the string can have.
 
typedef basetype::difference_type difference_type
 Integral type representing the difference between two iterators.
 
typedef CharTy * pointer
 Pointer type for the underlying character storage.
 
typedef CharTy const * const_pointer
 Pointer type to a const view of the underlying character storage.
 
typedef CharTy & reference
 Reference type for the underlying characters.
 
typedef CharTy const & const_reference
 Reference type to a const view of the underlying characters.
 
typedef const_pointer const_iterator
 Iterator type.
 
typedef basetype::const_reverse_iterator const_reverse_iterator
 Reverse iterator type.
 

Public Member Functions

constexpr basic_string_view () noexcept=default
 default-ctor: empty string.
 
constexpr basic_string_view (basic_string_view const &) noexcept=default
 copy-ctor
 
CXXO_CONSTEXPR basic_string_view (CharTy const *px, size_t sz) CXXO_NOEXCEPTNOTHROW
 string_view to characters at position px with length sz .
 
 basic_string_view (const_pointer const px) CXXO_NOEXCEPTNOTHROW
 string_view to characters at position px and length reported by CTraits::length .
 
template<typename IBegin , typename IEnd >
 basic_string_view (IBegin ini, IEnd fin)
 Iterator constructor, added in C++20.
 
CXXO_CONSTEXPR size_type length () const CXXO_NOEXCEPTNOTHROW
 Returns the length of the viewed string.
 
const_reference at (size_type idx) const
 Accesses characters in the string, checked.
 
size_type copy (CharTy *d, size_type count, size_type pos=0) const
 Copies contents from the viewed string to a CharTy array.
 
basic_string_view substr (size_type pos, size_type count=npos) const
 Returns a view of part of the string.
 
int compare (basic_string_view const r) const CXXO_NOEXCEPTNOTHROW
 strcmp -like compare against another string view
 
CXXO_CONSTEXPR14 size_type find (basic_string_view s, size_type pos=0) const CXXO_NOEXCEPTNOTHROW
 Find a substring.
 
CXXO_CONSTEXPR14 size_type find (CharTy const, size_type pos=0) const CXXO_NOEXCEPTNOTHROW
 Find a character.
 
size_type find (const_pointer s, size_type pos=0) const CXXO_NOEXCEPTNOTHROW
 Find a substring.
 
size_type find (const_pointer s, size_type pos, size_type count) const CXXO_NOEXCEPTNOTHROW
 Find a substring.
 
size_type rfind (basic_string_view, size_type pos=0) const CXXO_NOEXCEPTNOTHROW
 Find last instance of a string.
 
size_type rfind (CharTy, size_type pos=0) const CXXO_NOEXCEPTNOTHROW
 Find last instance of a character.
 
size_type rfind (const_pointer s, size_type pos=0) const CXXO_NOEXCEPTNOTHROW
 Find last instance of a string.
 
size_type rfind (const_pointer s, size_type pos, size_type count) const CXXO_NOEXCEPTNOTHROW
 Find last instance of a string.
 

Static Public Attributes

static const size_type npos = size_type(-1)
 Flag that indicates a position not found.
 

Additional Inherited Members

- Protected Types inherited from array_ref< T, IdxType >
typedef T element_type
 Type of the data contained in the view.
 
typedef std::remove_cv< element_type >::type value_type
 Type of variables of the type of the pointed-to data.
 
typedef std::add_const< value_type >::type const_value_type
 const version of the value_type .
 
typedef ptrdiff_t difference_type
 Type for the distance between pointers or iterators.
 
typedef IdxType size_type
 Type for subscript / indexed access (eg.: operator[]).
 
typedef std::add_pointer< element_type >::type pointer
 Type of a pointer to a contained value; potentially writable.
 
typedef std::add_pointer< element_type const >::type const_pointer
 Type of a pointer to a contained value; view-only.
 
typedef pointer iterator
 Iterator type; potentially writable.
 
typedef const_pointer const_iterator
 Iterator type; view-only.
 
typedef std::reverse_iterator< iteratorreverse_iterator
 Reverse iterator type; potentially writable.
 
typedef std::reverse_iterator< const_iteratorconst_reverse_iterator
 Reverse iterator type; view-only.
 
- Protected Member Functions inherited from array_ref< T, IdxType >
constexpr array_ref () noexcept=default
 Trivial constructor; creates a view to nothing.
 
constexpr array_ref (array_ref const &) noexcept=default
 Copy constructor (trivial)
 
constexpr array_refoperator= (array_ref const &) noexcept=default
 Assignment operator (trivial)
 
CXXO_CONSTEXPR array_ref (pointer p, size_type len) CXXO_NOEXCEPTNOTHROW
 Construct a view to a buffer starting at p and of len units long.
 
CXXO_CONSTEXPR array_ref (std::nullptr_t, pointer p, pointer q) CXXO_NOEXCEPTNOTHROW
 Construct a view to a buffer starting at p and ending at q (not in the original n3334 proposal).
 
CXXO_CONSTEXPR array_ref (pointer p, pointer q) CXXO_NOEXCEPTNOTHROW
 Construct a view to a buffer starting at p and ending at q (not in the original n3334 proposal).
 
template<size_t N>
CXXO_CONSTEXPR array_ref (T(&arr)[N]) CXXO_NOEXCEPTNOTHROW
 Constructs a view over a native C array.
 
reference operator[] (size_type i) CXXO_NOEXCEPTNOTHROW
 Unchecked access to the i -th element.
 
CXXO_CONSTEXPR const_reference operator[] (size_type i) const CXXO_NOEXCEPTNOTHROW
 Unchecked access to the i -th element.
 
reference at (size_type i)
 Checked access to the i -th element; throw.
 
const_reference at (size_type i) const
 Checked access to the i -th element; throw.
 
reference at_or (size_type i, reference alt) CXXO_NOEXCEPTNOTHROW
 Checked access to the i -th element; returns an alternative if it doesn't exist.
 
CXXO_CONSTEXPR const_reference at_or (size_type i, const_reference alt) const CXXO_NOEXCEPTNOTHROW
 Checked access to the i -th element; returns an alternative if it doesn't exist.
 
CXXO_CONSTEXPR size_type size () const CXXO_NOEXCEPTNOTHROW
 
CXXO_CONSTEXPR bool empty () const CXXO_NOEXCEPTNOTHROW
 
CXXO_CONSTEXPR14 pointer data () CXXO_NOEXCEPTNOTHROW
 
CXXO_CONSTEXPR const_pointer data () const CXXO_NOEXCEPTNOTHROW
 
CXXO_CONSTEXPR size_type size_bytes () const CXXO_NOEXCEPTNOTHROW
 
CXXO_CONSTEXPR const_iterator cbegin () const CXXO_NOEXCEPTNOTHROW
 begin
 
CXXO_CONSTEXPR const_iterator cend () const CXXO_NOEXCEPTNOTHROW
 end
 
iterator begin () CXXO_NOEXCEPTNOTHROW
 begin
 
iterator end () CXXO_NOEXCEPTNOTHROW
 end
 
CXXO_CONSTEXPR const_iterator begin () const CXXO_NOEXCEPTNOTHROW
 begin
 
CXXO_CONSTEXPR const_iterator end () const CXXO_NOEXCEPTNOTHROW
 end
 
CXXO_CONSTEXPR const_reverse_iterator crbegin () const CXXO_NOEXCEPTNOTHROW
 reverse-begin
 
CXXO_CONSTEXPR const_reverse_iterator crend () const CXXO_NOEXCEPTNOTHROW
 reverse-end
 
reverse_iterator rbegin () CXXO_NOEXCEPTNOTHROW
 reverse-begin
 
reverse_iterator rend () CXXO_NOEXCEPTNOTHROW
 reverse-end
 
const_reverse_iterator rbegin () const CXXO_NOEXCEPTNOTHROW
 reverse-begin
 
const_reverse_iterator rend () const CXXO_NOEXCEPTNOTHROW
 reverse-end
 
CXXO_CONSTEXPR14 const_iterator front () const CXXO_NOEXCEPTNOTHROW
 Unchecked (!) access to the 0th element.
 
iterator front () CXXO_NOEXCEPTNOTHROW
 Unchecked (!) access to the 0th element.
 
CXXO_CONSTEXPR14 const_iterator back () const CXXO_NOEXCEPTNOTHROW
 Unchecked (!) access to the last element.
 
iterator back () CXXO_NOEXCEPTNOTHROW
 Unchecked (!) access to the last element.
 
CXXO_CONSTEXPR array_ref substr (size_type pos, size_type count) const
 Returns a view to the count -elements subsequence starting from pos .
 
array_ref substr (size_type pos) const
 
array_ref leftmost (size_type n) const CXXO_NOEXCEPTNOTHROW
 Returns a view to the leftmost (first) n elements.
 
array_ref rightmost (size_type n) const CXXO_NOEXCEPTNOTHROW
 Returns a view to the rightmost (last) n elements.
 
array_ref slice (difference_type pos, size_type count) const
 Returns a view of sub-contents from position pos which can be negative, ala PHP, JS.
 
array_ref slice (difference_type pos) const
 
CXXO_CONSTEXPR14 array_ref without_back_n (size_type n) const
 Removes the last n elements.
 
CXXO_CONSTEXPR14 array_ref without_front_n (size_type n) const
 Removes the first n elements.
 
CXXO_CONSTEXPR14 array_ref without_back () const
 Returns a view with the last element removed.
 
CXXO_CONSTEXPR14 array_ref without_front () const
 Returns a view with the first element removed.
 

Detailed Description

template<class CharTy, class CTraits = std::char_traits<CharTy>>
class cxxomfort::cxxostd::basic_string_view< CharTy, CTraits >

Read-only view of a string or string-like object, from C++17. See also string/basic_string_view @ cppreference .

A basic_string_view is a view (non-owning) to a buffer of characters representing a string object, and given a set of operations.

Differences with std::basic_string_view

Cxxomfort's basic_string_view has a number of differences from the std version in C++17 onwards, documented here for clarity. Largely the differences lie in the member functions, as cxxomfort intentionally chooses to not implement the hundreditude of member functions that std::basic_string_view inherits from the bad design of std::basic_string .

Compared to the std version, the cxxomfort implementation:

Cxxomfort also offers the helper sv_helper in order to construct basic_string_view s easily; and starting with C++11 it implements the ""sv user-defined literal as well.

See also
string/basic_string_view @ cppreference .
"sv" helper sv("text")

The documentation for this class was generated from the following file: