xref: /llvm-project/libcxx/test/libcxx/containers/unord/unord.multimap/assert.iterator.increment.pass.cpp (revision 41658bafb70680d0aafb7e79c7f694b8c2a5217d)
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 // Increment iterator past end.
12 
13 // REQUIRES: has-unix-headers, libcpp-hardening-mode={{extensive|debug}}
14 // UNSUPPORTED: c++03
15 // XFAIL: libcpp-hardening-mode=debug && availability-verbose_abort-missing
16 
17 #include <unordered_map>
18 #include <cassert>
19 #include <string>
20 
21 #include "check_assertion.h"
22 #include "min_allocator.h"
23 
main(int,char **)24 int main(int, char**) {
25   {
26     typedef std::unordered_multimap<int, std::string> C;
27     C c;
28     c.insert(std::make_pair(1, "one"));
29     C::iterator i = c.begin();
30     ++i;
31     assert(i == c.end());
32     TEST_LIBCPP_ASSERT_FAILURE(++i, "Attempted to increment a non-incrementable unordered container iterator");
33     C::const_iterator i2 = c.cbegin();
34     ++i2;
35     assert(i2 == c.cend());
36     TEST_LIBCPP_ASSERT_FAILURE(++i2, "Attempted to increment a non-incrementable unordered container const_iterator");
37   }
38 
39   {
40     typedef std::unordered_multimap<int,
41                                     std::string,
42                                     std::hash<int>,
43                                     std::equal_to<int>,
44                                     min_allocator<std::pair<const int, std::string>>>
45         C;
46     C c;
47     c.insert(std::make_pair(1, "one"));
48     C::iterator i = c.begin();
49     ++i;
50     assert(i == c.end());
51     TEST_LIBCPP_ASSERT_FAILURE(++i, "Attempted to increment a non-incrementable unordered container iterator");
52     C::const_iterator i2 = c.cbegin();
53     ++i2;
54     assert(i2 == c.cend());
55     TEST_LIBCPP_ASSERT_FAILURE(++i2, "Attempted to increment a non-incrementable unordered container const_iterator");
56   }
57 
58   return 0;
59 }
60