blob: 5ccb6e5cbcd75972b6d4fcc5a3d4cacb882b3109 [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001//===----------------------------------------------------------------------===//
2//
Howard Hinnantf5256e12010-05-11 21:36:01 +00003// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004//
Howard Hinnantb64f8b02010-11-16 22:09:02 +00005// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00007//
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 Clow24a7e332013-09-11 00:06:45 +000017//
18// template <class InputIterator>
19// set(InputIterator first, InputIterator last,
20// const allocator_type& a);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000021
22#include <set>
23#include <cassert>
24
Marshall Clow83e2c4d2013-01-05 03:21:01 +000025#include "test_iterators.h"
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000026#include "../../../test_compare.h"
Marshall Clow1b921882013-12-03 00:18:10 +000027#include "test_allocator.h"
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000028
29int 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 Clow24a7e332013-09-11 00:06:45 +000056#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 Hinnantbc8d3f92010-05-11 19:42:16 +000084}