Backport
bpstd::basic_string_view< CharT, Traits > Class Template Reference

A semantic non-owning wrapper around contiguous character sequences. More...

#include <string_view.hpp>

Public Types

using char_type = CharT
 
using traits_type = Traits
 
using size_type = std::size_t
 
using value_type = CharT
 
using reference = value_type &
 
using const_reference = const value_type &
 
using pointer = value_type *
 
using const_pointer = const value_type *
 
using iterator = const CharT *
 
using const_iterator = const CharT *
 
using reverse_iterator = std::reverse_iterator< iterator >
 
using const_reverse_iterator = std::reverse_iterator< const_iterator >
 

Public Member Functions

constexpr basic_string_view () noexcept
 Default constructs a basic_string_view without any content.
 
constexpr basic_string_view (const basic_string_view &other) noexcept=default
 Constructs a basic_string_view by copying another one. More...
 
constexpr basic_string_view (basic_string_view &&other) noexcept=default
 Constructs a basic_string_view by moving anothe rone. More...
 
template<typename Allocator >
 basic_string_view (const std::basic_string< CharT, Traits, Allocator > &str) noexcept
 Constructs a basic_string_view from a std::basic_string. More...
 
constexpr basic_string_view (const char_type *str) noexcept
 Constructs a basic_string_view from an ansi-string. More...
 
constexpr basic_string_view (const char_type *str, size_type count) noexcept
 Constructs a basic_string_view from an ansi string of a given size. More...
 
basic_string_view & operator= (const basic_string_view &view)=default
 Assigns a basic_string_view from an ansi-string. More...
 
constexpr size_type max_size () const noexcept
 The largest possible number of char-like objects that can be referred to by a basic_string_view. More...
 
constexpr bool empty () const noexcept
 Returns whether the basic_string_view is empty (i.e. whether its length is 0). More...
 
constexpr const char_type * data () const noexcept
 Gets the data of the current basic_string_view. More...
 
constexpr const_reference operator[] (size_type pos) const noexcept
 Accesses the element at index pos. More...
 
constexpr const_reference at (size_type pos) const
 Accesses the element at index pos. More...
 
constexpr const_reference front () const noexcept
 Access the first character of the string. More...
 
constexpr const_reference back () const noexcept
 References the last character of the string. More...
 
BPSTD_CPP14_CONSTEXPR void remove_prefix (size_type n) noexcept
 Moves the start of the view forward by n characters. More...
 
BPSTD_CPP14_CONSTEXPR void remove_suffix (size_type n) noexcept
 Moves the end of the view back by n characters. More...
 
BPSTD_CPP14_CONSTEXPR void swap (basic_string_view &v) noexcept
 Exchanges the view with that of v. More...
 
template<typename Allocator >
constexpr operator std::basic_string< CharT, Traits, Allocator > () const
 Creates a basic_string with a copy of the content of the current view. More...
 
BPSTD_CPP14_CONSTEXPR size_type copy (char_type *dest, size_type count=npos, size_type pos=0) const
 Copies the substring [pos, pos + rcount) to the character string pointed to by dest, where rcount is the smaller of count and size() - pos. More...
 
BPSTD_CPP14_CONSTEXPR basic_string_view substr (size_t pos=0, size_t len=npos) const
 Returns a substring of this viewed string. More...
 
BPSTD_CPP14_CONSTEXPR int compare (basic_string_view v) const noexcept
 Compares two character sequences. More...
 
BPSTD_CPP14_CONSTEXPR int compare (size_type pos, size_type count, basic_string_view v) const
 Compares two character sequences. More...
 
BPSTD_CPP14_CONSTEXPR int compare (size_type pos1, size_type count1, basic_string_view v, size_type pos2, size_type count2) const
 Compares two character sequences. More...
 
BPSTD_CPP14_CONSTEXPR int compare (const char_type *s) const
 Compares two character sequences. More...
 
BPSTD_CPP14_CONSTEXPR int compare (size_type pos, size_type count, const char_type *s) const
 Compares two character sequences. More...
 
BPSTD_CPP14_CONSTEXPR int compare (size_type pos, size_type count1, const char_type *s, size_type count2) const
 Compares two character sequences. More...
 
