std::map::size(3)

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

okay bestie, welcome to std::map::size(3) from the C++ Standard Libary β€” manual name folded in right here, typo preserved because details are details πŸ’…βœ¨

✨ NAME ✨

std::map::size β€” std::map::size (yes bestie, the name is the name, it's giving self-referential main character energy πŸŽ€)

πŸ¦‹ Synopsis πŸ¦‹

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

Returns the number of elements in the container, i.e. std::distance(begin(), end()). That's the whole synopsis tea β˜•

🌸 Parameters 🌸

(none) β€” she takes zero parameters, low-maintenance icon behavior 🫢

πŸ’– Return value πŸ’–

The number of elements in the container. That's the whole answer, no cap πŸ’…

⚑ Complexity ⚑

Constant. The page says constant, bestie β€” that's the vibe check, and it passes πŸ”₯

πŸŽ€ Example πŸŽ€

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

// Run this code

#include <iostream>
#include <map>

int main()
{
    std::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 β€” bare size entry from the original See also block, standing right here with no extra description attached
  • ssize β€” returns the size of a container or array
    • (C++17)
    • (function template)
    • (C++20)

source: http://cppreference.com Β· version/date: 2024.06.10 Β· page tag: std::map::size(3) β€” bye bestie, go count your elements and slay πŸ’–πŸŒˆ

πŸ“¦ where this page comes from