brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.7 KiB · f8b5774 Raw
88 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// flat_map(const flat_map&, const allocator_type&);14 15#include <cassert>16#include <deque>17#include <flat_map>18#include <functional>19#include <vector>20 21#include "test_macros.h"22#include "../../../test_compare.h"23#include "test_allocator.h"24 25template <template <class...> class KeyContainer, template <class...> class ValueContainer>26constexpr void test() {27  using C = test_less<int>;28  KeyContainer<int, test_allocator<int>> ks({1, 3, 5}, test_allocator<int>(6));29  ValueContainer<char, test_allocator<char>> vs({2, 2, 1}, test_allocator<char>(7));30  using M = std::flat_map<int, char, C, decltype(ks), decltype(vs)>;31  auto mo = M(ks, vs, C(5));32  auto m  = M(mo, test_allocator<int>(3));33 34  assert(m.key_comp() == C(5));35  assert(m.keys() == ks);36  assert(m.values() == vs);37  assert(m.keys().get_allocator() == test_allocator<int>(3));38  assert(m.values().get_allocator() == test_allocator<char>(3));39 40  // mo is unchanged41  assert(mo.key_comp() == C(5));42  assert(mo.keys() == ks);43  assert(mo.values() == vs);44  assert(mo.keys().get_allocator() == test_allocator<int>(6));45  assert(mo.values().get_allocator() == test_allocator<char>(7));46}47 48constexpr bool test() {49  {50    // The constructors in this subclause shall not participate in overload51    // resolution unless uses_allocator_v<key_container_type, Alloc> is true52    // and uses_allocator_v<mapped_container_type, Alloc> is true.53 54    using C  = test_less<int>;55    using A1 = test_allocator<int>;56    using A2 = other_allocator<int>;57    using V1 = std::vector<int, A1>;58    using V2 = std::vector<int, A2>;59    using M1 = std::flat_map<int, int, C, V1, V1>;60    using M2 = std::flat_map<int, int, C, V1, V2>;61    using M3 = std::flat_map<int, int, C, V2, V1>;62    static_assert(std::is_constructible_v<M1, const M1&, const A1&>);63    static_assert(!std::is_constructible_v<M1, const M1&, const A2&>);64    static_assert(!std::is_constructible_v<M2, const M2&, const A2&>);65    static_assert(!std::is_constructible_v<M3, const M3&, const A2&>);66  }67 68  test<std::vector, std::vector>();69 70#ifndef __cpp_lib_constexpr_deque71  if (!TEST_IS_CONSTANT_EVALUATED)72#endif73  {74    test<std::deque, std::deque>();75  }76 77  return true;78}79 80int main(int, char**) {81  test();82#if TEST_STD_VER >= 2683  static_assert(test());84#endif85 86  return 0;87}88