brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.1 KiB · b1c667a Raw
82 lines · cpp
1//===----------------------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9// UNSUPPORTED: c++03, c++11, c++14, c++17, c++2010 11// <flat_set>12 13// key_compare key_comp() const;14// value_compare value_comp() const;15 16#include <cassert>17#include <flat_set>18#include <functional>19#include <utility>20#include <vector>21 22#include "test_macros.h"23 24constexpr bool test() {25  {26    using M    = std::flat_set<int>;27    using Comp = std::less<int>; // the default28    M m        = {};29    ASSERT_SAME_TYPE(M::key_compare, Comp);30    ASSERT_SAME_TYPE(decltype(m.key_comp()), Comp);31    ASSERT_SAME_TYPE(decltype(m.value_comp()), Comp);32    Comp kc = m.key_comp();33    assert(kc(1, 2));34    assert(!kc(2, 1));35    auto vc = m.value_comp();36    assert(vc(1, 2));37    assert(!vc(2, 1));38  }39  if (!TEST_IS_CONSTANT_EVALUATED) {40    using Comp = std::function<bool(int, int)>;41    using M    = std::flat_set<int, Comp>;42    Comp comp  = std::greater<int>();43    M m({}, comp);44    ASSERT_SAME_TYPE(M::key_compare, Comp);45    ASSERT_SAME_TYPE(decltype(m.key_comp()), Comp);46    ASSERT_SAME_TYPE(decltype(m.value_comp()), Comp);47    Comp kc = m.key_comp();48    assert(!kc(1, 2));49    assert(kc(2, 1));50    auto vc = m.value_comp();51    assert(!vc(1, 2));52    assert(vc(2, 1));53  }54  {55    using Comp = std::less<>;56    using M    = std::flat_set<int, Comp>;57    M m        = {};58    ASSERT_SAME_TYPE(M::key_compare, Comp);59    ASSERT_SAME_TYPE(decltype(m.key_comp()), Comp);60    ASSERT_SAME_TYPE(decltype(m.value_comp()), Comp);61    Comp kc = m.key_comp();62    assert(kc(1, 2));63    assert(!kc(2, 1));64    auto vc = m.value_comp();65    auto a  = std::make_pair(1, 2);66    ASSERT_SAME_TYPE(decltype(vc(a, a)), bool);67    assert(vc(1, 2));68    assert(!vc(2, 1));69  }70 71  return true;72}73 74int main(int, char**) {75  test();76#if TEST_STD_VER >= 2677  static_assert(test());78#endif79 80  return 0;81}82