std::flat_m...:value_comp(3)

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

okay so bestie, you’re on the std::flat_m...:value_comp(3) page from the C++ Standard Libary manual β€” yes, that’s the exact spelling, no cap β€” and it’s literally all about std::flat_multiset::value_comp. it’s giving β€œtiny but important member function” energy πŸ’…βœ¨

✨ NAME ✨

std::flat_multiset::value_comp β€” std::flat_multiset::value_comp


🌸 Synopsis 🌸

std::flat_multiset::value_compare value_comp() const;  (since C++23)

so this one returns the function object that compares the values β€” and it is the same as key_comp. periodt. πŸŽ€

πŸŽ€ Parameters πŸŽ€

(none) β€” literally no parameters, bestie. zero. nada. 🫢

πŸ’– Return value πŸ’–

The value comparison function object. that’s the whole vibe. πŸ’…

⚑ Complexity ⚑

Constant. ⭐


🧚 Example 🧚

okay so here’s the example, run this code:

// Run this code

#include <iostream>
#include <flat_set>
#include <utility>

// Example module 97 key compare function
struct ModCmp
{
    bool operator()(int lhs, int rhs) const
    {
        return (lhs % 97) < (rhs % 97);
    }
};

int main()
{
    std::flat_multiset<int, ModCmp> cont{1, 2, 3, 4, 5};

    // Same behaviour as key_comp()
    auto comp_func = cont.value_comp();

    for (const int val{100}; const int key : cont)
    {
        const bool before = comp_func(key, val);
        const bool after = comp_func(val, key);

        std::cout << "Key (" << key << ") ";
        if (!before && !after)
            std::cout << "equivalent to key (" << val << ")\n";
        else if (before)
            std::cout << "goes before key (" << val << ")\n";
        else if (after)
            std::cout << "goes after key (" << val << ")\n";
        else
            std::unreachable();
    }
}

πŸ’¬ Output πŸ’¬

and the output is giving:

Key (1) goes before key (100)
Key (2) goes before key (100)
Key (3) equivalent to key (100)
Key (4) goes after key (100)
Key (5) goes after key (100)

πŸ”— See also πŸ”—

  • key_comp β€” returns the function that compares keys (public member function)

mwah πŸ’‹ β€” this page came from http://cppreference.com, version/date 2024.06.10, on std::flat_m...:value_comp(3). catch you later, bestie 🫢✨

πŸ“¦ where this page comes from