My Project
Public Types | Public Member Functions | Static Public Member Functions | Related Functions | List of all members
bsl::basic_string_view< CharT, Traits > Class Template Referencefinal

A bsl::basic_string_view is a non-owning, encapsulation of a string, providing helper functions for working with strings. More...

#include <basic_string_view.hpp>

Public Types

using value_type = CharT const
 alias for: CharT const
 
using size_type = bsl::uintmax
 alias for: bsl::uintmax
 
using difference_type = bsl::uintmax
 alias for: bsl::uintmax
 
using reference_type = CharT const &
 alias for: CharT const &
 
using const_reference_type = CharT const &
 alias for: CharT const &
 
using pointer_type = CharT const *
 alias for: CharT const *
 
using const_pointer_type = CharT const *
 alias for: CharT const const *
 
using iterator_type = contiguous_iterator< CharT const >
 alias for: contiguous_iterator<CharT const>
 
using const_iterator_type = contiguous_iterator< CharT const >
 alias for: contiguous_iterator<CharT const const>
 
using reverse_iterator_type = reverse_iterator< iterator_type >
 alias for: reverse_iterator<iterator>
 
using const_reverse_iterator_type = reverse_iterator< const_iterator_type >
 alias for: reverse_iterator<const_iterator>
 

Public Member Functions

constexpr basic_string_view () noexcept=default
 Default constructor that creates a basic_string_view with data() == nullptr and size() == 0. All accessors will return a nullptr if used. Note that like other view types in the BSL, the bsl::basic_string_view is a POD type. This means that when declaring a global, default constructed bsl::basic_string_view, DO NOT include the {} for initialization. Instead, remove the {} and the global bsl::basic_string_view will be included in the BSS section of the executable, and initialized to 0 for you. All other instantiations of a bsl::basic_string_view (or any POD type), should be initialized using {} to ensure the POD is properly initialized. Using the above method for global initialization ensures that global constructors are not executed at runtime, which is required by AUTOSAR. More...
 
constexpr basic_string_view (pointer_type const s) noexcept
 ptr constructor. This creates a bsl::basic_string_view given a pointer to a string. The number of characters in the string is determined using Traits<CharT>::length, which scans for '\0'. More...
 
constexpr basic_string_viewoperator= (pointer_type const s) &noexcept
 ptr assignment. This assigns a bsl::basic_string_view a pointer to a string. The number of characters in the string is determined using Traits<CharT>::length, which scans for '\0'. More...
 
constexpr pointer_type at_if (size_type const index) noexcept
 Returns a pointer to the instance of T stored at index "index". If the index is out of bounds, or the view is invalid, this function returns a nullptr. More...
 
constexpr const_pointer_type at_if (size_type const index) const noexcept
 Returns a pointer to the instance of T stored at index "index". If the index is out of bounds, or the view is invalid, this function returns a nullptr. More...
 
constexpr pointer_type front_if () noexcept
 Returns a pointer to the instance of T stored at index "0". If the index is out of bounds, or the view is invalid, this function returns a nullptr. More...
 
constexpr const_pointer_type front_if () const noexcept
 Returns a pointer to the instance of T stored at index "0". If the index is out of bounds, or the view is invalid, this function returns a nullptr. More...
 
constexpr pointer_type back_if () noexcept
 Returns a pointer to the instance of T stored at index "size() - 1". If the index is out of bounds, or the view is invalid, this function returns a nullptr. More...
 
constexpr const_pointer_type back_if () const noexcept
 Returns a pointer to the instance of T stored at index "size() - 1". If the index is out of bounds, or the view is invalid, this function returns a nullptr. More...
 
constexpr pointer_type data () noexcept
 Returns a pointer to the string being viewed. If this is a default constructed view, or the view was constructed in error, this will return a nullptr. More...
 
constexpr const_pointer_type data () const noexcept
 Returns a pointer to the string being viewed. If this is a default constructed view, or the view was constructed in error, this will return a nullptr. More...
 
constexpr iterator_type begin () noexcept
 Returns an iterator to the first element of the view. More...
 
constexpr const_iterator_type begin () const noexcept
 Returns an iterator to the first element of the view. More...
 
constexpr const_iterator_type cbegin () const noexcept
 Returns an iterator to the first element of the view. More...
 
constexpr iterator_type iter (size_type const i) noexcept
 Returns an iterator to the element "i" in the view. More...
 
constexpr const_iterator_type iter (size_type const i) const noexcept
 Returns an iterator to the element "i" in the view. More...
 
constexpr const_iterator_type citer (size_type const i) const noexcept
 Returns an iterator to the element "i" in the view. More...
 
constexpr iterator_type end () noexcept
 Returns an iterator to one past the last element of the view. If you attempt to access this iterator, a nullptr will always be returned. More...
 
constexpr const_iterator_type end () const noexcept
 Returns an iterator to one past the last element of the view. If you attempt to access this iterator, a nullptr will always be returned. More...
 
constexpr const_iterator_type cend () const noexcept
 Returns an iterator to one past the last element of the view. If you attempt to access this iterator, a nullptr will always be returned. More...
 
constexpr reverse_iterator_type rbegin () noexcept
 Returns a reverse iterator to one past the last element of the view. When accessing the iterator, the iterator will always return the element T[internal index - 1], providing access to the range [size() - 1, 0) while internally storing the range [size(), 1) with element 0 representing the end(). For more information, see the bsl::reverse_iterator documentation. More...
 
constexpr const_reverse_iterator_type rbegin () const noexcept
 Returns a reverse iterator to one past the last element of the view. When accessing the iterator, the iterator will always return the element T[internal index - 1], providing access to the range [size() - 1, 0) while internally storing the range [size(), 1) with element 0 representing the end(). For more information, see the bsl::reverse_iterator documentation. More...
 
constexpr const_reverse_iterator_type crbegin () const noexcept
 Returns a reverse iterator to one past the last element of the view. When accessing the iterator, the iterator will always return the element T[internal index - 1], providing access to the range [size() - 1, 0) while internally storing the range [size(), 1) with element 0 representing the end(). For more information, see the bsl::reverse_iterator documentation. More...
 
constexpr reverse_iterator_type riter (size_type const i) noexcept
 Returns a reverse iterator element "i" in the view. When accessing the iterator, the iterator will always return the element T[internal index - 1], providing access to the range [size() - 1, 0) while internally storing the range [size(), 1) with element 0 representing the end(). For more information, see the bsl::reverse_iterator documentation. More...
 
constexpr const_reverse_iterator_type riter (size_type const i) const noexcept
 Returns a reverse iterator element "i" in the view. When accessing the iterator, the iterator will always return the element T[internal index - 1], providing access to the range [size() - 1, 0) while internally storing the range [size(), 1) with element 0 representing the end(). For more information, see the bsl::reverse_iterator documentation. More...
 
constexpr const_reverse_iterator_type criter (size_type const i) const noexcept
 Returns a reverse iterator element "i" in the view. When accessing the iterator, the iterator will always return the element T[internal index - 1], providing access to the range [size() - 1, 0) while internally storing the range [size(), 1) with element 0 representing the end(). For more information, see the bsl::reverse_iterator documentation. More...
 