BPSTD_CPP14_CONSTEXPR size_type find (basic_string_view v, size_type pos=0) const
 
BPSTD_CPP14_CONSTEXPR size_type find (char_type c, size_type pos=0) const
 
BPSTD_CPP14_CONSTEXPR size_type find (const char_type *s, size_type pos, size_type count) const
 
BPSTD_CPP14_CONSTEXPR size_type find (const char_type *s, size_type pos=0) const
 
BPSTD_CPP14_CONSTEXPR size_type rfind (basic_string_view v, size_type pos=npos) const
 
BPSTD_CPP14_CONSTEXPR size_type rfind (char_type c, size_type pos=npos) const
 
BPSTD_CPP14_CONSTEXPR size_type rfind (const char_type *s, size_type pos, size_type count) const
 
BPSTD_CPP14_CONSTEXPR size_type rfind (const char_type *s, size_type pos=npos) const
 
BPSTD_CPP14_CONSTEXPR size_type find_first_of (basic_string_view v, size_type pos=0) const
 
BPSTD_CPP14_CONSTEXPR size_type find_first_of (char_type c, size_type pos=0) const
 
BPSTD_CPP14_CONSTEXPR size_type find_first_of (const char_type *s, size_type pos, size_type count) const
 
BPSTD_CPP14_CONSTEXPR size_type find_first_of (const char_type *s, size_type pos=0) const
 
BPSTD_CPP14_CONSTEXPR size_type find_last_of (basic_string_view v, size_type pos=npos) const
 
BPSTD_CPP14_CONSTEXPR size_type find_last_of (char_type c, size_type pos=npos) const
 
BPSTD_CPP14_CONSTEXPR size_type find_last_of (const char_type *s, size_type pos, size_type count) const
 
BPSTD_CPP14_CONSTEXPR size_type find_last_of (const char_type *s, size_type pos=npos) const
 
BPSTD_CPP14_CONSTEXPR size_type find_first_not_of (basic_string_view v, size_type pos=0) const
 
BPSTD_CPP14_CONSTEXPR size_type find_first_not_of (char_type c, size_type pos=0) const
 
BPSTD_CPP14_CONSTEXPR size_type find_first_not_of (const char_type *s, size_type pos, size_type count) const
 
BPSTD_CPP14_CONSTEXPR size_type find_first_not_of (const char_type *s, size_type pos=0) const
 
BPSTD_CPP14_CONSTEXPR size_type find_last_not_of (basic_string_view v, size_type pos=npos) const
 
BPSTD_CPP14_CONSTEXPR size_type find_last_not_of (char_type c, size_type pos=npos) const
 
BPSTD_CPP14_CONSTEXPR size_type find_last_not_of (const char_type *s, size_type pos, size_type count) const
 
BPSTD_CPP14_CONSTEXPR size_type find_last_not_of (const char_type *s, size_type pos=npos) const
 
template<typename Allocator >
BPSTD_INLINE_VISIBILITY basic_string_view (const std::basic_string< CharT, Traits, Allocator > &str) noexcept
 
template<class Allocator >
constexpr BPSTD_INLINE_VISIBILITY operator std::basic_string< CharT, Traits, Allocator > () const
 
constexpr size_type size () const noexcept
 Returns the length of the string, in terms of bytes. More...
 
constexpr size_type length () const noexcept
 Returns the length of the string, in terms of bytes. More...
 
BPSTD_CPP14_CONSTEXPR const_iterator begin () const noexcept
 Retrieves the begin iterator for this basic_string_view. More...
 
BPSTD_CPP14_CONSTEXPR const_iterator cbegin () const noexcept
 Retrieves the begin iterator for this basic_string_view. More...
 
BPSTD_CPP14_CONSTEXPR const_iterator end () const noexcept
 Retrieves the end iterator for this basic_string_view. More...
 
BPSTD_CPP14_CONSTEXPR const_iterator cend () const noexcept
 Retrieves the end iterator for this basic_string_view. More...
 
BPSTD_CPP14_CONSTEXPR const_reverse_iterator rbegin () const noexcept
 Retrieves the reverse begin iterator for this basic_string_view. More...
 
BPSTD_CPP14_CONSTEXPR const_reverse_iterator rend () const noexcept
 Retrieves the reverse begin iterator for this basic_string_view. More...
 
