88 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_map>12 13// class flat_multimap14 15// iterator upper_bound(const key_type& k);16// const_iterator upper_bound(const key_type& k) const;17 18#include <cassert>19#include <deque>20#include <flat_map>21#include <functional>22#include <utility>23 24#include "MinSequenceContainer.h"25#include "test_macros.h"26#include "min_allocator.h"27 28template <class KeyContainer, class ValueContainer>29constexpr void test() {30 using Key = typename KeyContainer::value_type;31 using Value = typename ValueContainer::value_type;32 {33 using M = std::flat_multimap<Key, Value, std::less<Key>, KeyContainer, ValueContainer>;34 M m = {35 {1, 'a'}, {2, 'b'}, {4, 'd'}, {4, 'e'}, {4, 'a'}, {4, 'b'}, {5, 'e'}, {5, 'a'}, {8, 'a'}, {8, 'b'}, {8, 'h'}};36 ASSERT_SAME_TYPE(decltype(m.upper_bound(0)), typename M::iterator);37 ASSERT_SAME_TYPE(decltype(std::as_const(m).upper_bound(0)), typename M::const_iterator);38 assert(m.upper_bound(0) == m.begin());39 assert(m.upper_bound(1) == m.begin() + 1);40 assert(m.upper_bound(2) == m.begin() + 2);41 assert(m.upper_bound(3) == m.begin() + 2);42 assert(m.upper_bound(4) == m.begin() + 6);43 assert(m.upper_bound(5) == m.begin() + 8);44 assert(m.upper_bound(6) == m.begin() + 8);45 assert(std::as_const(m).upper_bound(7) == m.begin() + 8);46 assert(std::as_const(m).upper_bound(8) == m.end());47 assert(std::as_const(m).upper_bound(9) == m.end());48 }49 50 {51 using M = std::flat_multimap<Key, Value, std::greater<Key>, KeyContainer, ValueContainer>;52 M m = {53 {1, 'a'}, {2, 'b'}, {4, 'd'}, {4, 'e'}, {4, 'a'}, {4, 'b'}, {5, 'e'}, {5, 'a'}, {8, 'a'}, {8, 'b'}, {8, 'h'}};54 ASSERT_SAME_TYPE(decltype(m.upper_bound(0)), typename M::iterator);55 ASSERT_SAME_TYPE(decltype(std::as_const(m).upper_bound(0)), typename M::const_iterator);56 assert(m.upper_bound(0) == m.end());57 assert(m.upper_bound(1) == m.end());58 assert(m.upper_bound(2) == m.begin() + 10);59 assert(m.upper_bound(3) == m.begin() + 9);60 assert(m.upper_bound(4) == m.begin() + 9);61 assert(m.upper_bound(5) == m.begin() + 5);62 assert(m.upper_bound(6) == m.begin() + 3);63 assert(m.upper_bound(7) == m.begin() + 3);64 assert(std::as_const(m).upper_bound(8) == m.begin() + 3);65 assert(std::as_const(m).upper_bound(9) == m.begin());66 }67}68 69constexpr bool test() {70 test<std::vector<int>, std::vector<char>>();71#ifndef __cpp_lib_constexpr_deque72 if (!TEST_IS_CONSTANT_EVALUATED)73#endif74 test<std::deque<int>, std::vector<char>>();75 test<MinSequenceContainer<int>, MinSequenceContainer<char>>();76 test<std::vector<int, min_allocator<int>>, std::vector<char, min_allocator<char>>>();77 return true;78}79 80int main(int, char**) {81 test();82#if TEST_STD_VER >= 2683 static_assert(test());84#endif85 86 return 0;87}88