constexpr reverse_iterator_type rend () noexcept
 Returns a reverse iterator first element of the view. When accessing the iterator, the iterator will always return the element T[internal index - 1], providing access to the range [size() - 1, 0) while internally storing the range [size(), 1) with element 0 representing the end(). For more information, see the bsl::reverse_iterator documentation. More...
 
constexpr const_reverse_iterator_type rend () const noexcept
 Returns a reverse iterator first element of the view. When accessing the iterator, the iterator will always return the element T[internal index - 1], providing access to the range [size() - 1, 0) while internally storing the range [size(), 1) with element 0 representing the end(). For more information, see the bsl::reverse_iterator documentation. More...
 
constexpr const_reverse_iterator_type crend () const noexcept
 Returns a reverse iterator first element of the view. When accessing the iterator, the iterator will always return the element T[internal index - 1], providing access to the range [size() - 1, 0) while internally storing the range [size(), 1) with element 0 representing the end(). For more information, see the bsl::reverse_iterator documentation. More...
 
constexpr bool empty () const noexcept
 Returns size() == 0. More...
 
constexpr size_type size () const noexcept
 Returns the number of elements in the string being viewed. If this is a default constructed view, or the view was constructed in error, this will return 0. More...
 
constexpr size_type length () const noexcept
 Returns the length of the string being viewed. This is the same as bsl::basic_string_view::size(). Note that the length refers to the total number of characters in the string and not the number of bytes in the string. For the total number of bytes, use bsl::basic_string_view::size_bytes(). More...
 
constexpr size_type size_bytes () const noexcept
 Returns size() * sizeof(T) More...
 
constexpr basic_string_viewremove_prefix (size_type const n) noexcept
 Moves the start of the view forward by n characters. If n >= size(), the bsl::basic_string_view is reset to a NULL string, with data() returning a nullptr, and size() returning 0. More...
 
constexpr basic_string_viewremove_suffix (size_type const n) noexcept
 Moves the end of the view back by n characters. If n >= size(), the bsl::basic_string_view is reset to a NULL string, with data() returning a nullptr, and size() returning 0. More...
 
constexpr basic_string_view substr (size_type const pos=0U, size_type const count=npos) const noexcept
 Returns a new bsl::basic_string_view that is a substring view of the original. The substring starts at "pos" and ends at "pos" + "count". Note that this does not copy the string, it simply changes the internal pointer and size of the same string that is currently being viewed (meaning the lifetime of the new substring cannot outlive the lifetime of the string being viewed by the original bsl::basic_string_view). If the provided "pos" or "count" are invalid, this function returns an empty string view. More...
 
constexpr bsl::int32 compare (basic_string_view const &str) const noexcept
 Compares two strings. More...
 
constexpr bsl::int32 compare (size_type const pos, size_type const count, basic_string_view const &str) const noexcept
 Same as substr(pos, count).compare(v) More...
 
constexpr bsl::int32 compare (size_type pos1, size_type count1, basic_string_view const &str, size_type pos2, size_type count2) const noexcept
 Same as substr(pos1, count1).compare(v.substr(pos2, count2)) More...
 
constexpr bsl::int32 compare (pointer_type const str) const noexcept
 Same as compare(basic_string_view{s}) More...
 
constexpr bsl::int32 compare (size_type pos, size_type count, pointer_type const str) const noexcept
 Same as substr(pos, count).compare(basic_string_view{s}) More...
 
constexpr bsl::int32 compare (size_type pos, size_type count1, pointer_type const str, size_type count2) const noexcept
 Same as substr(pos, count1).compare(basic_string_view{s, count2}) More...
 
constexpr bool starts_with (basic_string_view const &str) const noexcept
 Checks if the string begins with the given prefix. More...
 
constexpr bool starts_with (value_type const c) const noexcept
 Checks if the string begins with the given prefix. More...
 
constexpr bool starts_with (pointer_type const str) const noexcept
 Checks if the string begins with the given prefix. More...
 
constexpr bool ends_with (basic_string_view const &str) const noexcept
 Checks if the string ends with the given suffix. More...
 
constexpr bool ends_with (value_type const c) const noexcept
 Checks if the string ends with the given suffix. More...
 
constexpr bool ends_with (pointer_type const str) const noexcept
 Checks if the string ends with the given suffix. More...
 

Static Public Member Functions

static constexpr size_type max_size () noexcept
 Returns the max number of elements the BSL supports. More...
 

Related Functions

(Note that these are not member functions.)

using string_view = basic_string_view< char_type >
 provides the default string_view prototype More...
 
template<typename CharT , typename Traits >
constexpr bool operator== (bsl::basic_string_view< CharT, Traits > const &lhs, bsl::basic_string_view< CharT, Traits > const &rhs) noexcept
 Returns true if two strings have the same length (which is different from compare() which uses the minimum size between the two provided strings), and contain the same characters. Returns false otherwise. More...
 
template<typename CharT , typename Traits >
constexpr bool operator== (bsl::basic_string_view< CharT, Traits > const &lhs, CharT const *const rhs) noexcept
 Returns true if two strings have the same length (which is different from compare() which uses the minimum size between the two provided strings), and contain the same characters. Returns false otherwise. More...
 
template<typename CharT , typename Traits >
constexpr bool operator== (CharT const *const lhs, bsl::basic_string_view< CharT, Traits > const &rhs) noexcept
 Returns true if two strings have the same length (which is different from compare() which uses the minimum size between the two provided strings), and contain the same characters. Returns false otherwise. More...
 
template<typename CharT , typename Traits >
constexpr bool operator!= (bsl::basic_string_view< CharT, Traits > const &lhs, bsl::basic_string_view< CharT, Traits > const &rhs) noexcept
 Returns true if two strings are not the same length (which is different from compare() which uses the minimum size between the two provided strings), or contain different characters. Returns false otherwise. More...
 
template<typename CharT , typename Traits >
constexpr bool operator!= (bsl::basic_string_view< CharT, Traits > const &lhs, CharT const *const rhs) noexcept
 Returns true if two strings are not the same length (which is different from compare() which uses the minimum size between the two provided strings), or contain different characters. Returns false otherwise. More...
 
template<typename CharT , typename Traits >
constexpr bool operator!= (CharT const *const lhs, bsl::basic_string_view< CharT, Traits > const &rhs) noexcept
 Returns true if two strings are not the same length (which is different from compare() which uses the minimum size between the two provided strings), or contain different characters. Returns false otherwise. More...
 
template<typename OUT , typename CharT >
constexpr void fmt_impl (OUT &&o, fmt_options const &ops, basic_string_view< CharT > const &str) noexcept
 This function is responsible for implementing bsl::fmt for string_view types. For strings, the only fmt options that are available are alignment, fill and width, all of which are handled by the fmt_impl_align_xxx functions. More...
 
template<typename T , typename CharT >
constexpr out< T > operator<< (out< T > const o, basic_string_view< CharT > const &str) noexcept
 Outputs the provided string_view to the provided output type. More...
 

Detailed Description

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

