• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 // <set>
11 
12 // class multiset
13 
14 // template <class... Args>
15 //   iterator emplace(Args&&... args);
16 
17 #include <set>
18 #include <cassert>
19 
20 #include "../../Emplaceable.h"
21 #include "DefaultOnly.h"
22 #include "min_allocator.h"
23 
main()24 int main()
25 {
26 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
27     {
28         typedef std::multiset<DefaultOnly> M;
29         typedef M::iterator R;
30         M m;
31         assert(DefaultOnly::count == 0);
32         R r = m.emplace();
33         assert(r == m.begin());
34         assert(m.size() == 1);
35         assert(*m.begin() == DefaultOnly());
36         assert(DefaultOnly::count == 1);
37 
38         r = m.emplace();
39         assert(r == next(m.begin()));
40         assert(m.size() == 2);
41         assert(*m.begin() == DefaultOnly());
42         assert(DefaultOnly::count == 2);
43     }
44     assert(DefaultOnly::count == 0);
45     {
46         typedef std::multiset<Emplaceable> M;
47         typedef M::iterator R;
48         M m;
49         R r = m.emplace();
50         assert(r == m.begin());
51         assert(m.size() == 1);
52         assert(*m.begin() == Emplaceable());
53         r = m.emplace(2, 3.5);
54         assert(r == next(m.begin()));
55         assert(m.size() == 2);
56         assert(*r == Emplaceable(2, 3.5));
57         r = m.emplace(2, 3.5);
58         assert(r == next(m.begin(), 2));
59         assert(m.size() == 3);
60         assert(*r == Emplaceable(2, 3.5));
61     }
62     {
63         typedef std::multiset<int> M;
64         typedef M::iterator R;
65         M m;
66         R r = m.emplace(M::value_type(2));
67         assert(r == m.begin());
68         assert(m.size() == 1);
69         assert(*r == 2);
70     }
71 #if __cplusplus >= 201103L
72     {
73         typedef std::multiset<int, std::less<int>, min_allocator<int>> M;
74         typedef M::iterator R;
75         M m;
76         R r = m.emplace(M::value_type(2));
77         assert(r == m.begin());
78         assert(m.size() == 1);
79         assert(*r == 2);
80     }
81 #endif
82 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
83 }
84