std::basic_...w::max_size(3)

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

πŸŽ€ NAME πŸŽ€

okay so this is the std::basic_...w::max_size(3) page from the C++ Standard Libary, and the NAME line is literally std::basic_string_view::max_size - std::basic_string_view::max_size. Bestie, it's a whole page for one tiny function and I'm obsessed. πŸ’…

✨ Synopsis ✨

constexpr size_type max_size() const noexcept;

(since C++17) β€” yes bestie, this one landed in C++17. The largest possible number of char-like objects that can be referred to by a basic_string_view. It's literally the max ceiling of char-like cuties a view can refer to. 🌈

🫢 Parameters 🫢

(none) β€” literally no parameters, no stress, just vibes. 😌

πŸ’– Return value πŸ’–

Maximum number of characters. That's the whole return value, bestie. πŸŽ€

⚑ Complexity ⚑

Constant. Periodt. ✨

πŸ“ Example πŸ“

Okay, run this code:

       // Run this code

        #include <cstdint>
        #include <iostream>
        #include <limits>
        #include <string_view>

        int main()
        {
            std::cout << std::numeric_limits<std::int64_t>::max()
                      << " <- numeric_limits<int64_t>::max()\n"
                      << std::string_view{}.max_size()
                      << " <- string_view::max_size()\n"
                      << std::basic_string_view<char>{}.max_size()
                      << " <- basic_string_view<char>::max_size()\n"
                      << std::basic_string_view<char16_t>{}.max_size()
                      << " <- basic_string_view<char16_t>::max_size()\n"
                      << std::wstring_view{}.max_size()
                      << " <- wstring_view::max_size()\n"
                      << std::basic_string_view<char32_t>{}.max_size()
                      << " <- basic_string_view<char32_t>::max_size()\n";
        }

Possible output:

        9223372036854775807 <- numeric_limits<int64_t>::max()
        4611686018427387899 <- string_view::max_size()
        4611686018427387899 <- basic_string_view<char>::max_size()
        2305843009213693949 <- basic_string_view<char16_t>::max_size()
        1152921504606846974 <- wstring_view::max_size()
        1152921504606846974 <- basic_string_view<char32_t>::max_size()

πŸ‘‘ See also πŸ‘‘

  • size β€” returns the number of characters
  • length β€” (public member function)
  • empty β€” checks whether the view is empty (public member function)
  • max_size β€” returns the maximum number of characters (public member function of std::basic_string<CharT,Traits,Allocator>)

πŸ’– source/version: http://cppreference.com Β· date: 2024.06.10 Β· page: std::basic_...w::max_size(3) β€” bye bestie, go get that max size! πŸ’–

πŸ“¦ where this page comes from