A bsl::basic_string_view is a non-owning, encapsulation of a string, providing helper functions for working with strings.

#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_basic_string_view_overview() noexcept
{
constexpr bsl::basic_string_view<bsl::char_type> str1{"Hello World"};
constexpr bsl::basic_string_view<bsl::char_type> str2{"Hello World"};
if (str1 == str2) {
bsl::print() << "success\n";
}
}
}
Template Parameters
CharTthe type of characters in the string
Traitsthe traits class used to work with the string

Constructor & Destructor Documentation

◆ basic_string_view() [1/2]

template<typename CharT, typename Traits = char_traits<CharT>>
constexpr bsl::basic_string_view< CharT, Traits >::basic_string_view ( )
defaultnoexcept

Default constructor that creates a basic_string_view with data() == nullptr and size() == 0. All accessors will return a nullptr if used. Note that like other view types in the BSL, the bsl::basic_string_view is a POD type. This means that when declaring a global, default constructed bsl::basic_string_view, DO NOT include the {} for initialization. Instead, remove the {} and the global bsl::basic_string_view will be included in the BSS section of the executable, and initialized to 0 for you. All other instantiations of a bsl::basic_string_view (or any POD type), should be initialized using {} to ensure the POD is properly initialized. Using the above method for global initialization ensures that global constructors are not executed at runtime, which is required by AUTOSAR.

#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_basic_string_view_default_constructor() noexcept
{
if (str.empty()) {
bsl::print() << "success\n";
}
}
}

◆ basic_string_view() [2/2]

template<typename CharT, typename Traits = char_traits<CharT>>
constexpr bsl::basic_string_view< CharT, Traits >::basic_string_view ( pointer_type const  s)
inlinenoexcept

ptr constructor. This creates a bsl::basic_string_view given a pointer to a string. The number of characters in the string is determined using Traits<CharT>::length, which scans for '\0'.

#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_basic_string_view_s_constructor() noexcept
{
constexpr bsl::basic_string_view<bsl::char_type> str1{"Hello"};
constexpr bsl::basic_string_view<bsl::char_type> str2{"Hello"};
if (str1 == str2) {
bsl::print() << "success\n";
}
}
}

SUPPRESSION: PRQA 2180 - false positive

  • We suppress this because A12-1-4 states that all constructors that are callable from a fundamental type should be marked as explicit. This is not a fundamental type and there for does not apply (as pointers are not fundamental types).
Parameters
sa pointer to the string

Member Function Documentation

◆ operator=()

template<typename CharT, typename Traits = char_traits<CharT>>
constexpr basic_string_view& bsl::basic_string_view< CharT, Traits >::operator= ( pointer_type const  s) &
inlinenoexcept

ptr assignment. This assigns a bsl::basic_string_view a pointer to a string. The number of characters in the string is determined using Traits<CharT>::length, which scans for '\0'.

#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_basic_string_view_s_assignment() noexcept
{
str = "Hello";
if (str == "Hello") {
bsl::print() << "success\n";
}
}
}
Parameters
sa pointer to the string
Returns
Returns *this

◆ at_if() [1/2]

template<typename CharT, typename Traits = char_traits<CharT>>
constexpr pointer_type bsl::basic_string_view< CharT, Traits >::at_if ( size_type const  index)
inlinenoexcept

Returns a pointer to the instance of T stored at index "index". If the index is out of bounds, or the view is invalid, this function returns a nullptr.

#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_basic_string_view_at_if() noexcept
{
if (auto const *const ptr = str.at_if(0U)) {
bsl::print() << "success: " << *ptr << bsl::endl;
}
}
}

SUPPRESSION: PRQA 4024 - false positive

  • We suppress this because A9-3-1 states that we should not provide a non-const reference or pointer to private member function, unless the class mimics a smart pointer or a containter. This class mimics a container.
Parameters
indexthe index of the instance to return
Returns
Returns a pointer to the instance of T stored at index "index". If the index is out of bounds, or the view is invalid, this function returns a nullptr.

◆ at_if() [2/2]

template<typename CharT, typename Traits = char_traits<CharT>>
constexpr const_pointer_type bsl::basic_string_view< CharT, Traits >::at_if ( size_type const  index) const
inlinenoexcept

Returns a pointer to the instance of T stored at index "index". If the index is out of bounds, or the view is invalid, this function returns a nullptr.

#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_basic_string_view_at_if() noexcept
{
if (auto const *const ptr = str.at_if(0U)) {
bsl::print() << "success: " << *ptr << bsl::endl;
}
}
}
Parameters
indexthe index of the instance to return
Returns
Returns a pointer to the instance of T stored at index "index". If the index is out of bounds, or the view is invalid, this function returns a nullptr.

◆ front_if() [1/2]

template<typename CharT, typename Traits = char_traits<CharT>>
constexpr pointer_type bsl::basic_string_view< CharT, Traits >::front_if ( )
inlinenoexcept

Returns a pointer to the instance of T stored at index "0". If the index is out of bounds, or the view is invalid, this function returns a nullptr.

#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_basic_string_view_front_if() noexcept
{
if (auto const *const ptr = str.front_if()) {
bsl::print() << "success: " << *ptr << bsl::endl;
}
}
}
Returns
Returns a pointer to the instance of T stored at index "0". If the index is out of bounds, or the view is invalid, this function returns a nullptr.

◆ front_if() [2/2]

template<typename CharT, typename Traits = char_traits<CharT>>
constexpr const_pointer_type bsl::basic_string_view< CharT, Traits >::front_if ( ) const
inlinenoexcept

Returns a pointer to the instance of T stored at index "0". If the index is out of bounds, or the view is invalid, this function returns a nullptr.

#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_basic_string_view_front_if() noexcept
{
if (auto const *const ptr = str.front_if()) {
bsl::print() << "success: " << *ptr << bsl::endl;
}
}
}
Returns
Returns a pointer to the instance of T stored at index "0". If the index is out of bounds, or the view is invalid, this function returns a nullptr.

◆ back_if() [1/2]

template<typename CharT, typename Traits = char_traits<CharT>>
constexpr pointer_type bsl::basic_string_view< CharT, Traits >::back_if ( )
inlinenoexcept

Returns a pointer to the instance of T stored at index "size() - 1". If the index is out of bounds, or the view is invalid, this function returns a nullptr.

#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_basic_string_view_back_if() noexcept
{
if (auto const *const ptr = str.back_if()) {
bsl::print() << "success: " << *ptr << bsl::endl;
}
}
}
Returns
Returns a pointer to the instance of T stored at index "size() - 1". If the index is out of bounds, or the view is invalid, this function returns a nullptr.

◆ back_if() [2/2]

template<typename CharT, typename Traits = char_traits<CharT>>
constexpr const_pointer_type bsl::basic_string_view< CharT, Traits >::back_if ( ) const
inlinenoexcept

Returns a pointer to the instance of T stored at index "size() - 1". If the index is out of bounds, or the view is invalid, this function returns a nullptr.

#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_basic_string_view_back_if() noexcept
{
if (auto const *const ptr = str.back_if()) {
bsl::print() << "success: " << *ptr << bsl::endl;
}
}
}
Returns
Returns a pointer to the instance of T stored at index "size() - 1". If the index is out of bounds, or the view is invalid, this function returns a nullptr.

