std::list::size(3)

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

πŸ’… std::list::size β€” C++ Standard Libary main character energy

okay so this is the page for std::list::size(3), straight outta the C++ Standard Libary, and yes bestie it is literally about std::list::size. no cap, we're getting into it. 🫢


✨ NAME ✨

std::list::size β€” std::list::size

like… that's the name, that's the function, that's the vibe. periodt. πŸ’…


πŸ¦‹ Synopsis πŸ¦‹

Two eras, bestie β€” the before-times and the noexcept glow-up:

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

It returns the number of elements in the container, i.e. std::distance(begin(), end()). that's the whole assignment. ✨


πŸ’– Parameters πŸ’–

(none)

absolutely none, bestie. not a single argument. she takes no notes. πŸŽ€


πŸŽ€ Return value πŸŽ€

The number of elements in the container.

that's it. that's the tea. the count. πŸ‘‘


πŸ”₯ Complexity πŸ”₯

  • Until C++11: Constant or linear.
  • Since C++11: Constant.

so modern you is eating good, fr fr. πŸ”₯


🌈 Example 🌈

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

// Run this code

#include <iostream>
#include <list>

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

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

πŸ“ Output πŸ“

nums contains 4 elements.

slay. four little ints, one iconic little output. πŸ’–


πŸ‘‘ See also πŸ‘‘

  • empty β€” checks whether the container is empty (public member function)
  • max_size β€” returns the maximum possible number of elements (public member function)
  • resize β€” changes the number of elements stored (public member function)

mwah πŸ’‹ β€” source/version: http://cppreference.com Β· date: 2024.06.10 Β· manual: std::list::size(3). bestie, you understood the assignment. πŸ§šβ€β™€οΈπŸ’œ

πŸ“¦ where this page comes from