70 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 find(const key_type& k);14// const_iterator find(const key_type& k) const;15 16#include <cassert>17#include <deque>18#include <flat_map>19#include <functional>20#include <string>21#include <utility>22 23#include "MinSequenceContainer.h"24#include "test_macros.h"25#include "min_allocator.h"26 27template <class KeyContainer, class ValueContainer>28constexpr void test() {29 using Key = typename KeyContainer::value_type;30 using Value = typename ValueContainer::value_type;31 using M = std::flat_map<Key, Value, std::less<Key>, KeyContainer, ValueContainer>;32 33 M m = {{1, 'a'}, {2, 'b'}, {4, 'd'}, {5, 'e'}, {8, 'h'}};34 ASSERT_SAME_TYPE(decltype(m.find(0)), typename M::iterator);35 ASSERT_SAME_TYPE(decltype(std::as_const(m).find(0)), typename M::const_iterator);36 assert(m.find(0) == m.end());37 assert(m.find(1) == m.begin());38 assert(m.find(2) == m.begin() + 1);39 assert(m.find(3) == m.end());40 assert(m.find(4) == m.begin() + 2);41 assert(m.find(5) == m.begin() + 3);42 assert(m.find(6) == m.end());43 assert(m.find(7) == m.end());44 assert(std::as_const(m).find(8) == m.begin() + 4);45 assert(std::as_const(m).find(9) == m.end());46}47 48constexpr bool test() {49 test<std::vector<int>, std::vector<char>>();50#ifndef __cpp_lib_constexpr_deque51 if (!TEST_IS_CONSTANT_EVALUATED)52#endif53 {54 test<std::deque<int>, std::vector<char>>();55 }56 test<MinSequenceContainer<int>, MinSequenceContainer<char>>();57 test<std::vector<int, min_allocator<int>>, std::vector<char, min_allocator<char>>>();58 59 return true;60}61 62int main(int, char**) {63 test();64#if TEST_STD_VER >= 2665 static_assert(test());66#endif67 68 return 0;69}70