◆ data() [1/2]

template<typename CharT, typename Traits = char_traits<CharT>>
constexpr pointer_type bsl::basic_string_view< CharT, Traits >::data ( )
inlinenoexcept

Returns a pointer to the string being viewed. If this is a default constructed view, or the view was constructed in error, this will return a nullptr.

#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_basic_string_view_data() noexcept
{
if (nullptr != str.data()) {
bsl::print() << "success\n";
}
}
}
Returns
Returns a pointer to the string being viewed. If this is a default constructed view, or the view was constructed in error, this will return a nullptr.

◆ data() [2/2]

template<typename CharT, typename Traits = char_traits<CharT>>
constexpr const_pointer_type bsl::basic_string_view< CharT, Traits >::data ( ) const
inlinenoexcept

Returns a pointer to the string being viewed. If this is a default constructed view, or the view was constructed in error, this will return a nullptr.

#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_basic_string_view_data() noexcept
{
if (nullptr != str.data()) {
bsl::print() << "success\n";
}
}
}
Returns
Returns a pointer to the string being viewed. If this is a default constructed view, or the view was constructed in error, this will return a nullptr.

◆ begin() [1/2]

template<typename CharT, typename Traits = char_traits<CharT>>
constexpr iterator_type bsl::basic_string_view< CharT, Traits >::begin ( )
inlinenoexcept

Returns an iterator to the first element of the view.

#include <bsl/for_each.hpp>
#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_basic_string_view_begin() noexcept
{
bsl::for_each(str.begin(), str.end(), [](auto &e, auto const i) noexcept {
bsl::print() << "element [" << i << "] == " << e << bsl::endl;
});
}
}
Returns
Returns an iterator to the first element of the view.

◆ begin() [2/2]

template<typename CharT, typename Traits = char_traits<CharT>>
constexpr const_iterator_type bsl::basic_string_view< CharT, Traits >::begin ( ) const
inlinenoexcept

Returns an iterator to the first element of the view.

#include <bsl/for_each.hpp>
#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_basic_string_view_begin() noexcept
{
bsl::for_each(str.begin(), str.end(), [](auto &e, auto const i) noexcept {
bsl::print() << "element [" << i << "] == " << e << bsl::endl;
});
}
}
Returns
Returns an iterator to the first element of the view.

◆ cbegin()

template<typename CharT, typename Traits = char_traits<CharT>>
constexpr const_iterator_type bsl::basic_string_view< CharT, Traits >::cbegin ( ) const
inlinenoexcept

Returns an iterator to the first element of the view.

#include <bsl/for_each.hpp>
#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_basic_string_view_begin() noexcept
{
bsl::for_each(str.begin(), str.end(), [](auto &e, auto const i) noexcept {
bsl::print() << "element [" << i << "] == " << e << bsl::endl;
});
}
}
Returns
Returns an iterator to the first element of the view.

◆ iter() [1/2]

template<typename CharT, typename Traits = char_traits<CharT>>
constexpr iterator_type bsl::basic_string_view< CharT, Traits >::iter ( size_type const  i)
inlinenoexcept

Returns an iterator to the element "i" in the view.

#include <bsl/for_each.hpp>
#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_basic_string_view_iter() noexcept
{
constexpr bsl::uintmax i1{1U};
constexpr bsl::uintmax i4{4U};
bsl::for_each(str.iter(i1), str.iter(i4), [](auto &e, auto const i) noexcept {
bsl::print() << "element [" << i << "] == " << e << bsl::endl;
});
}
}
Parameters
ithe element in the string to return an iterator for.
Returns
Returns an iterator to the element "i" in the view.

◆ iter() [2/2]

template<typename CharT, typename Traits = char_traits<CharT>>
constexpr const_iterator_type bsl::basic_string_view< CharT, Traits >::iter ( size_type const  i) const
inlinenoexcept

Returns an iterator to the element "i" in the view.

#include <bsl/for_each.hpp>
#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_basic_string_view_iter() noexcept
{
constexpr bsl::uintmax i1{1U};
constexpr bsl::uintmax i4{4U};
bsl::for_each(str.iter(i1), str.iter(i4), [](auto &e, auto const i) noexcept {
bsl::print() << "element [" << i << "] == " << e << bsl::endl;
});
}
}
Parameters
ithe element in the string to return an iterator for.
Returns
Returns an iterator to the element "i" in the view.

◆ citer()

template<typename CharT, typename Traits = char_traits<CharT>>
constexpr const_iterator_type bsl::basic_string_view< CharT, Traits >::citer ( size_type const  i) const
inlinenoexcept

Returns an iterator to the element "i" in the view.

#include <bsl/for_each.hpp>
#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_basic_string_view_iter() noexcept
{
constexpr bsl::uintmax i1{1U};
constexpr bsl::uintmax i4{4U};
bsl::for_each(str.iter(i1), str.iter(i4), [](auto &e, auto const i) noexcept {
bsl::print() << "element [" << i << "] == " << e << bsl::endl;
});
}
}
Parameters
ithe element in the string to return an iterator for.
Returns
Returns an iterator to the element "i" in the view.

◆ end() [1/2]

template<typename CharT, typename Traits = char_traits<CharT>>
constexpr iterator_type bsl::basic_string_view< CharT, Traits >::end ( )
inlinenoexcept

Returns an iterator to one past the last element of the view. If you attempt to access this iterator, a nullptr will always be returned.

#include <bsl/for_each.hpp>
#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_basic_string_view_end() noexcept
{
bsl::for_each(str.begin(), str.end(), [](auto &e, auto const i) noexcept {
bsl::print() << "element [" << i << "] == " << e << bsl::endl;
});
}
}
Returns
Returns an iterator to one past the last element of the view. If you attempt to access this iterator, a nullptr will always be returned.

◆ end() [2/2]

template<typename CharT, typename Traits = char_traits<CharT>>
constexpr const_iterator_type bsl::basic_string_view< CharT, Traits >::end ( ) const
inlinenoexcept

Returns an iterator to one past the last element of the view. If you attempt to access this iterator, a nullptr will always be returned.

#include <bsl/for_each.hpp>
#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_basic_string_view_end() noexcept
{
bsl::for_each(str.begin(), str.end(), [](auto &e, auto const i) noexcept {
bsl::print() << "element [" << i << "] == " << e << bsl::endl;
});
}
}
Returns
Returns an iterator to one past the last element of the view. If you attempt to access this iterator, a nullptr will always be returned.

◆ cend()

template<typename CharT, typename Traits = char_traits<CharT>>
constexpr const_iterator_type bsl::basic_string_view< CharT, Traits >::cend ( ) const
inlinenoexcept

Returns an iterator to one past the last element of the view. If you attempt to access this iterator, a nullptr will always be returned.

#include <bsl/for_each.hpp>
#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_basic_string_view_end() noexcept
{
bsl::for_each(str.begin(), str.end(), [](auto &e, auto const i) noexcept {
bsl::print() << "element [" << i << "] == " << e << bsl::endl;
});
}
}
Returns
Returns an iterator to one past the last element of the view. If you attempt to access this iterator, a nullptr will always be returned.

