brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.1 KiB · 5128a40 Raw
94 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 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_multiset<Key, std::less<Key>, KeyContainer>;29  using R   = typename M::iterator;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 == m.begin());36  assert(m.size() == 1);37  assert(*r == 2);38 39  const VT v2(1);40  r = m.insert(v2);41  assert(r == m.begin());42  assert(m.size() == 2);43  assert(*r == 1);44 45  const VT v3(3);46  r = m.insert(v3);47  assert(r == std::ranges::prev(m.end()));48  assert(m.size() == 3);49  assert(*r == 3);50 51  const VT v4(3);52  r = m.insert(v4);53  assert(r == std::ranges::prev(m.end()));54  assert(m.size() == 4);55  assert(*r == 3);56 57  const VT v5(1);58  r = m.insert(v5);59  assert(r == m.begin() + 1);60  assert(m.size() == 5);61  assert(*r == 1);62}63 64constexpr bool test() {65  test_one<std::vector<int>>();66#ifndef __cpp_lib_constexpr_deque67  if (!TEST_IS_CONSTANT_EVALUATED)68#endif69    test_one<std::deque<int>>();70  test_one<MinSequenceContainer<int>>();71  test_one<std::vector<int, min_allocator<int>>>();72 73  return true;74}75 76void test_exception() {77  auto insert_func = [](auto& m, auto key_arg) {78    using value_type = typename std::decay_t<decltype(m)>::value_type;79    const value_type p(key_arg);80    m.insert(p);81  };82  test_emplace_exception_guarantee(insert_func);83}84 85int main(int, char**) {86  test();87#if TEST_STD_VER >= 2688  static_assert(test());89#endif90  test_exception();91 92  return 0;93}94