std::set::contains(3)

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

πŸ’… std::set::contains(3) πŸ’…

hiii bestie!! welcome to the page for std::set::contains(3) from the C++ Standard Libary manual ✨ this is the one where we ask a set β€œdo u contain this key?” and it gives us a yes/no, no cap πŸ’–

🌸 NAME 🌸

std::set::contains - std::set::contains

✨ Synopsis ✨

bool contains( const Key& key ) const; (1) (since C++20)
template< class K >                    (2) (since C++20)
bool contains( const K& x ) const;
  1. bestie, this overload checks if there’s an element with key equivalent to key in the container πŸ‘€
  2. this overload checks if there’s 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. periodt πŸ’…

πŸŽ€ 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. it’s giving simple boolean energy, fr fr 😌

πŸ¦‹ Complexity πŸ¦‹

Logarithmic in the size of the container. ngl that’s the whole complexity tea β˜•

πŸ“ Example πŸ“

// Run this code

        #include <iostream>
        #include <set>

        int main()
        {
            std::set<int> example{1, 2, 3, 4};

            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: http://cppreference.com, version/date: 2024.06.10, page: std::set::contains(3) β€” slay and bye πŸ’…βœ¨

πŸ“¦ where this page comes from