xref: /llvm-project/libcxx/test/std/containers/unord/unord.multimap/iterators.compile.fail.cpp (revision 7a6aaf9b23d6ac2fb8c11c00c73e55c0bc7aa2f0)
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 // <unordered_map>
10 
11 // template <class Key, class T, class Hash = hash<Key>, class Pred = equal_to<Key>,
12 //           class Alloc = allocator<pair<const Key, T>>>
13 // class unordered_multimap
14 
15 // iterator       begin()        {return __table_.begin();}
16 // iterator       end()          {return __table_.end();}
17 // const_iterator begin()  const {return __table_.begin();}
18 // const_iterator end()    const {return __table_.end();}
19 // const_iterator cbegin() const {return __table_.begin();}
20 // const_iterator cend()   const {return __table_.end();}
21 
22 #include <unordered_map>
23 #include <string>
24 #include <cassert>
25 
26 #include "test_macros.h"
27 
main(int,char **)28 int main(int, char**)
29 {
30     {
31         typedef std::unordered_multimap<int, std::string> C;
32         typedef std::pair<int, std::string> P;
33         P a[] =
34         {
35             P(1, "one"),
36             P(2, "two"),
37             P(3, "three"),
38             P(4, "four"),
39             P(1, "four"),
40             P(2, "four"),
41         };
42         C c(a, a + sizeof(a)/sizeof(a[0]));
43         LIBCPP_ASSERT(c.bucket_count() == 7);
44         assert(c.size() == 6);
45         assert(std::distance(c.begin(), c.end()) == c.size());
46         assert(std::distance(c.cbegin(), c.cend()) == c.size());
47         C::iterator i = c.begin();
48         i->second = "ONE";
49         assert(i->second == "ONE");
50         i->first = 2;
51     }
52     {
53         typedef std::unordered_multimap<int, std::string> C;
54         typedef std::pair<int, std::string> P;
55         P a[] =
56         {
57             P(1, "one"),
58             P(2, "two"),
59             P(3, "three"),
60             P(4, "four"),
61             P(1, "four"),
62             P(2, "four"),
63         };
64         const C c(a, a + sizeof(a)/sizeof(a[0]));
65         LIBCPP_ASSERT(c.bucket_count() == 7);
66         assert(c.size() == 6);
67         assert(std::distance(c.begin(), c.end()) == c.size());
68         assert(std::distance(c.cbegin(), c.cend()) == c.size());
69     }
70 
71   return 0;
72 }
73