brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.5 KiB · 96f2120 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_map>12 13// class flat_multimap14 15// iterator insert(const value_type& v);16 17#include <flat_map>18#include <deque>19#include <cassert>20#include <functional>21 22#include "MinSequenceContainer.h"23#include "test_macros.h"24#include "../helpers.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_multimap<Key, Value, std::less<Key>, KeyContainer, ValueContainer>;32  using R     = typename M::iterator;33  using VT    = typename M::value_type;34  M m;35 36  const VT v1(2, 2.5);37  std::same_as<R> decltype(auto) r = m.insert(v1);38  assert(r == m.begin());39  assert(m.size() == 1);40  assert(r->first == 2);41  assert(r->second == 2.5);42 43  const VT v2(1, 1.5);44  r = m.insert(v2);45  assert(r == m.begin());46  assert(m.size() == 2);47  assert(r->first == 1);48  assert(r->second == 1.5);49 50  const VT v3(3, 3.5);51  r = m.insert(v3);52  assert(r == m.begin() + 2);53  assert(m.size() == 3);54  assert(r->first == 3);55  assert(r->second == 3.5);56 57  const VT v4(3, 4.5);58  r = m.insert(v4);59  assert(r == m.begin() + 3);60  assert(m.size() == 4);61  assert(r->first == 3);62  assert(r->second == 4.5);63}64 65constexpr bool test() {66  test<std::vector<int>, std::vector<double>>();67#ifndef __cpp_lib_constexpr_deque68  if (!TEST_IS_CONSTANT_EVALUATED)69#endif70    test<std::deque<int>, std::vector<double>>();71  test<MinSequenceContainer<int>, MinSequenceContainer<double>>();72  test<std::vector<int, min_allocator<int>>, std::vector<double, min_allocator<double>>>();73 74  if (!TEST_IS_CONSTANT_EVALUATED) {75    auto insert_func = [](auto& m, auto key_arg, auto value_arg) {76      using FlatMap    = std::decay_t<decltype(m)>;77      using value_type = typename FlatMap::value_type;78      const value_type p(std::piecewise_construct, std::tuple(key_arg), std::tuple(value_arg));79      m.insert(p);80    };81    test_emplace_exception_guarantee(insert_func);82  }83  return true;84}85 86int main(int, char**) {87  test();88#if TEST_STD_VER >= 2689  static_assert(test());90#endif91 92  return 0;93}94