◆ rbegin() [1/2]

template<typename CharT, typename Traits = char_traits<CharT>>
constexpr reverse_iterator_type bsl::basic_string_view< CharT, Traits >::rbegin ( )
inlinenoexcept

Returns a reverse iterator to one past the last element of the view. When accessing the iterator, the iterator will always return the element T[internal index - 1], providing access to the range [size() - 1, 0) while internally storing the range [size(), 1) with element 0 representing the end(). For more information, see the bsl::reverse_iterator documentation.

#include <bsl/for_each.hpp>
#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_basic_string_view_rbegin() noexcept
{
bsl::for_each(str.rbegin(), str.rend(), [](auto &e, auto const i) noexcept {
bsl::print() << "element [" << i << "] == " << e << bsl::endl;
});
}
}
Returns
Returns a reverse iterator to the last element of the view.

◆ rbegin() [2/2]

template<typename CharT, typename Traits = char_traits<CharT>>
constexpr const_reverse_iterator_type bsl::basic_string_view< CharT, Traits >::rbegin ( ) const
inlinenoexcept

Returns a reverse iterator to one past the last element of the view. When accessing the iterator, the iterator will always return the element T[internal index - 1], providing access to the range [size() - 1, 0) while internally storing the range [size(), 1) with element 0 representing the end(). For more information, see the bsl::reverse_iterator documentation.

#include <bsl/for_each.hpp>
#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_basic_string_view_rbegin() noexcept
{
bsl::for_each(str.rbegin(), str.rend(), [](auto &e, auto const i) noexcept {
bsl::print() << "element [" << i << "] == " << e << bsl::endl;
});
}
}
Returns
Returns a reverse iterator to the last element of the view.

◆ crbegin()

template<typename CharT, typename Traits = char_traits<CharT>>
constexpr const_reverse_iterator_type bsl::basic_string_view< CharT, Traits >::crbegin ( ) const
inlinenoexcept

Returns a reverse iterator to one past the last element of the view. When accessing the iterator, the iterator will always return the element T[internal index - 1], providing access to the range [size() - 1, 0) while internally storing the range [size(), 1) with element 0 representing the end(). For more information, see the bsl::reverse_iterator documentation.

#include <bsl/for_each.hpp>
#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_basic_string_view_rbegin() noexcept
{
bsl::for_each(str.rbegin(), str.rend(), [](auto &e, auto const i) noexcept {
bsl::print() << "element [" << i << "] == " << e << bsl::endl;
});
}
}
Returns
Returns a reverse iterator to the last element of the view.

◆ riter() [1/2]

template<typename CharT, typename Traits = char_traits<CharT>>
constexpr reverse_iterator_type bsl::basic_string_view< CharT, Traits >::riter ( size_type const  i)
inlinenoexcept

Returns a reverse iterator element "i" in the view. When accessing the iterator, the iterator will always return the element T[internal index - 1], providing access to the range [size() - 1, 0) while internally storing the range [size(), 1) with element 0 representing the end(). For more information, see the bsl::reverse_iterator documentation.

#include <bsl/for_each.hpp>
#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_basic_string_view_riter() noexcept
{
constexpr bsl::uintmax i1{1U};
constexpr bsl::uintmax i4{4U};
bsl::for_each(str.riter(i4), str.riter(i1), [](auto &e, auto const i) noexcept {
bsl::print() << "element [" << i << "] == " << e << bsl::endl;
});
}
}
Parameters
ithe element in the string to return an iterator for.
Returns
Returns a reverse iterator element "i" in the view.

◆ riter() [2/2]

template<typename CharT, typename Traits = char_traits<CharT>>
constexpr const_reverse_iterator_type bsl::basic_string_view< CharT, Traits >::riter ( size_type const  i) const
inlinenoexcept

Returns a reverse iterator element "i" in the view. When accessing the iterator, the iterator will always return the element T[internal index - 1], providing access to the range [size() - 1, 0) while internally storing the range [size(), 1) with element 0 representing the end(). For more information, see the bsl::reverse_iterator documentation.

#include <bsl/for_each.hpp>
#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_basic_string_view_riter() noexcept
{
constexpr bsl::uintmax i1{1U};
constexpr bsl::uintmax i4{4U};
bsl::for_each(str.riter(i4), str.riter(i1), [](auto &e, auto const i) noexcept {
bsl::print() << "element [" << i << "] == " << e << bsl::endl;
});
}
}
Parameters
ithe element in the string to return an iterator for.
Returns
Returns a reverse iterator element "i" in the view.

◆ criter()

template<typename CharT, typename Traits = char_traits<CharT>>
constexpr const_reverse_iterator_type bsl::basic_string_view< CharT, Traits >::criter ( size_type const  i) const
inlinenoexcept

Returns a reverse iterator element "i" in the view. When accessing the iterator, the iterator will always return the element T[internal index - 1], providing access to the range [size() - 1, 0) while internally storing the range [size(), 1) with element 0 representing the end(). For more information, see the bsl::reverse_iterator documentation.

#include <bsl/for_each.hpp>
#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_basic_string_view_riter() noexcept
{
constexpr bsl::uintmax i1{1U};
constexpr bsl::uintmax i4{4U};
bsl::for_each(str.riter(i4), str.riter(i1), [](auto &e, auto const i) noexcept {
bsl::print() << "element [" << i << "] == " << e << bsl::endl;
});
}
}
Parameters
ithe element in the string to return an iterator for.
Returns
Returns a reverse iterator element "i" in the view.

◆ rend() [1/2]

template<typename CharT, typename Traits = char_traits<CharT>>
constexpr reverse_iterator_type bsl::basic_string_view< CharT, Traits >::rend ( )
inlinenoexcept

Returns a reverse iterator first element of the view. When accessing the iterator, the iterator will always return the element T[internal index - 1], providing access to the range [size() - 1, 0) while internally storing the range [size(), 1) with element 0 representing the end(). For more information, see the bsl::reverse_iterator documentation.

#include <bsl/for_each.hpp>
#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_basic_string_view_rend() noexcept
{
bsl::for_each(str.rbegin(), str.rend(), [](auto &e, auto const i) noexcept {
bsl::print() << "element [" << i << "] == " << e << bsl::endl;
});
}
}
Returns
Returns a reverse iterator first element of the view.

◆ rend() [2/2]

template<typename CharT, typename Traits = char_traits<CharT>>
constexpr const_reverse_iterator_type bsl::basic_string_view< CharT, Traits >::rend ( ) const
inlinenoexcept

Returns a reverse iterator first element of the view. When accessing the iterator, the iterator will always return the element T[internal index - 1], providing access to the range [size() - 1, 0) while internally storing the range [size(), 1) with element 0 representing the end(). For more information, see the bsl::reverse_iterator documentation.

#include <bsl/for_each.hpp>
#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_basic_string_view_rend() noexcept
{
bsl::for_each(str.rbegin(), str.rend(), [](auto &e, auto const i) noexcept {
bsl::print() << "element [" << i << "] == " << e << bsl::endl;
});
}
}
Returns
Returns a reverse iterator first element of the view.

