std::unordered_map::size(3)

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

πŸ¦‹ std::unordered_map::size(3) πŸ¦‹

okay bestie, welcome to the std::unordered_map::size page from the C++ Standard Libary manual. this is literally the β€œhow many elements are in my container” moment, and it’s giving main character energy. πŸ’…βœ¨

🌸 NAME 🌸

std::unordered_map::size β€” std::unordered_map::size

✨ Synopsis ✨

size_type size() const noexcept;  (since C++11)

Returns the number of elements in the container, i.e. std::distance(begin(), end()).

bestie, that’s the whole vibe: count the elements. 🫢

πŸŽ€ Parameters πŸŽ€

(none) β€” zero arguments, not a single one. iconic. ✨

πŸ’– Return value πŸ’–

The number of elements in the container.

⭐ Complexity ⭐

Constant. literally constant, no cap. πŸ’…

πŸ”₯ Example πŸ”₯

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

// Run this code

#include <iostream>
#include <unordered_map>

int main()
{
    std::unordered_map<int,char> nums{{1, 'a'}, {3, 'b'}, {5, 'c'}, {7, 'd'}};

    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) / (C++20); (function template)

mwah πŸ’‹ source: http://cppreference.com; version/date: 2024.06.10; this is the std::unordered_map::size(3) page β€” go count your elements, bestie! 🫢✨

πŸ“¦ where this page comes from