brintos

brintos / llvm-project-archived public Read only

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