89 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 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_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_set<Key, std::less<>, KeyContainer>;31 M m = {1, 2, 4, 5, 8};32 ASSERT_SAME_TYPE(decltype(m.lower_bound(0)), typename M::iterator);33 ASSERT_SAME_TYPE(decltype(std::as_const(m).lower_bound(0)), typename M::const_iterator);34 assert(m.lower_bound(0) == m.begin());35 assert(m.lower_bound(1) == m.begin());36 assert(m.lower_bound(2) == m.begin() + 1);37 assert(m.lower_bound(3) == m.begin() + 2);38 assert(m.lower_bound(4) == m.begin() + 2);39 assert(m.lower_bound(5) == m.begin() + 3);40 assert(m.lower_bound(6) == m.begin() + 4);41 assert(m.lower_bound(7) == m.begin() + 4);42 assert(std::as_const(m).lower_bound(8) == m.begin() + 4);43 assert(std::as_const(m).lower_bound(9) == m.end());44 }45 {46 using M = std::flat_set<Key, std::greater<int>, KeyContainer>;47 M m = {1, 2, 4, 5, 8};48 ASSERT_SAME_TYPE(decltype(m.lower_bound(0)), typename M::iterator);49 ASSERT_SAME_TYPE(decltype(std::as_const(m).lower_bound(0)), typename M::const_iterator);50 assert(m.lower_bound(0) == m.end());51 assert(m.lower_bound(1) == m.begin() + 4);52 assert(m.lower_bound(2) == m.begin() + 3);53 assert(m.lower_bound(3) == m.begin() + 3);54 assert(m.lower_bound(4) == m.begin() + 2);55 assert(m.lower_bound(5) == m.begin() + 1);56 assert(m.lower_bound(6) == m.begin() + 1);57 assert(m.lower_bound(7) == m.begin() + 1);58 assert(std::as_const(m).lower_bound(8) == m.begin());59 assert(std::as_const(m).lower_bound(9) == m.begin());60 }61 {62 // empty63 using M = std::flat_set<Key, std::less<>, KeyContainer>;64 M m;65 assert(m.lower_bound(0) == m.end());66 }67}68 69constexpr bool test() {70 test_one<std::vector<int>>();71#ifndef __cpp_lib_constexpr_deque72 if (!TEST_IS_CONSTANT_EVALUATED)73#endif74 test_one<std::deque<int>>();75 test_one<MinSequenceContainer<int>>();76 test_one<std::vector<int, min_allocator<int>>>();77 78 return true;79}80 81int main(int, char**) {82 test();83#if TEST_STD_VER >= 2684 static_assert(test());85#endif86 87 return 0;88}89