STD::BASIC_STRING_VIEW(3)

πŸ’– NAME πŸ’–

std::basic_string_view< _CharT, _Traits > β€” a non-owning reference to a string. πŸ‘‘

okay so bestie, real talk: this thing looks at a string, it does not own a string. That's the whole vibe. It's the friend who's like "yeah I know a guy" and points at the string from across the room. No ownership, no drama, no destructor meltdown. πŸ’…

We're in the Library Functions Manual, section 3, and this page is literally titled std::basic..., _Traits >(3) because the header got cut off and honestly it ate anyway. πŸŽ€


πŸ¦‹ SYNOPSIS πŸ¦‹

#include <>>

✨ Public Types ✨

using const_iterator
using const_pointer
using const_reference
using const_reverse_iterator
using difference_type
using iterator
using pointer
using reference
using reverse_iterator
using size_type
using traits_type
using value_type

✨ Public Member Functions ✨

template<contiguous_iterator _It, sized_sentinel_for< _It > _End>
    constexpr basic_string_view (_It __first, _End __last)
    noexcept(noexcept(__last - __first))
template<typename _Range, typename _DRange = remove_cvref_t<_Range>>
    constexpr basic_string_view (_Range &&__r)
    noexcept(noexcept(ranges::size(__r)) &&noexcept(ranges::data(__r)))
constexpr basic_string_view (const _CharT *__str) noexcept
constexpr basic_string_view (const _CharT *__str, size_type __len)
    noexcept
constexpr basic_string_view (const basic_string_view &) noexcept=default
basic_string_view (nullptr_t)=delete
constexpr const_reference at (size_type __pos) const
constexpr const_reference back () const noexcept
constexpr const_iterator begin () const noexcept
constexpr const_iterator cbegin () const noexcept
constexpr const_iterator cend () const noexcept
constexpr int compare (basic_string_view __str) const noexcept
constexpr int compare (const _CharT *__str) const noexcept
constexpr int compare (size_type __pos1, size_type __n1,
    basic_string_view __str) const
constexpr int compare (size_type __pos1, size_type __n1,
    basic_string_view __str, size_type __pos2, size_type __n2) const
constexpr int compare (size_type __pos1, size_type __n1, const _CharT
    *__str) const
constexpr int compare (size_type __pos1, size_type __n1, const _CharT
    *__str, size_type __n2) const noexcept(false)
constexpr bool contains (_CharT __x) const noexcept
constexpr bool contains (basic_string_view __x) const noexcept
constexpr bool contains (const _CharT *__x) const noexcept
constexpr size_type copy (_CharT *__str, size_type __n, size_type
    __pos=0) const
constexpr const_reverse_iterator crbegin () const noexcept
constexpr const_reverse_iterator crend () const noexcept
constexpr const_pointer data () const noexcept
constexpr bool empty () const noexcept
constexpr const_iterator end () const noexcept
constexpr size_type find (_CharT __c, size_type __pos=0) const noexcept
constexpr size_type find (basic_string_view __str, size_type __pos=0)
    const noexcept
constexpr size_type find (const _CharT *__str, size_type __pos,
    size_type __n) const noexcept
constexpr size_type find (const _CharT *__str, size_type __pos=0) const
    noexcept
constexpr size_type find_first_not_of (_CharT __c, size_type __pos=0)
    const noexcept
constexpr size_type find_first_not_of (basic_string_view __str,
    size_type __pos=0) const noexcept
constexpr size_type find_first_not_of (const _CharT *__str, size_type
    __pos, size_type __n) const noexcept
constexpr size_type find_first_not_of (const _CharT *__str, size_type
    __pos=0) const noexcept
constexpr size_type find_first_of (_CharT __c, size_type __pos=0) const
    noexcept
constexpr size_type find_first_of (basic_string_view __str, size_type
    __pos=0) const noexcept
constexpr size_type find_first_of (const _CharT *__str, size_type __pos,
    size_type __n) const noexcept
constexpr size_type find_first_of (const _CharT *__str, size_type
    __pos=0) const noexcept
constexpr size_type find_last_not_of (_CharT __c, size_type __pos=npos)
    const noexcept
constexpr size_type find_last_not_of (basic_string_view __str, size_type
    __pos=npos) const noexcept
constexpr size_type find_last_not_of (const _CharT *__str, size_type
    __pos, size_type __n) const noexcept
constexpr size_type find_last_not_of (const _CharT *__str, size_type
    __pos=npos) const noexcept
constexpr size_type find_last_of (_CharT __c, size_type __pos=npos)
    const noexcept
constexpr size_type find_last_of (basic_string_view __str, size_type
    __pos=npos) const noexcept
constexpr size_type find_last_of (const _CharT *__str, size_type __pos,
    size_type __n) const noexcept
constexpr size_type find_last_of (const _CharT *__str, size_type
    __pos=npos) const noexcept
