brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.7 KiB · 8568867 Raw
93 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& m);14 15#include <cassert>16#include <deque>17#include <flat_map>18#include <vector>19 20#include "test_macros.h"21#include "../../../test_compare.h"22#include "test_allocator.h"23 24template <template <class...> class KeyContainer, template <class...> class ValueContainer>25constexpr void test() {26  {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  = mo;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>(6));38    assert(m.values().get_allocator() == test_allocator<char>(7));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  {48    using C  = test_less<int>;49    using Ks = KeyContainer<int, other_allocator<int>>;50    using Vs = ValueContainer<char, other_allocator<char>>;51    auto ks  = Ks({1, 3, 5}, other_allocator<int>(6));52    auto vs  = Vs({2, 2, 1}, other_allocator<char>(7));53    using M  = std::flat_map<int, char, C, Ks, Vs>;54    auto mo  = M(Ks(ks, other_allocator<int>(6)), Vs(vs, other_allocator<int>(7)), C(5));55    auto m   = mo;56 57    assert(m.key_comp() == C(5));58    assert(m.keys() == ks);59    assert(m.values() == vs);60    assert(m.keys().get_allocator() == other_allocator<int>(-2));61    assert(m.values().get_allocator() == other_allocator<char>(-2));62 63    // mo is unchanged64    assert(mo.key_comp() == C(5));65    assert(mo.keys() == ks);66    assert(mo.values() == vs);67    assert(mo.keys().get_allocator() == other_allocator<int>(6));68    assert(mo.values().get_allocator() == other_allocator<char>(7));69  }70}71 72constexpr bool test() {73  test<std::vector, std::vector>();74 75#ifndef __cpp_lib_constexpr_deque76  if (!TEST_IS_CONSTANT_EVALUATED)77#endif78  {79    test<std::deque, std::deque>();80  }81 82  return true;83}84 85int main(int, char**) {86  test();87#if TEST_STD_VER >= 2688  static_assert(test());89#endif90 91  return 0;92}93