//===----------------------------------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20 // // key_compare key_comp() const; // value_compare value_comp() const; #include #include #include #include #include #include "test_macros.h" constexpr bool test() { { using M = std::flat_set; using Comp = std::less; // the default M m = {}; ASSERT_SAME_TYPE(M::key_compare, Comp); ASSERT_SAME_TYPE(decltype(m.key_comp()), Comp); ASSERT_SAME_TYPE(decltype(m.value_comp()), Comp); Comp kc = m.key_comp(); assert(kc(1, 2)); assert(!kc(2, 1)); auto vc = m.value_comp(); assert(vc(1, 2)); assert(!vc(2, 1)); } if (!TEST_IS_CONSTANT_EVALUATED) { using Comp = std::function; using M = std::flat_set; Comp comp = std::greater(); M m({}, comp); ASSERT_SAME_TYPE(M::key_compare, Comp); ASSERT_SAME_TYPE(decltype(m.key_comp()), Comp); ASSERT_SAME_TYPE(decltype(m.value_comp()), Comp); Comp kc = m.key_comp(); assert(!kc(1, 2)); assert(kc(2, 1)); auto vc = m.value_comp(); assert(!vc(1, 2)); assert(vc(2, 1)); } { using Comp = std::less<>; using M = std::flat_set; M m = {}; ASSERT_SAME_TYPE(M::key_compare, Comp); ASSERT_SAME_TYPE(decltype(m.key_comp()), Comp); ASSERT_SAME_TYPE(decltype(m.value_comp()), Comp); Comp kc = m.key_comp(); assert(kc(1, 2)); assert(!kc(2, 1)); auto vc = m.value_comp(); auto a = std::make_pair(1, 2); ASSERT_SAME_TYPE(decltype(vc(a, a)), bool); assert(vc(1, 2)); assert(!vc(2, 1)); } return true; } int main(int, char**) { test(); #if TEST_STD_VER >= 26 static_assert(test()); #endif return 0; }