brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.0 KiB · 79dd218 Raw
85 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 lower_bound(const key_type& k);16// const_iterator lower_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     = {{1, 'a'}, {2, 'a'}, {2, 'c'}, {2, 'b'}, {4, 'd'}, {5, 'a'}, {5, 'e'}, {8, 'h'}, {8, 'a'}};35    ASSERT_SAME_TYPE(decltype(m.lower_bound(0)), typename M::iterator);36    ASSERT_SAME_TYPE(decltype(std::as_const(m).lower_bound(0)), typename M::const_iterator);37    assert(m.lower_bound(0) == m.begin());38    assert(m.lower_bound(1) == m.begin());39    assert(m.lower_bound(2) == m.begin() + 1);40    assert(m.lower_bound(3) == m.begin() + 4);41    assert(m.lower_bound(4) == m.begin() + 4);42    assert(m.lower_bound(5) == m.begin() + 5);43    assert(m.lower_bound(6) == m.begin() + 7);44    assert(m.lower_bound(7) == m.begin() + 7);45    assert(std::as_const(m).lower_bound(8) == m.begin() + 7);46    assert(std::as_const(m).lower_bound(9) == m.end());47  }48  {49    using M = std::flat_multimap<Key, Value, std::greater<Key>, KeyContainer, ValueContainer>;50    M m     = {{1, 'a'}, {1, 'b'}, {2, 'b'}, {4, 'd'}, {4, 'a'}, {4, 'e'}, {5, 'e'}, {8, 'a'}, {8, 'h'}};51    ASSERT_SAME_TYPE(decltype(m.lower_bound(0)), typename M::iterator);52    ASSERT_SAME_TYPE(decltype(std::as_const(m).lower_bound(0)), typename M::const_iterator);53    assert(m.lower_bound(0) == m.end());54    assert(m.lower_bound(1) == m.begin() + 7);55    assert(m.lower_bound(2) == m.begin() + 6);56    assert(m.lower_bound(3) == m.begin() + 6);57    assert(m.lower_bound(4) == m.begin() + 3);58    assert(m.lower_bound(5) == m.begin() + 2);59    assert(m.lower_bound(6) == m.begin() + 2);60    assert(m.lower_bound(7) == m.begin() + 2);61    assert(std::as_const(m).lower_bound(8) == m.begin());62    assert(std::as_const(m).lower_bound(9) == m.begin());63  }64}65 66constexpr bool test() {67  test<std::vector<int>, std::vector<char>>();68#ifndef __cpp_lib_constexpr_deque69  if (!TEST_IS_CONSTANT_EVALUATED)70#endif71    test<std::deque<int>, std::vector<char>>();72  test<MinSequenceContainer<int>, MinSequenceContainer<char>>();73  test<std::vector<int, min_allocator<int>>, std::vector<char, min_allocator<char>>>();74  return true;75}76 77int main(int, char**) {78  test();79#if TEST_STD_VER >= 2680  static_assert(test());81#endif82 83  return 0;84}85