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 //===----------------------------------------------------------------------===//
15 // mapped_type& operator[](key_type&& k);
20 #include "test_macros.h"
21 #include "count_new.h"
23 #include "min_allocator.h"
24 #include "container_test_types.h"
29 std::map
<MoveOnly
, double> m
;
30 assert(m
.size() == 0);
32 assert(m
.size() == 1);
35 assert(m
.size() == 1);
37 assert(m
.size() == 2);
40 assert(m
.size() == 2);
43 typedef std::pair
<const MoveOnly
, double> V
;
44 std::map
<MoveOnly
, double, std::less
<MoveOnly
>, min_allocator
<V
>> m
;
45 assert(m
.size() == 0);
47 assert(m
.size() == 1);
50 assert(m
.size() == 1);
52 assert(m
.size() == 2);
55 assert(m
.size() == 2);
58 // Use "container_test_types.h" to check what arguments get passed
59 // to the allocator for operator[]
60 using Container
= TCT::map
<>;
61 using Key
= Container::key_type
;
62 using MappedType
= Container::mapped_type
;
63 ConstructController
* cc
= getConstructController();
68 cc
->expect
<std::piecewise_construct_t
const&, std::tuple
<Key
&&>&&, std::tuple
<>&&>();
69 MappedType
& mref
= c
[std::move(k
)];
70 assert(!cc
->unchecked());
73 DisableAllocationGuard g
;
74 MappedType
& mref2
= c
[std::move(k2
)];
75 assert(&mref
== &mref2
);