flat_multiset_value_comp

flat_multiset_value_comp (std::flat_multiset::value_comp — 값 비교 함수)

std::flat_multiset이 값을 비교하는 데 쓰는 함수 객체를 반환하는 멤버 함수예요. key_comp와 같아요.

출처: cppreference

본문

시그니처는 다음과 같아요.

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

값을 비교하는 함수 객체를 반환해요. key_comp와 같아요.

반환값

값 비교 함수 객체.

복잡도

상수(constant)예요.

예제

#include <iostream>
#include <flat_set>
// 모듈로 97 키 비교 함수 예시
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};
    // 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 (100)\n";
        else if (before)
            std::cout << "goes before key (100)\n";
        else if (after)
            std::cout << "goes after key (100)\n";
        else
            std::unreachable();
    }
}

함께 보기

  • key_comp: 키를 비교하는 함수를 반환해요 (공개 멤버 함수)

더 알아보기 (Learn more)

cppreference