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& operator[](const key_type& k);
18 #include "test_macros.h"
19 #include "count_new.h"
20 #include "min_allocator.h"
21 #include "private_constructor.h"
22 #if TEST_STD_VER >= 11
23 #include "container_test_types.h"
29 typedef std::pair
<const int, double> V
;
40 std::map
<int, double> m(ar
, ar
+sizeof(ar
)/sizeof(ar
[0]));
41 assert(m
.size() == 7);
43 assert(m
.size() == 7);
46 assert(m
.size() == 7);
48 assert(m
.size() == 8);
51 assert(m
.size() == 8);
53 #if TEST_STD_VER >= 11
55 typedef std::pair
<const int, double> V
;
66 std::map
<int, double, std::less
<int>, min_allocator
<V
>> m(ar
, ar
+sizeof(ar
)/sizeof(ar
[0]));
67 assert(m
.size() == 7);
69 assert(m
.size() == 7);
73 assert(m
.size() == 7);
75 assert(m
.size() == 8);
78 assert(m
.size() == 8);
81 // Use "container_test_types.h" to check what arguments get passed
82 // to the allocator for operator[]
83 using Container
= TCT::map
<>;
84 using Key
= Container::key_type
;
85 using MappedType
= Container::mapped_type
;
86 ConstructController
* cc
= getConstructController();
91 cc
->expect
<std::piecewise_construct_t
const&, std::tuple
<Key
const&>&&, std::tuple
<>&&>();
92 MappedType
& mref
= c
[k
];
93 assert(!cc
->unchecked());
95 DisableAllocationGuard g
;
96 MappedType
& mref2
= c
[k
];
97 assert(&mref
== &mref2
);
103 cc
->expect
<std::piecewise_construct_t
const&, std::tuple
<Key
const&>&&, std::tuple
<>&&>();
104 MappedType
& mref
= c
[k
];
105 assert(!cc
->unchecked());
107 DisableAllocationGuard g
;
108 MappedType
& mref2
= c
[k
];
109 assert(&mref
== &mref2
);
114 #if TEST_STD_VER > 11
116 typedef std::pair
<const int, double> V
;
127 std::map
<int, double, std::less
<>> m(ar
, ar
+sizeof(ar
)/sizeof(ar
[0]));
129 assert(m
.size() == 7);
131 assert(m
.size() == 7);
133 assert(m
[1] == -1.5);
134 assert(m
.size() == 7);
136 assert(m
.size() == 8);
139 assert(m
.size() == 8);