std::array::max_size(3)
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
sizereturns 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
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms