std::array::size(3)

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

πŸ’– NAME πŸ’–

Okay so welcome to std::array::size(3), bestie β€” it's from the C++ Standard Libary manual, and the NAME section is literally std::array::size - std::array::size (yes, it said it twice, and honestly? iconic). ✨

✨ Synopsis ✨

This is the vibe:

constexpr size_type size() const noexcept;

It's been around since C++11, and it returns the number of elements in the container, i.e. std::distance(begin(), end()). No cap. πŸ’…

πŸŽ€ Parameters πŸŽ€

(none) β€” literally zero parameters, not a single one, the param list is empty and thriving. 🫢

🌸 Return value 🌸

The number of elements in the container. That's it, that's the tea. πŸ“

πŸ’… Complexity πŸ’…

Constant. ⭐

πŸ¦‹ Example πŸ¦‹

The following code uses size to display the number of elements in a std::array:

// Run this code

#include <array>
#include <iostream>

int main()
{
    std::array<int, 4> nums{1, 3, 5, 7};

    std::cout << "nums contains " << nums.size() << " elements.\n";
}

🌈 Output 🌈

nums contains 4 elements.

⭐ See also ⭐

  • empty β€” checks whether the container is empty (public member function)
  • max_size β€” returns the maximum possible number of elements (public member function)
  • size
  • ssize β€” returns the size of a container or array (C++17) (function template) (C++20)

mwah πŸ’‹ this page came from http://cppreference.com, version/date 2024.06.10 β€” see u next time bestie 🫢

πŸ“¦ where this page comes from