constexpr const_reference front () const noexcept
constexpr size_type length () const noexcept
constexpr size_type max_size () const noexcept
constexpr basic_string_view & operator= (const basic_string_view &)
    noexcept=default
constexpr const_reference operator[] (size_type __pos) const noexcept
constexpr const_reverse_iterator rbegin () const noexcept
constexpr void remove_prefix (size_type __n) noexcept
constexpr void remove_suffix (size_type __n) noexcept
constexpr const_reverse_iterator rend () const noexcept
constexpr size_type rfind (_CharT __c, size_type __pos=npos) const
    noexcept
constexpr size_type rfind (basic_string_view __str, size_type
    __pos=npos) const noexcept
constexpr size_type rfind (const _CharT *__str, size_type __pos,
    size_type __n) const noexcept
constexpr size_type rfind (const _CharT *__str, size_type __pos=npos)
    const noexcept
constexpr size_type size () const noexcept
constexpr basic_string_view substr (size_type __pos=0, size_type
    __n=npos) const noexcept(false)
constexpr basic_string_view subview (size_type __pos=0, size_type
    __n=npos) const
constexpr void swap (basic_string_view &__sv) noexcept
not me reading this list and needing a lil lie-down 😭 it's a LOT of overloads but every single one of them is iconic in its own right, fr fr.

So yeah, that's the whole squad: a crew of constructors (and one very deliberately deleted one that takes nullptr_t β€” do not try it, it's been cancelled πŸ’€), the iterator besties (begin, end, cbegin, cend, rbegin, rend, crbegin, crend), the compare family, the contains trio, copy, data, empty, size, length, max_size, front, back, at, operator[], operator=, remove_prefix, remove_suffix, swap, substr, subview, and the entire search squad: find, rfind, find_first_of, find_last_of, find_first_not_of, find_last_not_of, each with their multiple overloads. 🫢

Note the defaults, bestie β€” lots of these take size_type __pos=0, the find_last_* and rfind crew default to size_type __pos=npos, and substr/subview default to size_type __pos=0, size_type __n=npos. Also clock the noexcept sprinkled everywhere like glitter ✨, and the spicy noexcept(false) on compare and substr β€” those two are allowed to throw, so don't @ me when they do. 🚨

✨ Static Public Attributes ✨

static constexpr size_type npos

🧚 DETAILED DESCRIPTION 🧚

template<typename _CharT, typename _Traits = std::char_traits<_CharT>>
    class std::basic_string_view< _CharT, _Traits >

"A non-owning reference to a string."

🌸 Template Parameters 🌸

  • _CharT β€” Type of character πŸ’œ
  • _Traits β€” Traits for character type, defaults to char_traits<_CharT>.

And here's the tea, the whole entire layout, it literally looks like this:

_CharT*    _M_str
size_t     _M_len

a pointer and a length. That's it. That's the whole class. It's giving minimalism, it's giving "I don't need to allocate to be the main character", it's giving lowkey the most efficient thing in the standard library. πŸ¦‹βœ¨


🌈 AUTHOR 🌈

Generated automatically by Doxygen for libstdc++ from the source code.


and that's the page, bestie!! πŸ’– this was std::basic..., _Traits >(3) from the libstdc++ crew, served up fresh out of the Library Functions Manual. go forth, view those strings, own absolutely none of them. periodt. πŸ‘‘πŸŒΈπŸ’…

πŸ“¦ where this page comes from
  • arch rolling: gcc 16.2.1+r23+gd564253eb6c8-1 Β· GPL-3.0-or-later WITH GCC-exception-3.1 AND GFDL-1.3-or-later
  • fedora 44: libstdc++-docs 16.2.1-2.fc44
  • fedora 44: libstdc++-docs 16.2.1-3.fc44 Β· GPL-3.0-or-later AND LGPL-3.0-or-later AND (GPL-3.0-or-later WITH GCC-exception-3.1) AND (GPL-3.0-or-later WITH Texinfo-exception) AND (LGPL-2.1-or-later WITH GCC-exception-2.0) AND (GPL-2.0-or-later WITH GCC-exception-2.0) AND (GPL-2.0-or-later WITH GNU-compiler-exception) AND BSL-1.0 AND GFDL-1.3-or-later AND Linux-man-pages-copyleft-2-para AND SunPro AND BSD-1-Clause AND BSD-2-Clause AND BSD-2-Clause-Views AND BSD-3-Clause AND BSD-4-Clause AND BSD-Source-Code AND Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 WITH LLVM-Exception) AND ZPL-2.1 AND ISC AND LicenseRef-Fedora-Public-Domain AND HP-1986 AND curl AND Martin-Birgmeier AND HPND-Markus-Kuhn AND dtoa AND SMLNJ AND AMD-newlib AND OAR AND HPND-merchantability-variant AND HPND-Intel
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms