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-exception |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | |
9 | // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20 |
10 | |
11 | // using key_type = Key; |
12 | // using mapped_type = T; |
13 | // using value_type = pair<key_type, mapped_type>; |
14 | // using key_compare = Compare; |
15 | // using reference = pair<const key_type&, mapped_type&>; |
16 | // using const_reference = pair<const key_type&, const mapped_type&>; |
17 | // using size_type = size_t; |
18 | // using difference_type = ptrdiff_t; |
19 | // using iterator = implementation-defined; // see [container.requirements] |
20 | // using const_iterator = implementation-defined; // see [container.requirements] |
21 | // using reverse_iterator = std::reverse_iterator<iterator>; |
22 | // using const_reverse_iterator = std::reverse_iterator<const_iterator>; |
23 | // using key_container_type = KeyContainer; |
24 | // using mapped_container_type = MappedContainer; |
25 | |
26 | // class value_compare; |
27 | |
28 | // struct containers { |
29 | // key_container_type keys; |
30 | // mapped_container_type values; |
31 | // }; |
32 | |
33 | #include <concepts> |
34 | #include <deque> |
35 | #include <flat_map> |
36 | #include <functional> |
37 | #include <ranges> |
38 | #include <string> |
39 | #include <vector> |
40 | #include "min_allocator.h" |
41 | |
42 | void test() { |
43 | { |
44 | using M = std::flat_map<int, double>; |
45 | static_assert(std::is_same_v<typename M::key_type, int>); |
46 | static_assert(std::is_same_v<typename M::mapped_type, double>); |
47 | static_assert(std::is_same_v<typename M::value_type, std::pair<int, double>>); |
48 | static_assert(std::is_same_v<typename M::key_compare, std::less<int>>); |
49 | static_assert(std::is_same_v<typename M::reference, std::pair<const int&, double&>>); |
50 | static_assert(std::is_same_v<typename M::const_reference, std::pair<const int&, const double&>>); |
51 | static_assert(std::is_same_v<typename M::size_type, size_t>); |
52 | static_assert(std::is_same_v<typename M::difference_type, ptrdiff_t>); |
53 | static_assert(requires { typename M::iterator; }); |
54 | static_assert(requires { typename M::const_iterator; }); |
55 | static_assert(std::is_same_v<typename M::reverse_iterator, std::reverse_iterator<typename M::iterator>>); |
56 | static_assert( |
57 | std::is_same_v<typename M::const_reverse_iterator, std::reverse_iterator<typename M::const_iterator>>); |
58 | static_assert(std::is_same_v<typename M::key_container_type, std::vector<int>>); |
59 | static_assert(std::is_same_v<typename M::mapped_container_type, std::vector<double>>); |
60 | static_assert(requires { typename M::value_compare; }); |
61 | static_assert(requires { typename M::containers; }); |
62 | static_assert(std::is_same_v<decltype(M::containers::keys), std::vector<int>>); |
63 | static_assert(std::is_same_v<decltype(M::containers::values), std::vector<double>>); |
64 | } |
65 | |
66 | { |
67 | struct A {}; |
68 | struct Compare { |
69 | bool operator()(const std::string&, const std::string&) const; |
70 | }; |
71 | using M = std::flat_map<std::string, A, Compare, std::deque<std::string>, std::deque<A>>; |
72 | static_assert(std::is_same_v<typename M::key_type, std::string>); |
73 | static_assert(std::is_same_v<typename M::mapped_type, A>); |
74 | static_assert(std::is_same_v<typename M::value_type, std::pair<std::string, A>>); |
75 | static_assert(std::is_same_v<typename M::key_compare, Compare>); |
76 | static_assert(std::is_same_v<typename M::reference, std::pair<const std::string&, A&>>); |
77 | static_assert(std::is_same_v<typename M::const_reference, std::pair<const std::string&, const A&>>); |
78 | static_assert(std::is_same_v<typename M::size_type, size_t>); |
79 | static_assert(std::is_same_v<typename M::difference_type, ptrdiff_t>); |
80 | static_assert(requires { typename M::iterator; }); |
81 | static_assert(requires { typename M::const_iterator; }); |
82 | static_assert(std::is_same_v<typename M::reverse_iterator, std::reverse_iterator<typename M::iterator>>); |
83 | static_assert( |
84 | std::is_same_v<typename M::const_reverse_iterator, std::reverse_iterator<typename M::const_iterator>>); |
85 | static_assert(std::is_same_v<typename M::key_container_type, std::deque<std::string>>); |
86 | static_assert(std::is_same_v<typename M::mapped_container_type, std::deque<A>>); |
87 | static_assert(requires { typename M::value_compare; }); |
88 | static_assert(requires { typename M::containers; }); |
89 | static_assert(std::is_same_v<decltype(M::containers::keys), std::deque<std::string>>); |
90 | static_assert(std::is_same_v<decltype(M::containers::values), std::deque<A>>); |
91 | } |
92 | { |
93 | using C = std::flat_map<int, short>; |
94 | static_assert(std::is_same_v<C::key_type, int>); |
95 | static_assert(std::is_same_v<C::mapped_type, short>); |
96 | static_assert(std::is_same_v<C::value_type, std::pair<int, short>>); |
97 | static_assert(std::is_same_v<C::key_compare, std::less<int>>); |
98 | static_assert(!std::is_same_v<C::value_compare, std::less<int>>); |
99 | static_assert(std::is_same_v<C::reference, std::pair<const int&, short&>>); |
100 | static_assert(std::is_same_v<C::const_reference, std::pair<const int&, const short&>>); |
101 | static_assert(std::random_access_iterator<C::iterator>); |
102 | static_assert(std::random_access_iterator<C::const_iterator>); |
103 | static_assert(std::random_access_iterator<C::reverse_iterator>); |
104 | static_assert(std::random_access_iterator<C::const_reverse_iterator>); |
105 | static_assert(std::is_same_v<C::reverse_iterator, std::reverse_iterator<C::iterator>>); |
106 | static_assert(std::is_same_v<C::const_reverse_iterator, std::reverse_iterator<C::const_iterator>>); |
107 | static_assert(std::is_same_v<C::size_type, std::size_t>); |
108 | static_assert(std::is_same_v<C::difference_type, std::ptrdiff_t>); |
109 | static_assert(std::is_same_v<C::key_container_type, std::vector<int>>); |
110 | static_assert(std::is_same_v<C::mapped_container_type, std::vector<short>>); |
111 | } |
112 | { |
113 | using C = std::flat_map<short, int, std::greater<long>, std::deque<short, min_allocator<short>>>; |
114 | static_assert(std::is_same_v<C::key_type, short>); |
115 | static_assert(std::is_same_v<C::mapped_type, int>); |
116 | static_assert(std::is_same_v<C::value_type, std::pair<short, int>>); |
117 | static_assert(std::is_same_v<C::key_compare, std::greater<long>>); |
118 | static_assert(!std::is_same_v<C::value_compare, std::greater<long>>); |
119 | static_assert(std::is_same_v<C::reference, std::pair<const short&, int&>>); |
120 | static_assert(std::is_same_v<C::const_reference, std::pair<const short&, const int&>>); |
121 | static_assert(std::random_access_iterator<C::iterator>); |
122 | static_assert(std::random_access_iterator<C::const_iterator>); |
123 | static_assert(std::random_access_iterator<C::reverse_iterator>); |
124 | static_assert(std::random_access_iterator<C::const_reverse_iterator>); |
125 | static_assert(std::is_same_v<C::reverse_iterator, std::reverse_iterator<C::iterator>>); |
126 | static_assert(std::is_same_v<C::const_reverse_iterator, std::reverse_iterator<C::const_iterator>>); |
127 | // size_type is invariably size_t |
128 | static_assert(std::is_same_v<C::size_type, std::size_t>); |
129 | static_assert(std::is_same_v<C::difference_type, std::ptrdiff_t>); |
130 | static_assert(std::is_same_v<C::key_container_type, std::deque<short, min_allocator<short>>>); |
131 | static_assert(std::is_same_v<C::mapped_container_type, std::vector<int>>); |
132 | } |
133 | } |
134 | |