brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.7 KiB · 596da81 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_multimap>12 13// template<class Allocator>14//   explicit flat_multimap(const Allocator& a);15 16#include <cassert>17#include <deque>18#include <flat_map>19#include <functional>20#include <vector>21 22#include "test_macros.h"23#include "test_allocator.h"24#include "../../../test_compare.h"25 26template <template <class...> class KeyContainer, template <class...> class ValueContainer>27constexpr void test() {28  using A = test_allocator<short>;29  using M =30      std::flat_multimap<int,31                         long,32                         std::less<int>,33                         KeyContainer<int, test_allocator<int>>,34                         ValueContainer<long, test_allocator<long>>>;35  M m(A(0, 5));36  assert(m.empty());37  assert(m.begin() == m.end());38  assert(m.keys().get_allocator().get_id() == 5);39  assert(m.values().get_allocator().get_id() == 5);40}41 42constexpr bool test() {43  {44    // The constructors in this subclause shall not participate in overload45    // resolution unless uses_allocator_v<key_container_type, Alloc> is true46    // and uses_allocator_v<mapped_container_type, Alloc> is true.47 48    using C  = test_less<int>;49    using A1 = test_allocator<int>;50    using A2 = other_allocator<int>;51    using V1 = std::vector<int, A1>;52    using V2 = std::vector<int, A2>;53    using M1 = std::flat_multimap<int, int, C, V1, V1>;54    using M2 = std::flat_multimap<int, int, C, V1, V2>;55    using M3 = std::flat_multimap<int, int, C, V2, V1>;56    static_assert(std::is_constructible_v<M1, const A1&>);57    static_assert(!std::is_constructible_v<M1, const A2&>);58    static_assert(!std::is_constructible_v<M2, const A2&>);59    static_assert(!std::is_constructible_v<M3, const A2&>);60  }61  {62    // explicit63    using M =64        std::flat_multimap<int,65                           long,66                           std::less<int>,67                           std::vector<int, test_allocator<int>>,68                           std::vector<long, test_allocator<long>>>;69 70    static_assert(std::is_constructible_v<M, test_allocator<int>>);71    static_assert(!std::is_convertible_v<test_allocator<int>, M>);72  }73 74  test<std::vector, std::vector>();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