std::flat_m...p::contains(3)

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

πŸ¦‹ std::flat_m...p::contains(3) πŸ¦‹

okay so this is the C++ Standard Libary manual, and today’s main character is std::flat_multimap::contains β€” page std::flat_m...p::contains(3). it’s giving β€œdo I know this key or not?” energy, and honestly? iconic. πŸ’…


🌸 NAME 🌸

std::flat_multimap::contains β€” std::flat_multimap::contains


✨ Synopsis ✨

          bool contains( const Key& key ) const; (1) (since C++23)
          template< class K >                    (2) (since C++23)
          bool contains( const K& x ) const;
  1. (1) β€” checks if there is an element with key equivalent to key in the container. πŸ’–
  2. (2) β€” checks if there is an element with key that compares equivalent to the value x.

this overload participates in overload resolution only if the qualified-id Compare::is_transparent is valid and denotes a type. it allows calling this function without constructing an instance of Key. no cap, that’s the transparent-comparator flex. 🫢


πŸŽ€ Parameters πŸŽ€

  • key β€” key value of the element to search for
  • x β€” a value of any type that can be transparently compared with a key

πŸ’– Return value πŸ’–

true if there is such an element, otherwise false.


πŸ¦‹ Complexity πŸ¦‹

Logarithmic in the size of the container. logarithmic, bestie β€” not a whole scan, we’re bougie like that. ✨


🌈 Example 🌈

// Run this code

        #include <iostream>
        #include <flat_map>

        int main()
        {
            std::flat_multimap<int, char> example{{1, 'a'}, {2, 'b'}};

            for (int x : {2, 5})
                if (example.contains(x))
                    std::cout << x << ": Found\n";
                else
                    std::cout << x << ": Not found\n";
        }

⭐ Output ⭐

        2: Found
        5: Not found

πŸ‘‘ See also πŸ‘‘

  • find β€” finds element with specific key (public member function)
  • count β€” returns the number of elements matching specific key (public member function)
  • equal_range β€” returns range of elements matching a specific key (public member function)

that’s the whole page, bestie πŸ’– β€” source is http://cppreference.com, the version/date stamp is 2024.06.10, and the page is std::flat_m...p::contains(3). mwah 🫢

πŸ“¦ where this page comes from