std::flat_map::size(3)

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

πŸ’– NAME πŸ’–

std::flat_map::size β€” std::flat_map::size β€” okay bestie, this is the std::flat_map::size(3) page from the C++ Standard Libary manual, and it's giving β€œhow many elements are we carrying?” energy πŸ’…

🌸 Synopsis 🌸

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

Returns the number of elements in the container adaptor. Equivalent to return c.keys.size(). No cap ✨

πŸŽ€ Parameters πŸŽ€

(none) β€” literally none, not a single parameter in sight 🫢

πŸ¦‹ Return value πŸ¦‹

The number of elements in the container adaptor. That's the whole tea β˜•

⭐ Complexity ⭐

Constant. Iconic, efficient, no drama πŸ’«

πŸ”₯ Example πŸ”₯

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

// Run this code

#include <iostream>
#include <flat_map>

int main()
{
    std::flat_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 adaptor is empty (public member function)
  • size β€” returns the size of a container or array (C++17) (function template)
  • ssize β€” returns the size of a container or array (C++20) (function template)
  • max_size β€” returns the maximum possible number of elements (public member function)

source/version: http://cppreference.com 🌸 date: 2024.06.10 β€” mwah, bestie πŸ’‹

πŸ“¦ where this page comes from