1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
13 // mapped_type& at(const key_type& k);
14 // const mapped_type& at(const key_type& k) const;
20 #include "min_allocator.h"
21 #include "test_macros.h"
26 typedef std::pair
<const int, double> V
;
37 std::map
<int, double> m(ar
, ar
+sizeof(ar
)/sizeof(ar
[0]));
38 assert(m
.size() == 7);
39 assert(m
.at(1) == 1.5);
41 assert(m
.at(1) == -1.5);
42 assert(m
.at(2) == 2.5);
43 assert(m
.at(3) == 3.5);
44 assert(m
.at(4) == 4.5);
45 assert(m
.at(5) == 5.5);
46 #ifndef TEST_HAS_NO_EXCEPTIONS
49 TEST_IGNORE_NODISCARD m
.at(6);
52 catch (std::out_of_range
&)
56 assert(m
.at(7) == 7.5);
57 assert(m
.at(8) == 8.5);
58 assert(m
.size() == 7);
61 typedef std::pair
<const int, double> V
;
72 const std::map
<int, double> m(ar
, ar
+sizeof(ar
)/sizeof(ar
[0]));
73 assert(m
.size() == 7);
74 assert(m
.at(1) == 1.5);
75 assert(m
.at(2) == 2.5);
76 assert(m
.at(3) == 3.5);
77 assert(m
.at(4) == 4.5);
78 assert(m
.at(5) == 5.5);
79 #ifndef TEST_HAS_NO_EXCEPTIONS
82 TEST_IGNORE_NODISCARD m
.at(6);
85 catch (std::out_of_range
&)
89 assert(m
.at(7) == 7.5);
90 assert(m
.at(8) == 8.5);
91 assert(m
.size() == 7);
93 #if TEST_STD_VER >= 11
95 typedef std::pair
<const int, double> V
;
106 std::map
<int, double, std::less
<int>, min_allocator
<V
>> m(ar
, ar
+sizeof(ar
)/sizeof(ar
[0]));
107 assert(m
.size() == 7);
108 assert(m
.at(1) == 1.5);
110 assert(m
.at(1) == -1.5);
111 assert(m
.at(2) == 2.5);
112 assert(m
.at(3) == 3.5);
113 assert(m
.at(4) == 4.5);
114 assert(m
.at(5) == 5.5);
115 #ifndef TEST_HAS_NO_EXCEPTIONS
118 TEST_IGNORE_NODISCARD m
.at(6);
121 catch (std::out_of_range
&)
125 assert(m
.at(7) == 7.5);
126 assert(m
.at(8) == 8.5);
127 assert(m
.size() == 7);
130 typedef std::pair
<const int, double> V
;
141 const std::map
<int, double, std::less
<int>, min_allocator
<V
>> m(ar
, ar
+sizeof(ar
)/sizeof(ar
[0]));
142 assert(m
.size() == 7);
143 assert(m
.at(1) == 1.5);
144 assert(m
.at(2) == 2.5);
145 assert(m
.at(3) == 3.5);
146 assert(m
.at(4) == 4.5);
147 assert(m
.at(5) == 5.5);
148 #ifndef TEST_HAS_NO_EXCEPTIONS
151 TEST_IGNORE_NODISCARD m
.at(6);
154 catch (std::out_of_range
&)
158 assert(m
.at(7) == 7.5);
159 assert(m
.at(8) == 8.5);
160 assert(m
.size() == 7);