brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.9 KiB · daf9b70 Raw
73 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 find(const key_type& k);14// const_iterator find(const key_type& k) const;15 16#include <cassert>17#include <deque>18#include <flat_set>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>28constexpr void test_one() {29  using Key = typename KeyContainer::value_type;30  using M   = std::flat_set<Key, std::less<>, KeyContainer>;31  {32    M m = {1, 2, 4, 5, 8};33    ASSERT_SAME_TYPE(decltype(m.find(0)), typename M::iterator);34    ASSERT_SAME_TYPE(decltype(std::as_const(m).find(0)), typename M::const_iterator);35    assert(m.find(0) == m.end());36    assert(m.find(1) == m.begin());37    assert(m.find(2) == m.begin() + 1);38    assert(m.find(3) == m.end());39    assert(m.find(4) == m.begin() + 2);40    assert(m.find(5) == m.begin() + 3);41    assert(m.find(6) == m.end());42    assert(m.find(7) == m.end());43    assert(std::as_const(m).find(8) == m.begin() + 4);44    assert(std::as_const(m).find(9) == m.end());45  }46  {47    // empty48    M m;49    assert(m.find(0) == m.end());50  }51}52 53constexpr bool test() {54  test_one<std::vector<int>>();55#ifndef __cpp_lib_constexpr_deque56  if (!TEST_IS_CONSTANT_EVALUATED)57#endif58    test_one<std::deque<int>>();59  test_one<MinSequenceContainer<int>>();60  test_one<std::vector<int, min_allocator<int>>>();61 62  return true;63}64 65int main(int, char**) {66  test();67#if TEST_STD_VER >= 2668  static_assert(test());69#endif70 71  return 0;72}73