86 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// iterator lower_bound(const key_type& k);14// const_iterator lower_bound(const key_type& k) const;15 16#include <cassert>17#include <deque>18#include <flat_map>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, class ValueContainer>27constexpr void test() {28 using Key = typename KeyContainer::value_type;29 using Value = typename ValueContainer::value_type;30 {31 using M = std::flat_map<Key, Value, std::less<Key>, KeyContainer, ValueContainer>;32 M m = {{1, 'a'}, {2, 'b'}, {4, 'd'}, {5, 'e'}, {8, 'h'}};33 ASSERT_SAME_TYPE(decltype(m.lower_bound(0)), typename M::iterator);34 ASSERT_SAME_TYPE(decltype(std::as_const(m).lower_bound(0)), typename M::const_iterator);35 assert(m.lower_bound(0) == m.begin());36 assert(m.lower_bound(1) == m.begin());37 assert(m.lower_bound(2) == m.begin() + 1);38 assert(m.lower_bound(3) == m.begin() + 2);39 assert(m.lower_bound(4) == m.begin() + 2);40 assert(m.lower_bound(5) == m.begin() + 3);41 assert(m.lower_bound(6) == m.begin() + 4);42 assert(m.lower_bound(7) == m.begin() + 4);43 assert(std::as_const(m).lower_bound(8) == m.begin() + 4);44 assert(std::as_const(m).lower_bound(9) == m.end());45 }46 {47 using M = std::flat_map<Key, Value, std::greater<Key>, KeyContainer, ValueContainer>;48 M m = {{1, 'a'}, {2, 'b'}, {4, 'd'}, {5, 'e'}, {8, 'h'}};49 ASSERT_SAME_TYPE(decltype(m.lower_bound(0)), typename M::iterator);50 ASSERT_SAME_TYPE(decltype(std::as_const(m).lower_bound(0)), typename M::const_iterator);51 assert(m.lower_bound(0) == m.end());52 assert(m.lower_bound(1) == m.begin() + 4);53 assert(m.lower_bound(2) == m.begin() + 3);54 assert(m.lower_bound(3) == m.begin() + 3);55 assert(m.lower_bound(4) == m.begin() + 2);56 assert(m.lower_bound(5) == m.begin() + 1);57 assert(m.lower_bound(6) == m.begin() + 1);58 assert(m.lower_bound(7) == m.begin() + 1);59 assert(std::as_const(m).lower_bound(8) == m.begin());60 assert(std::as_const(m).lower_bound(9) == m.begin());61 }62}63 64constexpr bool test() {65 test<std::vector<int>, std::vector<char>>();66#ifndef __cpp_lib_constexpr_deque67 if (!TEST_IS_CONSTANT_EVALUATED)68#endif69 {70 test<std::deque<int>, std::vector<char>>();71 }72 test<MinSequenceContainer<int>, MinSequenceContainer<char>>();73 test<std::vector<int, min_allocator<int>>, std::vector<char, min_allocator<char>>>();74 75 return true;76}77 78int main(int, char**) {79 test();80#if TEST_STD_VER >= 2681 static_assert(test());82#endif83 84 return 0;85}86