folly::basic_cstring_view

cstring_view

Synopsis

Declared in <folly/lang/cstring_view.h>

template<
    typename Char,
    typename Traits = std::char_traits<Char>>
class basic_cstring_view;

Description

A string view type that privately inherits from std::string_view but guarantees that the underlying buffer is null-terminated. This allows safe use of .c_str() while maintaining all the benefits of string_view.

The type provides adjusted constructors and assignment operators to ensure the null-termination guarantee is maintained.

mimic: std::cstring_view, p3655r3

https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2025/p3655r3.html

Type Aliases

NameDescription
const_iterator Constant iterator type over the characters.
const_pointer Pointer to constant character type.
const_reference Reference to constant character type.
const_reverse_iterator Constant reverse iterator type over the characters.
difference_type Signed integer type used for iterator differences.
iterator Iterator type over the characters.
pointer Pointer to character type.
reference Reference to character type.
reverse_iterator Reverse iterator type over the characters.
size_type Unsigned integer type used for sizes and positions.
traits_type Character traits type.
value_type Character value type.

Member Functions

NameDescription
basic_cstring_view [constructor]Constructors
operator= Assignment operators
at Returns a reference to the character at the given position, bounds-checked.
back Returns a reference to the last character.
begin Returns an iterator to the first character.
c_str Returns a pointer to the null-terminated character buffer.
cbegin Returns a constant iterator to the first character.
cend Returns a constant iterator past the last character.
compare compare overloads
contains contains overloads
crbegin Returns a constant reverse iterator to the last character.
crend Returns a constant reverse iterator before the first character.
data Returns a pointer to the underlying null-terminated character buffer.
empty Checks whether the view is empty.
end Returns an iterator past the last character.
ends_with ends_with overloads
find find overloads
find_first_not_of find_first_not_of overloads
find_first_of find_first_of overloads
find_last_not_of find_last_not_of overloads
find_last_of find_last_of overloads
front Returns a reference to the first character.
length Returns the number of characters in the view.
max_size Returns the maximum number of characters the view can reference.
operator[] Returns a reference to the character at the given position.
rbegin Returns a reverse iterator to the last character.
remove_prefix Removes the first n characters from the view.
remove_suffix [deleted]Removing a suffix is deleted because it would break null-termination.
rend Returns a reverse iterator before the first character.
rfind rfind overloads
size Returns the number of characters in the view.
starts_with starts_with overloads
substr substr overloads
swap Swaps the contents of this view with another view.
operator view_type Converts implicitly to the underlying string_view.

Static Data Members

NameDescription
npos Special position value indicating "not found" or "until the end".

Friends

NameDescription
folly::operator>=Orders two views lexicographically.
folly::operator>Orders two views lexicographically.
folly::operator<=Orders two views lexicographically.
folly::operator<Orders two views lexicographically.
folly::operator!=Checks two views for inequality.
folly::operator==Checks two views for equality.