std::array::max_size(3)

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

hey bestie, welcome to std::array::max_size(3) from the C++ Standard Libary manual πŸ’…βœ¨

🌸 NAME

std::array::max_size - std::array::max_size

Like, that's the whole name β€” it's giving β€œsay my name twice” energy πŸŽ€

✨ Synopsis

constexpr size_type max_size() const noexcept;  (since C++11)

okay so this returns the maximum number of elements the container is able to hold due to system or library implementation limitations, i.e. std::distance(begin(), end()) for the largest container πŸ¦‹

It’s a constexpr member, it’s noexcept, and it’s been around since C++11. no cap.

πŸŽ€ Parameters

(none)

No parameters, bestie β€” nothing to pass in. πŸ™ˆ

πŸ’– Return value

Maximum number of elements. periodt.

πŸ¦‹ Complexity

Constant. lowkey the easiest complexity ever πŸ’…

🌈 Notes

Because each std::array<T, N> is a fixed-size container, the value returned by max_size equals N (which is also the value returned by size).

So yeah β€” it’s fixed-size, so max_size is just N, and size() says the same thing. fr fr πŸ‘‘

πŸ“ Example

Run this code, bestie (// Run this code):

#include <iostream>
#include <locale>
#include <array>

int main()
{
    std::array<char, 10> p;
    std::array<long, 10> q;

    std::cout.imbue(std::locale("en_US.UTF-8"));
    std::cout << std::uppercase
              << "p.max_size() = " << std::dec << p.max_size() << " = 0x"
              << std::hex << p.max_size() << '\n'
              << "q.max_size() = " << std::dec << q.max_size() << " = 0x"
              << std::hex << q.max_size() << '\n';
}

✨ Output:

10 = 0xA
10 = 0xA

πŸ‘‘ See also

  • size returns the number of elements (public member function)

big lil sign-off: source is http://cppreference.com and the version/date is 2024.06.10 β€” mwah πŸ’‹

πŸ“¦ where this page comes from