◆ crend()

template<typename CharT, typename Traits = char_traits<CharT>>
constexpr const_reverse_iterator_type bsl::basic_string_view< CharT, Traits >::crend ( ) const
inlinenoexcept

Returns a reverse iterator first element of the view. When accessing the iterator, the iterator will always return the element T[internal index - 1], providing access to the range [size() - 1, 0) while internally storing the range [size(), 1) with element 0 representing the end(). For more information, see the bsl::reverse_iterator documentation.

#include <bsl/for_each.hpp>
#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_basic_string_view_rend() noexcept
{
bsl::for_each(str.rbegin(), str.rend(), [](auto &e, auto const i) noexcept {
bsl::print() << "element [" << i << "] == " << e << bsl::endl;
});
}
}
Returns
Returns a reverse iterator first element of the view.

◆ empty()

template<typename CharT, typename Traits = char_traits<CharT>>
constexpr bool bsl::basic_string_view< CharT, Traits >::empty ( ) const
inlinenoexcept

Returns size() == 0.

#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_basic_string_view_empty() noexcept
{
if (!str.empty()) {
bsl::print() << "success\n";
}
}
}
Returns
Returns size() == 0

◆ size()

template<typename CharT, typename Traits = char_traits<CharT>>
constexpr size_type bsl::basic_string_view< CharT, Traits >::size ( ) const
inlinenoexcept

Returns the number of elements in the string being viewed. If this is a default constructed view, or the view was constructed in error, this will return 0.

#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_basic_string_view_size() noexcept
{
bsl::print() << "size: " << str.size() << bsl::endl;
}
}
Returns
Returns the number of elements in the string being viewed. If this is a default constructed view, or the view was constructed in error, this will return 0.

◆ length()

template<typename CharT, typename Traits = char_traits<CharT>>
constexpr size_type bsl::basic_string_view< CharT, Traits >::length ( ) const
inlinenoexcept

Returns the length of the string being viewed. This is the same as bsl::basic_string_view::size(). Note that the length refers to the total number of characters in the string and not the number of bytes in the string. For the total number of bytes, use bsl::basic_string_view::size_bytes().

#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_basic_string_view_length() noexcept
{
constexpr bsl::uintmax expected{5U};
if (str.length() == expected) {
bsl::print() << "success\n";
}
}
}
Returns
Returns the length of the string being viewed.

◆ max_size()

template<typename CharT, typename Traits = char_traits<CharT>>
static constexpr size_type bsl::basic_string_view< CharT, Traits >::max_size ( )
inlinestaticnoexcept

Returns the max number of elements the BSL supports.

#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_basic_string_view_max_size() noexcept
{
bsl::print() << "max size: " << str.max_size() << bsl::endl;
}
}
Returns
Returns the max number of elements the BSL supports.

◆ size_bytes()

template<typename CharT, typename Traits = char_traits<CharT>>
constexpr size_type bsl::basic_string_view< CharT, Traits >::size_bytes ( ) const
inlinenoexcept

Returns size() * sizeof(T)

#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_basic_string_view_size_bytes() noexcept
{
bsl::print() << "size in bytes: " << str.size_bytes() << bsl::endl;
}
}
Returns
Returns size() * sizeof(T)

◆ remove_prefix()

template<typename CharT, typename Traits = char_traits<CharT>>
constexpr basic_string_view& bsl::basic_string_view< CharT, Traits >::remove_prefix ( size_type const  n)
inlinenoexcept

Moves the start of the view forward by n characters. If n >= size(), the bsl::basic_string_view is reset to a NULL string, with data() returning a nullptr, and size() returning 0.

#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_basic_string_view_remove_prefix() noexcept
{
constexpr bsl::uintmax num{6U};
if (str.remove_prefix(num) == "World") {
bsl::print() << "success\n";
}
}
}
Parameters
nthe number of character to remove from the start of the string.
Returns
returns *this

◆ remove_suffix()

template<typename CharT, typename Traits = char_traits<CharT>>
constexpr basic_string_view& bsl::basic_string_view< CharT, Traits >::remove_suffix ( size_type const  n)
inlinenoexcept

Moves the end of the view back by n characters. If n >= size(), the bsl::basic_string_view is reset to a NULL string, with data() returning a nullptr, and size() returning 0.

#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_basic_string_view_remove_suffix() noexcept
{
constexpr bsl::uintmax num{6U};
if (str.remove_suffix(num) == "Hello") {
bsl::print() << "success\n";
}
}
}
Parameters
nthe number of character to remove from the end of the string.
Returns
returns *this

◆ substr()

template<typename CharT, typename Traits = char_traits<CharT>>
constexpr basic_string_view bsl::basic_string_view< CharT, Traits >::substr ( size_type const  pos = 0U,
size_type const  count = npos 
) const
inlinenoexcept

Returns a new bsl::basic_string_view that is a substring view of the original. The substring starts at "pos" and ends at "pos" + "count". Note that this does not copy the string, it simply changes the internal pointer and size of the same string that is currently being viewed (meaning the lifetime of the new substring cannot outlive the lifetime of the string being viewed by the original bsl::basic_string_view). If the provided "pos" or "count" are invalid, this function returns an empty string view.

#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_basic_string_view_substr() noexcept
{
constexpr bsl::uintmax pos{0U};
constexpr bsl::uintmax count{5U};
constexpr bsl::basic_string_view<bsl::char_type> str{"Hello World"};
if (str.substr(pos, count) == "Hello") {
bsl::print() << "success\n";
}
}
}
Parameters
posthe starting position of the new substring.
countthe length of the new bsl::basic_string_view
Returns
Returns a new bsl::basic_string_view that is a substring view of the original. The substring starts at "pos" and ends at "pos" + "count".

◆ compare() [1/6]

template<typename CharT, typename Traits = char_traits<CharT>>
constexpr bsl::int32 bsl::basic_string_view< CharT, Traits >::compare ( basic_string_view< CharT, Traits > const &  str) const
inlinenoexcept

Compares two strings.

#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_basic_string_view_compare() noexcept
{
constexpr bsl::basic_string_view<bsl::char_type> str1{"Hello"};
constexpr bsl::basic_string_view<bsl::char_type> str2{"Hello"};
if (str1.compare(str2) == 0) {
bsl::print() << "success\n";
}
}
}
Parameters
strthe bsl::basic_string_view to compare with
Returns
Returns the same results as std::strncmp

◆ compare() [2/6]

template<typename CharT, typename Traits = char_traits<CharT>>
constexpr bsl::int32 bsl::basic_string_view< CharT, Traits >::compare ( size_type const  pos,
size_type const  count,
basic_string_view< CharT, Traits > const &  str 
) const
inlinenoexcept

Same as substr(pos, count).compare(v)

#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_basic_string_view_compare() noexcept
{
constexpr bsl::basic_string_view<bsl::char_type> str1{"Hello"};
constexpr bsl::basic_string_view<bsl::char_type> str2{"Hello"};
if (str1.compare(str2) == 0) {
bsl::print() << "success\n";
}
}
}
Parameters
posthe starting position of "this" to compare from
countthe number of characters of "this" to compare
strthe bsl::basic_string_view to compare with
Returns
Returns the same results as std::strncmp

