iterators.pass.cpp revision bc8d3f97eb5c958007f2713238472e0c1c8fe02c
1//===----------------------------------------------------------------------===//
2//
3// ��������������������The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10// <unordered_map>
11
12// template <class Key, class T, class Hash = hash<Key>, class Pred = equal_to<Key>,
13//           class Alloc = allocator<pair<const Key, T>>>
14// class unordered_map
15
16// iterator       begin()        {return __table_.begin();}
17// iterator       end()          {return __table_.end();}
18// const_iterator begin()  const {return __table_.begin();}
19// const_iterator end()    const {return __table_.end();}
20// const_iterator cbegin() const {return __table_.begin();}
21// const_iterator cend()   const {return __table_.end();}
22
23#include <unordered_map>
24#include <string>
25#include <cassert>
26
27int main()
28{
29    {
30        typedef std::unordered_map<int, std::string> C;
31        typedef std::pair<int, std::string> P;
32        P a[] =
33        {
34            P(1, "one"),
35            P(2, "two"),
36            P(3, "three"),
37            P(4, "four"),
38            P(1, "four"),
39            P(2, "four"),
40        };
41        C c(a, a + sizeof(a)/sizeof(a[0]));
42        assert(c.bucket_count() >= 5);
43        assert(c.size() == 4);
44        assert(std::distance(c.begin(), c.end()) == c.size());
45        assert(std::distance(c.cbegin(), c.cend()) == c.size());
46    }
47    {
48        typedef std::unordered_map<int, std::string> C;
49        typedef std::pair<int, std::string> P;
50        P a[] =
51        {
52            P(1, "one"),
53            P(2, "two"),
54            P(3, "three"),
55            P(4, "four"),
56            P(1, "four"),
57            P(2, "four"),
58        };
59        const C c(a, a + sizeof(a)/sizeof(a[0]));
60        assert(c.bucket_count() >= 5);
61        assert(c.size() == 4);
62        assert(std::distance(c.begin(), c.end()) == c.size());
63        assert(std::distance(c.cbegin(), c.cend()) == c.size());
64    }
65}
66