stim::string_view class

A non-owning view of a UTF-8 string.

Base classes

template<typename T, size_t Extent = -1>
class span<const char>
A non-owning view of contiguous elements.

Public types

using const_pointer = const const char*
Const-qualified pointer to a single element in the span.
using const_reference = const const char&
Const-qualified reference to a single element in the span.
using difference_type = ptrdiff_t
The difference between two pointers.
using element_type = const char
The span's element type.
using iterator = pointer
The iterator type returned by begin() and end().
using pointer = const char*
Pointer to a single element in the span.
using reference = const char&
Reference to a single element in the span.
using size_type = size_t
The unsigned integer type used for sizes, indices, et cetera.
using value_type = api_detail::remove_cv<const char>
The span's element type without any cv-qualifiers.

Public static variables

static size_type extent constexpr
The maximal number of elements that can be represented by the span (-1 == dynamic).
static size_type stride constexpr
The size of a single element, in bytes.

Constructors, destructors, conversion operators

operator bool() const explicit constexpr noexcept
Returns true if the span's extent is greater than zero and the data pointer is not null.
operator span<const const char, -1>() const constexpr noexcept
Casts the span to the const equivalent.
string_view() defaulted constexpr noexcept
Default constructor.
string_view(const string_view&) defaulted constexpr noexcept
Copy constructor.
string_view(const char* str, size_t len) constexpr noexcept
Pointer + length constructor.
string_view(const char* str) constexpr noexcept
Pointer-to-string constructor.

Public functions

auto back() const -> reference constexpr noexcept
Returns a reference to the last element in the span.
auto begin() const -> iterator constexpr noexcept
Returns an iterator to the first element represented by the span.
auto data() const -> pointer constexpr noexcept
Returns a pointer to the first element represented by the span.
auto empty() const -> bool constexpr noexcept
Returns true if the span's extent is greater than zero.
auto end() const -> iterator constexpr noexcept
Returns an iterator to one-past-the-last element represented by the span.
auto front() const -> reference constexpr noexcept
Returns a reference to the first element in the span.
auto length() const -> size_type constexpr noexcept
Returns the number of elements represented by the span.
auto operator=(const string_view&) -> string_view& defaulted noexcept
Copy-assignment constructor.
auto operator[](size_type idx) const -> reference constexpr noexcept
Returns a reference to an element in the span.
auto size() const -> size_type constexpr noexcept
Returns the number of elements represented by the span.
auto size_bytes() const -> size_type constexpr noexcept
Returns the size of the memory region represented by the span, in bytes.

Compatibility with UE4

operator::FString() const
Converts a string view into a UE4 FString.

Compatibility with std::ostream

template<typename Traits>
auto operator<<(std::basic_ostream<char, Traits>& lhs, const string_view& rhs) -> std::basic_ostream<char, Traits>&
Writes the string view out to an ostream.

Compatibility with std::string

operator std::string() const
Converts a string view into a std::string.
string_view(const std::string& str) noexcept
Constructs a string view from a std::string.
auto operator!=(const string_view& lhs, const std::string& rhs) -> bool noexcept
Inequality operator.
auto operator!=(const std::string& lhs, const string_view& rhs) -> bool noexcept
Inequality operator.
auto operator==(const string_view& lhs, const std::string& rhs) -> bool noexcept
Equality operator.
auto operator==(const std::string& lhs, const string_view& rhs) -> bool noexcept
Equality operator.

Compatibility with std::string_view

operator std::string_view() const constexpr noexcept
Converts a string view into a std::string_view.
string_view(std::string_view str) constexpr noexcept
Constructs a string view from a std::string_view.
auto operator!=(const string_view& lhs, const std::string_view& rhs) -> bool constexpr noexcept
Inequality operator.
auto operator!=(const std::string_view& lhs, const string_view& rhs) -> bool constexpr noexcept
Inequality operator.
auto operator==(const string_view& lhs, const std::string_view& rhs) -> bool constexpr noexcept
Equality operator.
auto operator==(const std::string_view& lhs, const string_view& rhs) -> bool constexpr noexcept
Equality operator.

Friends

auto operator!=(const string_view& lhs, const string_view& rhs) -> bool noexcept
Inequality operator.
auto operator==(const string_view& lhs, const string_view& rhs) -> bool noexcept
Equality operator.

Function documentation

string_view operator""_sv(const char* str, size_t len) constexpr noexcept

Creates a string_view.

using namespace stim::literals;

constexpr stim::string_view str = "Klaatu barada nikto!"_sv;