Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
Howard Hinnant | f5256e1 | 2010-05-11 21:36:01 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4 | // |
Howard Hinnant | b64f8b0 | 2010-11-16 22:09:02 +0000 | [diff] [blame] | 5 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 6 | // Source Licenses. See LICENSE.TXT for details. |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | // <set> |
| 11 | |
| 12 | // class set |
| 13 | |
| 14 | // template <class InputIterator> |
| 15 | // set(InputIterator first, InputIterator last, |
| 16 | // const value_compare& comp, const allocator_type& a); |
Marshall Clow | 24a7e33 | 2013-09-11 00:06:45 +0000 | [diff] [blame] | 17 | // |
| 18 | // template <class InputIterator> |
| 19 | // set(InputIterator first, InputIterator last, |
| 20 | // const allocator_type& a); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 21 | |
| 22 | #include <set> |
| 23 | #include <cassert> |
| 24 | |
Marshall Clow | 83e2c4d | 2013-01-05 03:21:01 +0000 | [diff] [blame] | 25 | #include "test_iterators.h" |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 26 | #include "../../../test_compare.h" |
Marshall Clow | 1b92188 | 2013-12-03 00:18:10 +0000 | [diff] [blame] | 27 | #include "test_allocator.h" |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 28 | |
| 29 | int main() |
| 30 | { |
| 31 | typedef int V; |
| 32 | V ar[] = |
| 33 | { |
| 34 | 1, |
| 35 | 1, |
| 36 | 1, |
| 37 | 2, |
| 38 | 2, |
| 39 | 2, |
| 40 | 3, |
| 41 | 3, |
| 42 | 3 |
| 43 | }; |
| 44 | typedef test_compare<std::less<V> > C; |
| 45 | typedef test_allocator<V> A; |
| 46 | std::set<V, C, A> m(input_iterator<const V*>(ar), |
| 47 | input_iterator<const V*>(ar+sizeof(ar)/sizeof(ar[0])), |
| 48 | C(5), A(7)); |
| 49 | assert(m.value_comp() == C(5)); |
| 50 | assert(m.get_allocator() == A(7)); |
| 51 | assert(m.size() == 3); |
| 52 | assert(distance(m.begin(), m.end()) == 3); |
| 53 | assert(*m.begin() == 1); |
| 54 | assert(*next(m.begin()) == 2); |
| 55 | assert(*next(m.begin(), 2) == 3); |
Marshall Clow | 24a7e33 | 2013-09-11 00:06:45 +0000 | [diff] [blame] | 56 | #if _LIBCPP_STD_VER > 11 |
| 57 | { |
| 58 | typedef int V; |
| 59 | V ar[] = |
| 60 | { |
| 61 | 1, |
| 62 | 1, |
| 63 | 1, |
| 64 | 2, |
| 65 | 2, |
| 66 | 2, |
| 67 | 3, |
| 68 | 3, |
| 69 | 3 |
| 70 | }; |
| 71 | typedef test_allocator<V> A; |
| 72 | typedef test_compare<std::less<int> > C; |
| 73 | A a(7); |
| 74 | std::set<V, C, A> m(ar, ar+sizeof(ar)/sizeof(ar[0]), a); |
| 75 | |
| 76 | assert(m.size() == 3); |
| 77 | assert(distance(m.begin(), m.end()) == 3); |
| 78 | assert(*m.begin() == 1); |
| 79 | assert(*next(m.begin()) == 2); |
| 80 | assert(*next(m.begin(), 2) == 3); |
| 81 | assert(m.get_allocator() == a); |
| 82 | } |
| 83 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 84 | } |