BPSTD_CPP14_CONSTEXPR const_reverse_iterator crbegin () const noexcept
 Retrieves the reverse end iterator for this basic_string_view. More...
 
BPSTD_CPP14_CONSTEXPR const_reverse_iterator crend () const noexcept
 Retrieves the reverse end iterator for this basic_string_view. More...
 

Static Public Attributes

static constexpr size_type npos = size_type(-1)
 

Detailed Description

template<typename CharT, typename Traits = std::char_traits<CharT>>
class bpstd::basic_string_view< CharT, Traits >

A semantic non-owning wrapper around contiguous character sequences.

This class describes an object that can refer to a constant contiguous sequence of char-like objects with the first element of the sequence at position zero.

Definition at line 61 of file string_view.hpp.

Constructor & Destructor Documentation

◆ basic_string_view() [1/5]

template<typename CharT , typename Traits = std::char_traits<CharT>>
constexpr bpstd::basic_string_view< CharT, Traits >::basic_string_view ( const basic_string_view< CharT, Traits > &  other)
constexprdefaultnoexcept

Constructs a basic_string_view by copying another one.

Parameters
otherthe string view being copied

◆ basic_string_view() [2/5]

template<typename CharT , typename Traits = std::char_traits<CharT>>
constexpr bpstd::basic_string_view< CharT, Traits >::basic_string_view ( basic_string_view< CharT, Traits > &&  other)
constexprdefaultnoexcept

Constructs a basic_string_view by moving anothe rone.

Parameters
otherthe string view being moved

◆ basic_string_view() [3/5]

template<typename CharT , typename Traits = std::char_traits<CharT>>
template<typename Allocator >
bpstd::basic_string_view< CharT, Traits >::basic_string_view ( const std::basic_string< CharT, Traits, Allocator > &  str)
noexcept

Constructs a basic_string_view from a std::basic_string.

Parameters
strthe string to view

◆ basic_string_view() [4/5]

template<typename CharT , typename Traits >
constexpr BPSTD_INLINE_VISIBILITY bpstd::basic_string_view< CharT, Traits >::basic_string_view ( const char_type *  str)
inlineconstexprnoexcept

Constructs a basic_string_view from an ansi-string.

Parameters
strthe string to view

Definition at line 548 of file string_view.hpp.

◆ basic_string_view() [5/5]

template<typename CharT , typename Traits >
constexpr BPSTD_INLINE_VISIBILITY bpstd::basic_string_view< CharT, Traits >::basic_string_view ( const char_type *  str,
size_type  count 
)
inlineconstexprnoexcept

Constructs a basic_string_view from an ansi string of a given size.

Parameters
strthe string to view
countthe size of the string

Definition at line 559 of file string_view.hpp.

Member Function Documentation

◆ at()

template<typename CharT , typename Traits >
constexpr BPSTD_INLINE_VISIBILITY bpstd::basic_string_view< CharT, Traits >::const_reference bpstd::basic_string_view< CharT, Traits >::at ( size_type  pos) const
inlineconstexpr

Accesses the element at index pos.

Parameters
posthe index to access
Returns
const reference to the character

Definition at line 631 of file string_view.hpp.

◆ back()

template<typename CharT , typename Traits >
constexpr BPSTD_INLINE_VISIBILITY bpstd::basic_string_view< CharT, Traits >::const_reference bpstd::basic_string_view< CharT, Traits >::back
inlineconstexprnoexcept

References the last character of the string.

Note
Undefined behavior if basic_string_view is empty
Returns
reference to the last character of the string

Definition at line 651 of file string_view.hpp.

◆ begin()

template<typename CharT , typename Traits >
BPSTD_INLINE_VISIBILITY BPSTD_CPP14_CONSTEXPR bpstd::basic_string_view< CharT, Traits >::const_iterator bpstd::basic_string_view< CharT, Traits >::begin
inlinenoexcept

Retrieves the begin iterator for this basic_string_view.

Returns
the begin iterator

Definition at line 1159 of file string_view.hpp.

◆ cbegin()

template<typename CharT , typename Traits >
BPSTD_INLINE_VISIBILITY BPSTD_CPP14_CONSTEXPR bpstd::basic_string_view< CharT, Traits >::const_iterator bpstd::basic_string_view< CharT, Traits >::cbegin
inlinenoexcept

