brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.9 KiB · d4d1992 Raw
90 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//       iterator upper_bound(const key_type& k);14// const_iterator upper_bound(const key_type& k) const;15 16#include <cassert>17#include <deque>18#include <flat_set>19#include <functional>20#include <utility>21 22#include "MinSequenceContainer.h"23#include "test_macros.h"24#include "min_allocator.h"25 26template <class KeyContainer>27constexpr void test_one() {28  using Key = typename KeyContainer::value_type;29  {30    using M = std::flat_multiset<Key, std::less<>, KeyContainer>;31    M m     = {1, 1, 2, 2, 4, 4, 5, 5, 8, 8};32    ASSERT_SAME_TYPE(decltype(m.upper_bound(0)), typename M::iterator);33    ASSERT_SAME_TYPE(decltype(std::as_const(m).upper_bound(0)), typename M::const_iterator);34    assert(m.upper_bound(0) == m.begin());35    assert(m.upper_bound(1) == m.begin() + 2);36    assert(m.upper_bound(2) == m.begin() + 4);37    assert(m.upper_bound(3) == m.begin() + 4);38    assert(m.upper_bound(4) == m.begin() + 6);39    assert(m.upper_bound(5) == m.begin() + 8);40    assert(m.upper_bound(6) == m.begin() + 8);41    assert(std::as_const(m).upper_bound(7) == m.begin() + 8);42    assert(std::as_const(m).upper_bound(8) == m.end());43    assert(std::as_const(m).upper_bound(9) == m.end());44  }45 46  {47    using M = std::flat_multiset<Key, std::greater<int>, KeyContainer>;48    M m     = {1, 1, 1, 1, 2, 2, 4, 4, 4, 5, 5, 5, 5, 5, 8, 8};49    ASSERT_SAME_TYPE(decltype(m.upper_bound(0)), typename M::iterator);50    ASSERT_SAME_TYPE(decltype(std::as_const(m).upper_bound(0)), typename M::const_iterator);51    assert(m.upper_bound(0) == m.end());52    assert(m.upper_bound(1) == m.end());53    assert(m.upper_bound(2) == m.begin() + 12);54    assert(m.upper_bound(3) == m.begin() + 10);55    assert(m.upper_bound(4) == m.begin() + 10);56    assert(m.upper_bound(5) == m.begin() + 7);57    assert(m.upper_bound(6) == m.begin() + 2);58    assert(m.upper_bound(7) == m.begin() + 2);59    assert(std::as_const(m).upper_bound(8) == m.begin() + 2);60    assert(std::as_const(m).upper_bound(9) == m.begin());61  }62  {63    // empty64    using M = std::flat_multiset<Key, std::less<>, KeyContainer>;65    M m;66    assert(m.upper_bound(0) == m.end());67  }68}69 70constexpr bool test() {71  test_one<std::vector<int>>();72#ifndef __cpp_lib_constexpr_deque73  if (!TEST_IS_CONSTANT_EVALUATED)74#endif75    test_one<std::deque<int>>();76  test_one<MinSequenceContainer<int>>();77  test_one<std::vector<int, min_allocator<int>>>();78 79  return true;80}81 82int main(int, char**) {83  test();84#if TEST_STD_VER >= 2685  static_assert(test());86#endif87 88  return 0;89}90