Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / test / std / containers / associative / map / map.access / index_rv_key.pass.cpp
blob5e92e6d1b2b0c284fe5ad5c782db8d87fbe905ec
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 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03
11 // <map>
13 // class map
15 // mapped_type& operator[](key_type&& k);
17 #include <map>
18 #include <cassert>
20 #include "test_macros.h"
21 #include "count_new.h"
22 #include "MoveOnly.h"
23 #include "min_allocator.h"
24 #include "container_test_types.h"
26 int main(int, char**)
29 std::map<MoveOnly, double> m;
30 assert(m.size() == 0);
31 assert(m[1] == 0.0);
32 assert(m.size() == 1);
33 m[1] = -1.5;
34 assert(m[1] == -1.5);
35 assert(m.size() == 1);
36 assert(m[6] == 0);
37 assert(m.size() == 2);
38 m[6] = 6.5;
39 assert(m[6] == 6.5);
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);
46 assert(m[1] == 0.0);
47 assert(m.size() == 1);
48 m[1] = -1.5;
49 assert(m[1] == -1.5);
50 assert(m.size() == 1);
51 assert(m[6] == 0);
52 assert(m.size() == 2);
53 m[6] = 6.5;
54 assert(m[6] == 6.5);
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();
64 cc->reset();
66 Container c;
67 Key k(1);
68 cc->expect<std::piecewise_construct_t const&, std::tuple<Key &&>&&, std::tuple<>&&>();
69 MappedType& mref = c[std::move(k)];
70 assert(!cc->unchecked());
72 Key k2(1);
73 DisableAllocationGuard g;
74 MappedType& mref2 = c[std::move(k2)];
75 assert(&mref == &mref2);
80 return 0;