1 //===----------------------------------------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
12 // class function<R(ArgTypes...)>
14 // template <MoveConstructible R, MoveConstructible ... ArgTypes>
15 // void swap(function<R(ArgTypes...)>&, function<R(ArgTypes...)>&);
22 #include "count_new.hpp"
39 for (int i = 0; i < 10; ++i)
40 data_[i] = a.data_[i];
45 int operator()(int i) const
47 for (int j = 0; j < 10; ++j)
52 int id() const {return data_[0];}
57 int g(int) {return 0;}
58 int h(int) {return 1;}
62 assert(globalMemCounter.checkOutstandingNewEq(0));
64 std::function<int(int)> f1 = A(1);
65 std::function<int(int)> f2 = A(2);
66 assert(A::count == 2);
67 assert(globalMemCounter.checkOutstandingNewEq(2));
68 assert(f1.target<A>()->id() == 1);
69 assert(f2.target<A>()->id() == 2);
71 assert(A::count == 2);
72 assert(globalMemCounter.checkOutstandingNewEq(2));
73 assert(f1.target<A>()->id() == 2);
74 assert(f2.target<A>()->id() == 1);
76 assert(A::count == 0);
77 assert(globalMemCounter.checkOutstandingNewEq(0));
79 std::function<int(int)> f1 = A(1);
80 std::function<int(int)> f2 = g;
81 assert(A::count == 1);
82 assert(globalMemCounter.checkOutstandingNewEq(1));
83 assert(f1.target<A>()->id() == 1);
84 assert(*f2.target<int(*)(int)>() == g);
86 assert(A::count == 1);
87 assert(globalMemCounter.checkOutstandingNewEq(1));
88 assert(*f1.target<int(*)(int)>() == g);
89 assert(f2.target<A>()->id() == 1);
91 assert(A::count == 0);
92 assert(globalMemCounter.checkOutstandingNewEq(0));
94 std::function<int(int)> f1 = g;
95 std::function<int(int)> f2 = A(1);
96 assert(A::count == 1);
97 assert(globalMemCounter.checkOutstandingNewEq(1));
98 assert(*f1.target<int(*)(int)>() == g);
99 assert(f2.target<A>()->id() == 1);
101 assert(A::count == 1);
102 assert(globalMemCounter.checkOutstandingNewEq(1));
103 assert(f1.target<A>()->id() == 1);
104 assert(*f2.target<int(*)(int)>() == g);
106 assert(A::count == 0);
107 assert(globalMemCounter.checkOutstandingNewEq(0));
109 std::function<int(int)> f1 = g;
110 std::function<int(int)> f2 = h;
111 assert(A::count == 0);
112 assert(globalMemCounter.checkOutstandingNewEq(0));
113 assert(*f1.target<int(*)(int)>() == g);
114 assert(*f2.target<int(*)(int)>() == h);
116 assert(A::count == 0);
117 assert(globalMemCounter.checkOutstandingNewEq(0));
118 assert(*f1.target<int(*)(int)>() == h);
119 assert(*f2.target<int(*)(int)>() == g);
121 assert(A::count == 0);
122 assert(globalMemCounter.checkOutstandingNewEq(0));