std::basic_..._view::front(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

πŸ’– NAME πŸ’–

okay so this is the page for std::basic_string_view::front β€” literally the front-character accessor, bestie. it lives in the C++ Standard Libary manual (yes, that’s the spelling on the page, not me lol) and the page is std::basic_..._view::front(3). this is the function you call when you want the first character of a string view, and it’s giving main character energy. πŸ’…


πŸ”₯ Synopsis πŸ”₯

constexpr const_reference front() const;  (since C++17)

Returns reference to the first character in the view. The behavior is undefined if empty() == true.

bestie, if empty() == true, it is undefined behavior β€” like, do not pass go, do not collect $200. that’s a hard no. πŸ’€

πŸŽ€ Parameters πŸŽ€

(none) β€” she takes zero arguments, periodt. no params, no stress. ✨


⚑ Return value ⚑

Reference to the first character, equivalent to operator[](0). literally the same character, bestie. 🫢


πŸ’« Complexity πŸ’«

Constant. like, one and done, no cap. ⭐


🌈 Example 🌈

// Run this code β€” go off, bestie:

        #include <iostream>
        #include <string_view>

        int main()
        {
            for (std::string_view str{"ABCDEF"}; !str.empty();
       str.remove_prefix(1))
                std::cout << str.front() << ' ' << str << '\n';
        }

πŸ‘‘ Output πŸ‘‘

A ABCDEF
B BCDEF
C CDEF
D DEF
E EF
F F

πŸ¦‹ See also πŸ¦‹

  • back β€” accesses the last character (public member function)
  • empty β€” checks whether the view is empty (public member function)
  • front β€” accesses the first character (DR*) (public member function of std::basic_string<CharT,Traits,Allocator>)

kbye, this iconic little page came from cppreference.com, dated 2024.06.10 β€” page std::basic_..._view::front(3). mwah πŸ’‹πŸ’–

πŸ“¦ where this page comes from