Retrieves the begin iterator for this basic_string_view.

Returns
the begin iterator

Definition at line 1168 of file string_view.hpp.

◆ cend()

template<typename CharT , typename Traits >
BPSTD_INLINE_VISIBILITY BPSTD_CPP14_CONSTEXPR bpstd::basic_string_view< CharT, Traits >::const_iterator bpstd::basic_string_view< CharT, Traits >::cend
inlinenoexcept

Retrieves the end iterator for this basic_string_view.

Returns
the end iterator

Definition at line 1186 of file string_view.hpp.

◆ compare() [1/6]

template<typename CharT , typename Traits >
BPSTD_INLINE_VISIBILITY BPSTD_CPP14_CONSTEXPR int bpstd::basic_string_view< CharT, Traits >::compare ( basic_string_view< CharT, Traits >  v) const
inlinenoexcept

Compares two character sequences.

Parameters
vview to compare
Returns
negative value if this view is less than the other character sequence, zero if the both character sequences are equal, positive value if this view is greater than the other character sequence.

Definition at line 748 of file string_view.hpp.

◆ compare() [2/6]

template<typename CharT , typename Traits >
BPSTD_INLINE_VISIBILITY BPSTD_CPP14_CONSTEXPR int bpstd::basic_string_view< CharT, Traits >::compare ( const char_type *  s) const
inline

Compares two character sequences.

Parameters
spointer to the character string to compare to
Returns
negative value if this view is less than the other character sequence, zero if the both character sequences are equal, positive value if this view is greater than the other character sequence.

Definition at line 793 of file string_view.hpp.

◆ compare() [3/6]

template<typename CharT , typename Traits >
BPSTD_INLINE_VISIBILITY BPSTD_CPP14_CONSTEXPR int bpstd::basic_string_view< CharT, Traits >::compare ( size_type  pos,
size_type  count,
basic_string_view< CharT, Traits >  v 
) const
inline

Compares two character sequences.

Parameters
posposition of the first character in this view to compare
countnumber of characters of this view to compare
vview to compare
Returns
negative value if this view is less than the other character sequence, zero if the both character sequences are equal, positive value if this view is greater than the other character sequence.

Definition at line 769 of file string_view.hpp.

◆ compare() [4/6]

template<typename CharT , typename Traits >
BPSTD_INLINE_VISIBILITY BPSTD_CPP14_CONSTEXPR int bpstd::basic_string_view< CharT, Traits >::compare ( size_type  pos,
size_type  count,
const char_type *  s 
) const
inline

Compares two character sequences.

Parameters
posposition of the first character in this view to compare
countnumber of characters of this view to compare
spointer to the character string to compare to
Returns
negative value if this view is less than the other character sequence, zero if the both character sequences are equal, positive value if this view is greater than the other character sequence.

Definition at line 802 of file string_view.hpp.

◆ compare() [5/6]

template<typename CharT , typename Traits >
BPSTD_INLINE_VISIBILITY BPSTD_CPP14_CONSTEXPR int bpstd::basic_string_view< CharT, Traits >::compare ( size_type  pos,
size_type  count1,
const char_type *  s,
size_type  count2 
) const
inline

Compares two character sequences.

Parameters
posposition of the first character in this view to compare
count1number of characters of this view to compare
spointer to the character string to compare to
count2number of characters of the given view to compare
Returns
negative value if this view is less than the other character sequence, zero if the both character sequences are equal, positive value if this view is greater than the other character sequence.

Definition at line 813 of file string_view.hpp.

◆ compare() [6/6]

template<typename CharT , typename Traits >
BPSTD_INLINE_VISIBILITY BPSTD_CPP14_CONSTEXPR int bpstd::basic_string_view< CharT, Traits >::compare ( size_type  pos1,
size_type  count1,
basic_string_view< CharT, Traits >  v,
size_type  pos2,
size_type  count2 
) const
inline

Compares two character sequences.

Parameters
pos1position of the first character in this view to compare
count1number of characters of this view to compare
vview to compare
pos2position of the second character in this view to compare
count2number of characters of the given view to compare
Returns
negative value if this view is less than the other character sequence, zero if the both character sequences are equal, positive value if this view is greater than the other character sequence.

Definition at line 780 of file string_view.hpp.

◆ copy()

template<typename CharT , typename Traits >
BPSTD_INLINE_VISIBILITY BPSTD_CPP14_CONSTEXPR bpstd::basic_string_view< CharT, Traits >::size_type bpstd::basic_string_view< CharT, Traits >::copy ( char_type *  dest,
size_type  count = npos,
size_type  pos = 0 
) const
inline

Copies the substring [pos, pos + rcount) to the character string pointed to by dest, where rcount is the smaller of count and size() - pos.

Parameters
destpointer to the destination character string
countrequested substring length
posposition of the first character

Definition at line 708 of file string_view.hpp.

◆ crbegin()

template<typename CharT , typename Traits >
BPSTD_INLINE_VISIBILITY BPSTD_CPP14_CONSTEXPR bpstd::basic_string_view< CharT, Traits >::const_reverse_iterator bpstd::basic_string_view< CharT, Traits >::crbegin
inlinenoexcept

Retrieves the reverse end iterator for this basic_string_view.

Returns
the reverse end iterator

Definition at line 1204 of file string_view.hpp.

◆ crend()

template<typename CharT , typename Traits >
BPSTD_INLINE_VISIBILITY BPSTD_CPP14_CONSTEXPR bpstd::basic_string_view< CharT, Traits >::const_reverse_iterator bpstd::basic_string_view< CharT, Traits >::crend
inlinenoexcept

Retrieves the reverse end iterator for this basic_string_view.

Returns
the reverse end iterator

Definition at line 1222 of file string_view.hpp.

◆ data()

template<typename CharT , typename Traits >
constexpr const BPSTD_INLINE_VISIBILITY bpstd::basic_string_view< CharT, Traits >::char_type * bpstd::basic_string_view< CharT, Traits >::data
inlineconstexprnoexcept

Gets the data of the current basic_string_view.

Note
This is an alias of #c_str
Returns
the data this basic_string_view contains

Definition at line 613 of file string_view.hpp.

◆ empty()

template<typename CharT , typename Traits >
constexpr BPSTD_INLINE_VISIBILITY bool bpstd::basic_string_view< CharT, Traits >::empty
inlineconstexprnoexcept

Returns whether the basic_string_view is empty (i.e. whether its length is 0).

Returns
whether the basic_string_view is empty

Definition at line 600 of file string_view.hpp.

◆ end()

template<typename CharT , typename Traits >
BPSTD_INLINE_VISIBILITY BPSTD_CPP14_CONSTEXPR bpstd::basic_string_view< CharT, Traits >::const_iterator bpstd::basic_string_view< CharT, Traits >::end
inlinenoexcept

Retrieves the end iterator for this basic_string_view.

Returns
the end iterator

Definition at line 1177 of file string_view.hpp.

◆ front()

template<typename CharT , typename Traits >
constexpr BPSTD_INLINE_VISIBILITY bpstd::basic_string_view< CharT, Traits >::const_reference bpstd::basic_string_view< CharT, Traits >::front
inlineconstexprnoexcept

Access the first character of the string.

Note
Undefined behavior if basic_string_view is empty
Returns
reference to the first character of the string

Definition at line 642 of file string_view.hpp.

◆ length()

template<typename CharT , typename Traits >
constexpr BPSTD_INLINE_VISIBILITY bpstd::basic_string_view< CharT, Traits >::size_type bpstd::basic_string_view< CharT, Traits >::length
inlineconstexprnoexcept

Returns the length of the string, in terms of bytes.

Returns
the length of the string, in terms of bytes

Definition at line 583 of file string_view.hpp.

◆ max_size()

template<typename CharT , typename Traits >
constexpr BPSTD_INLINE_VISIBILITY bpstd::basic_string_view< CharT, Traits >::size_type bpstd::basic_string_view< CharT, Traits >::max_size
inlineconstexprnoexcept

The largest possible number of char-like objects that can be referred to by a basic_string_view.

Returns
Maximum number of characters

Definition at line 592 of file string_view.hpp.

◆ operator std::basic_string< CharT, Traits, Allocator >()

template<typename CharT , typename Traits = std::char_traits<CharT>>
template<typename Allocator >
constexpr bpstd::basic_string_view< CharT, Traits >::operator std::basic_string< CharT, Traits, Allocator > ( ) const
explicitconstexpr

Creates a basic_string with a copy of the content of the current view.

Returns
A basic_string containing a copy of the characters of the current view.

◆ operator=()

template<typename CharT , typename Traits = std::char_traits<CharT>>
basic_string_view& bpstd::basic_string_view< CharT, Traits >::operator= ( const basic_string_view< CharT, Traits > &  view)
default

Assigns a basic_string_view from an ansi-string.

Parameters
viewthe string to view
Returns
reference to (*this)

◆ operator[]()

template<typename CharT , typename Traits >
constexpr BPSTD_INLINE_VISIBILITY bpstd::basic_string_view< CharT, Traits >::const_reference bpstd::basic_string_view< CharT, Traits >::operator[] ( size_type  pos) const
inlineconstexprnoexcept

Accesses the element at index pos.

Parameters
posthe index to access
Returns
const reference to the character

Definition at line 622 of file string_view.hpp.

◆ rbegin()

template<typename CharT , typename Traits >
BPSTD_INLINE_VISIBILITY BPSTD_CPP14_CONSTEXPR bpstd::basic_string_view< CharT, Traits >::const_reverse_iterator bpstd::basic_string_view< CharT, Traits >::rbegin
inlinenoexcept

Retrieves the reverse begin iterator for this basic_string_view.

Returns
the reverse begin iterator

Definition at line 1195 of file string_view.hpp.

◆ remove_prefix()

template<typename CharT , typename Traits >
BPSTD_INLINE_VISIBILITY BPSTD_CPP14_CONSTEXPR void bpstd::basic_string_view< CharT, Traits >::remove_prefix ( size_type  n)
inlinenoexcept

Moves the start of the view forward by n characters.

The behavior is undefined if n > size().

Parameters
nnumber of characters to remove from the start of the view

Definition at line 663 of file string_view.hpp.

◆ remove_suffix()

template<typename CharT , typename Traits >
BPSTD_INLINE_VISIBILITY BPSTD_CPP14_CONSTEXPR void bpstd::basic_string_view< CharT, Traits >::remove_suffix ( size_type  n)
inlinenoexcept

Moves the end of the view back by n characters.

The behavior is undefined if n > size().

Parameters
nnumber of characters to remove from the end of the view

Definition at line 671 of file string_view.hpp.

◆ rend()

template<typename CharT , typename Traits >
BPSTD_INLINE_VISIBILITY BPSTD_CPP14_CONSTEXPR bpstd::basic_string_view< CharT, Traits >::const_reverse_iterator bpstd::basic_string_view< CharT, Traits >::rend
inlinenoexcept

Retrieves the reverse begin iterator for this basic_string_view.

Returns
the reverse begin iterator

Definition at line 1213 of file string_view.hpp.

◆ size()

template<typename CharT , typename Traits >
constexpr BPSTD_INLINE_VISIBILITY bpstd::basic_string_view< CharT, Traits >::size_type bpstd::basic_string_view< CharT, Traits >::size
inlineconstexprnoexcept

Returns the length of the string, in terms of bytes.

Returns
the length of the string, in terms of bytes

Definition at line 574 of file string_view.hpp.

◆ substr()

template<typename CharT , typename Traits = std::char_traits<CharT>>
BPSTD_INLINE_VISIBILITY BPSTD_CPP14_CONSTEXPR bpstd::basic_string_view< CharT, Traits > bpstd::basic_string_view< CharT, Traits >::substr ( size_t  pos = 0,
size_t  len = npos 
) const
inline

Returns a substring of this viewed string.

Parameters
posthe position of the first character in the substring
lenthe length of the substring
Returns
the created substring

Definition at line 730 of file string_view.hpp.

◆ swap()

template<typename CharT , typename Traits >
BPSTD_INLINE_VISIBILITY BPSTD_CPP14_CONSTEXPR void bpstd::basic_string_view< CharT, Traits >::swap ( basic_string_view< CharT, Traits > &  v)
inlinenoexcept

Exchanges the view with that of v.

Parameters
vview to swap with

Definition at line 679 of file string_view.hpp.


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