◆ compare() [3/6]

template<typename CharT, typename Traits = char_traits<CharT>>
constexpr bsl::int32 bsl::basic_string_view< CharT, Traits >::compare ( size_type  pos1,
size_type  count1,
basic_string_view< CharT, Traits > const &  str,
size_type  pos2,
size_type  count2 
) const
inlinenoexcept

Same as substr(pos1, count1).compare(v.substr(pos2, count2))

#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_basic_string_view_compare() noexcept
{
constexpr bsl::basic_string_view<bsl::char_type> str1{"Hello"};
constexpr bsl::basic_string_view<bsl::char_type> str2{"Hello"};
if (str1.compare(str2) == 0) {
bsl::print() << "success\n";
}
}
}
Parameters
pos1the starting position of "this" to compare from
count1the number of characters of "this" to compare
strthe bsl::basic_string_view to compare with
pos2the starting position of "v" to compare from
count2the number of characters of "v" to compare
Returns
Returns the same results as std::strncmp

◆ compare() [4/6]

template<typename CharT, typename Traits = char_traits<CharT>>
constexpr bsl::int32 bsl::basic_string_view< CharT, Traits >::compare ( pointer_type const  str) const
inlinenoexcept

Same as compare(basic_string_view{s})

#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_basic_string_view_compare() noexcept
{
constexpr bsl::basic_string_view<bsl::char_type> str1{"Hello"};
constexpr bsl::basic_string_view<bsl::char_type> str2{"Hello"};
if (str1.compare(str2) == 0) {
bsl::print() << "success\n";
}
}
}
Parameters
stra pointer to a string to compare with "this"
Returns
Returns the same results as std::strncmp

◆ compare() [5/6]

template<typename CharT, typename Traits = char_traits<CharT>>
constexpr bsl::int32 bsl::basic_string_view< CharT, Traits >::compare ( size_type  pos,
size_type  count,
pointer_type const  str 
) const
inlinenoexcept

Same as substr(pos, count).compare(basic_string_view{s})

#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_basic_string_view_compare() noexcept
{
constexpr bsl::basic_string_view<bsl::char_type> str1{"Hello"};
constexpr bsl::basic_string_view<bsl::char_type> str2{"Hello"};
if (str1.compare(str2) == 0) {
bsl::print() << "success\n";
}
}
}
Parameters
posthe starting position of "this" to compare from
countthe number of characters of "this" to compare
stra pointer to a string to compare with "this"
Returns
Returns the same results as std::strncmp

◆ compare() [6/6]

template<typename CharT, typename Traits = char_traits<CharT>>
constexpr bsl::int32 bsl::basic_string_view< CharT, Traits >::compare ( size_type  pos,
size_type  count1,
pointer_type const  str,
size_type  count2 
) const
inlinenoexcept

Same as substr(pos, count1).compare(basic_string_view{s, count2})

#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_basic_string_view_compare() noexcept
{
constexpr bsl::basic_string_view<bsl::char_type> str1{"Hello"};
constexpr bsl::basic_string_view<bsl::char_type> str2{"Hello"};
if (str1.compare(str2) == 0) {
bsl::print() << "success\n";
}
}
}
Note
Unlike the standard library version of this function, the BSL implements this function as the following to prevent potential corruption: compare(pos, count1, basic_string_view{s}, 0, count2)
Parameters
posthe starting position of "this" to compare from
count1the number of characters of "this" to compare
stra pointer to a string to compare with "this"
count2the number of characters of "s" to compare
Returns
Returns the same results as std::strncmp

◆ starts_with() [1/3]

template<typename CharT, typename Traits = char_traits<CharT>>
constexpr bool bsl::basic_string_view< CharT, Traits >::starts_with ( basic_string_view< CharT, Traits > const &  str) const
inlinenoexcept

Checks if the string begins with the given prefix.

#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_basic_string_view_starts_with() noexcept
{
constexpr bsl::basic_string_view<bsl::char_type> str{"Hello World"};
if (str.starts_with("Hello")) {
bsl::print() << "success\n";
}
}
}
Parameters
strthe bsl::basic_string_view to compare with
Returns
Returns true if the string begins with the given prefix, false otherwise.

◆ starts_with() [2/3]

template<typename CharT, typename Traits = char_traits<CharT>>
constexpr bool bsl::basic_string_view< CharT, Traits >::starts_with ( value_type const  c) const
inlinenoexcept

Checks if the string begins with the given prefix.

#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_basic_string_view_starts_with() noexcept
{
constexpr bsl::basic_string_view<bsl::char_type> str{"Hello World"};
if (str.starts_with("Hello")) {
bsl::print() << "success\n";
}
}
}
Parameters
cthe value_type to compare with
Returns
Returns true if the string begins with the given prefix, false otherwise.

◆ starts_with() [3/3]

template<typename CharT, typename Traits = char_traits<CharT>>
constexpr bool bsl::basic_string_view< CharT, Traits >::starts_with ( pointer_type const  str) const
inlinenoexcept

Checks if the string begins with the given prefix.

#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_basic_string_view_starts_with() noexcept
{
constexpr bsl::basic_string_view<bsl::char_type> str{"Hello World"};
if (str.starts_with("Hello")) {
bsl::print() << "success\n";
}
}
}
Parameters
strthe string to compare with
Returns
Returns true if the string begins with the given prefix, false otherwise.

◆ ends_with() [1/3]

template<typename CharT, typename Traits = char_traits<CharT>>
constexpr bool bsl::basic_string_view< CharT, Traits >::ends_with ( basic_string_view< CharT, Traits > const &  str) const
inlinenoexcept

Checks if the string ends with the given suffix.

#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_basic_string_view_ends_with() noexcept
{
constexpr bsl::basic_string_view<bsl::char_type> str{"Hello World"};
if (str.ends_with("World")) {
bsl::print() << "success\n";
}
}
}
Parameters
strthe bsl::basic_string_view to compare with
Returns
Returns true if the string ends with the given suffix, false otherwise.

◆ ends_with() [2/3]

template<typename CharT, typename Traits = char_traits<CharT>>
constexpr bool bsl::basic_string_view< CharT, Traits >::ends_with ( value_type const  c) const
inlinenoexcept

Checks if the string ends with the given suffix.

#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_basic_string_view_ends_with() noexcept
{
constexpr bsl::basic_string_view<bsl::char_type> str{"Hello World"};
if (str.ends_with("World")) {
bsl::print() << "success\n";
}
}
}
Parameters
cthe value_type to compare with
Returns
Returns true if the string ends with the given suffix, false otherwise.

◆ ends_with() [3/3]

template<typename CharT, typename Traits = char_traits<CharT>>
constexpr bool bsl::basic_string_view< CharT, Traits >::ends_with ( pointer_type const  str) const
inlinenoexcept

Checks if the string ends with the given suffix.

