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_set>
10
11// template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>,
12// class Alloc = allocator<Value>>
13// class unordered_set
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_set>
23#include <cassert>
24
25int main(int, char**) {
26 {
27 typedef std::unordered_set<int> C;
28 typedef int P;
29 P a[] = {P(1), P(2), P(3), P(4), P(1), P(2)};
30 C c(a, a + sizeof(a) / sizeof(a[0]));
31 assert(c.bucket_count() >= 5);
32 assert(c.size() == 6);
33 assert(std::distance(c.begin(), c.end()) == c.size());
34 assert(std::distance(c.cbegin(), c.cend()) == c.size());
35 C::iterator i = c.begin();
36 assert(*i == 1);
37 *i = 2;
38 }
39 {
40 typedef std::unordered_set<int> C;
41 typedef int P;
42 P a[] = {P(1), P(2), P(3), P(4), P(1), P(2)};
43 const C c(a, a + sizeof(a) / sizeof(a[0]));
44 assert(c.bucket_count() >= 5);
45 assert(c.size() == 6);
46 assert(std::distance(c.begin(), c.end()) == c.size());
47 assert(std::distance(c.cbegin(), c.cend()) == c.size());
48 }
49
50 return 0;
51}
52

source code of libcxx/test/std/containers/unord/unord.set/iterators.compile.fail.cpp