brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.4 KiB · b5272f2 Raw
97 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// class flat_set14 15// pair<iterator, bool> insert(value_type&& v);16 17#include <flat_set>18#include <cassert>19#include <deque>20 21#include "MinSequenceContainer.h"22#include "MoveOnly.h"23#include "min_allocator.h"24#include "test_macros.h"25#include "../helpers.h"26 27template <class KeyContainer>28constexpr void test_one() {29  using Key = typename KeyContainer::value_type;30  using M   = std::flat_set<Key, TransparentComparator, KeyContainer>;31  using R   = std::pair<typename M::iterator, bool>;32  using V   = typename M::value_type;33 34  M m;35  std::same_as<R> decltype(auto) r = m.insert(V(2));36  assert(r.second);37  assert(r.first == m.begin());38  assert(m.size() == 1);39  assert(*r.first == V(2));40 41  r = m.insert(V(1));42  assert(r.second);43  assert(r.first == m.begin());44  assert(m.size() == 2);45  assert(*r.first == V(1));46 47  r = m.insert(V(3));48  assert(r.second);49  assert(r.first == std::ranges::prev(m.end()));50  assert(m.size() == 3);51  assert(*r.first == V(3));52 53  r = m.insert(V(3));54  assert(!r.second);55  assert(r.first == std::ranges::prev(m.end()));56  assert(m.size() == 3);57  assert(*r.first == V(3));58}59 60constexpr bool test() {61  test_one<std::vector<int>>();62  test_one<std::vector<MoveOnly>>();63#ifndef __cpp_lib_constexpr_deque64  if (!TEST_IS_CONSTANT_EVALUATED)65#endif66  {67    test_one<std::deque<int>>();68    test_one<std::deque<MoveOnly>>();69  }70  test_one<MinSequenceContainer<int>>();71  test_one<MinSequenceContainer<MoveOnly>>();72  test_one<std::vector<int, min_allocator<int>>>();73  test_one<std::vector<MoveOnly, min_allocator<MoveOnly>>>();74 75  return true;76}77 78void test_exception() {79  auto insert_func = [](auto& m, auto key_arg) {80    using FlatSet    = std::decay_t<decltype(m)>;81    using value_type = typename FlatSet::value_type;82    value_type p(key_arg);83    m.insert(std::move(p));84  };85  test_emplace_exception_guarantee(insert_func);86}87 88int main(int, char**) {89  test();90  test_exception();91#if TEST_STD_VER >= 2692  static_assert(test());93#endif94 95  return 0;96}97