#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_basic_string_view_ends_with() noexcept
{
constexpr bsl::basic_string_view<bsl::char_type> str{"Hello World"};
if (str.ends_with("World")) {
bsl::print() << "success\n";
}
}
}
Parameters
strthe string to compare with
Returns
Returns true if the string ends with the given suffix, false otherwise.

Friends And Related Function Documentation

◆ string_view

template<typename CharT, typename Traits = char_traits<CharT>>
using string_view = basic_string_view<char_type>
related

provides the default string_view prototype

◆ operator==() [1/3]

template<typename CharT , typename Traits >
constexpr bool operator== ( bsl::basic_string_view< CharT, Traits > const &  lhs,
bsl::basic_string_view< CharT, Traits > const &  rhs 
)
related

Returns true if two strings have the same length (which is different from compare() which uses the minimum size between the two provided strings), and contain the same characters. Returns false otherwise.

#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_basic_string_view_equals() noexcept
{
constexpr bsl::basic_string_view<bsl::char_type> str1{"Hello"};
constexpr bsl::basic_string_view<bsl::char_type> str2{"Hello"};
if (str1 == str2) {
bsl::print() << "success\n";
}
}
}
Template Parameters
CharTthe type of characters in the string
Traitsthe traits class used to work with the string
Parameters
lhsthe left hand side of the operation
rhsthe right hand side of the operation
Returns
Returns true if two strings have the same length (which is different from compare() which uses the minimum size between the two provided strings), and contain the same characters. Returns false otherwise.

◆ operator==() [2/3]

template<typename CharT , typename Traits >
constexpr bool operator== ( bsl::basic_string_view< CharT, Traits > const &  lhs,
CharT const *const  rhs 
)
related

Returns true if two strings have the same length (which is different from compare() which uses the minimum size between the two provided strings), and contain the same characters. Returns false otherwise.

#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_basic_string_view_equals() noexcept
{
constexpr bsl::basic_string_view<bsl::char_type> str1{"Hello"};
constexpr bsl::basic_string_view<bsl::char_type> str2{"Hello"};
if (str1 == str2) {
bsl::print() << "success\n";
}
}
}
Template Parameters
CharTthe type of characters in the string
Traitsthe traits class used to work with the string
Parameters
lhsthe left hand side of the operation
rhsthe right hand side of the operation
Returns
Returns true if two strings have the same length (which is different from compare() which uses the minimum size between the two provided strings), and contain the same characters. Returns false otherwise.

◆ operator==() [3/3]

template<typename CharT , typename Traits >
constexpr bool operator== ( CharT const *const  lhs,
bsl::basic_string_view< CharT, Traits > const &  rhs 
)
related

Returns true if two strings have the same length (which is different from compare() which uses the minimum size between the two provided strings), and contain the same characters. Returns false otherwise.

#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_basic_string_view_equals() noexcept
{
constexpr bsl::basic_string_view<bsl::char_type> str1{"Hello"};
constexpr bsl::basic_string_view<bsl::char_type> str2{"Hello"};
if (str1 == str2) {
bsl::print() << "success\n";
}
}
}
Template Parameters
CharTthe type of characters in the string
Traitsthe traits class used to work with the string
Parameters
lhsthe left hand side of the operation
rhsthe right hand side of the operation
Returns
Returns true if two strings have the same length (which is different from compare() which uses the minimum size between the two provided strings), and contain the same characters. Returns false otherwise.

◆ operator!=() [1/3]

template<typename CharT , typename Traits >
constexpr bool operator!= ( bsl::basic_string_view< CharT, Traits > const &  lhs,
bsl::basic_string_view< CharT, Traits > const &  rhs 
)
related

Returns true if two strings are not the same length (which is different from compare() which uses the minimum size between the two provided strings), or contain different characters. Returns false otherwise.

#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_basic_string_view_not_equals() noexcept
{
constexpr bsl::basic_string_view<bsl::char_type> str1{"Hello"};
constexpr bsl::basic_string_view<bsl::char_type> str2{"World"};
if (str1 != str2) {
bsl::print() << "success\n";
}
}
}
Template Parameters
CharTthe type of characters in the string
Traitsthe traits class used to work with the string
Parameters
lhsthe left hand side of the operation
rhsthe right hand side of the operation
Returns
Returns true if two strings are not the same length (which is different from compare() which uses the minimum size between the two provided strings), or contain different characters. Returns false otherwise.

◆ operator!=() [2/3]

template<typename CharT , typename Traits >
constexpr bool operator!= ( bsl::basic_string_view< CharT, Traits > const &  lhs,
CharT const *const  rhs 
)
related

Returns true if two strings are not the same length (which is different from compare() which uses the minimum size between the two provided strings), or contain different characters. Returns false otherwise.

#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_basic_string_view_not_equals() noexcept
{
constexpr bsl::basic_string_view<bsl::char_type> str1{"Hello"};
constexpr bsl::basic_string_view<bsl::char_type> str2{"World"};
if (str1 != str2) {
bsl::print() << "success\n";
}
}
}
Template Parameters
CharTthe type of characters in the string
Traitsthe traits class used to work with the string
Parameters
lhsthe left hand side of the operation
rhsthe right hand side of the operation
Returns
Returns true if two strings are not the same length (which is different from compare() which uses the minimum size between the two provided strings), or contain different characters. Returns false otherwise.

◆ operator!=() [3/3]

template<typename CharT , typename Traits >
constexpr bool operator!= ( CharT const *const  lhs,
bsl::basic_string_view< CharT, Traits > const &  rhs 
)
related

Returns true if two strings are not the same length (which is different from compare() which uses the minimum size between the two provided strings), or contain different characters. Returns false otherwise.

#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_basic_string_view_not_equals() noexcept
{
constexpr bsl::basic_string_view<bsl::char_type> str1{"Hello"};
constexpr bsl::basic_string_view<bsl::char_type> str2{"World"};
if (str1 != str2) {
bsl::print() << "success\n";
}
}
}
Template Parameters
CharTthe type of characters in the string
Traitsthe traits class used to work with the string
Parameters
lhsthe left hand side of the operation
rhsthe right hand side of the operation
Returns
Returns true if two strings are not the same length (which is different from compare() which uses the minimum size between the two provided strings), or contain different characters. Returns false otherwise.

◆ fmt_impl()

template<typename OUT , typename CharT >
constexpr void fmt_impl ( OUT &&  o,
fmt_options const &  ops,
basic_string_view< CharT > const &  str 
)
related

This function is responsible for implementing bsl::fmt for string_view types. For strings, the only fmt options that are available are alignment, fill and width, all of which are handled by the fmt_impl_align_xxx functions.

Template Parameters
OUTthe type of out (i.e., debug, alert, etc)
Parameters
othe instance of out<T> to output to
opsops the fmt options used to format the output
strthe string_view being outputted

◆ operator<<()

template<typename T , typename CharT >
constexpr out< T > operator<< ( out< T > const  o,
basic_string_view< CharT > const &  str 
)
related

Outputs the provided string_view to the provided output type.

Template Parameters
Tthe type of outputter provided
Parameters
othe instance of the outputter used to output the value.
strthe string_view to output
Returns
return o

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