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<class A> function(allocator_arg_t, const A&, const function&);
21 #include "test_allocator.h"
25 void* operator new(std::size_t s) throw(std::bad_alloc)
28 return std::malloc(s);
31 void operator delete(void* p) throw()
46 for (int i = 0; i < 10; ++i)
50 A(const A&) {++count;}
54 int operator()(int i) const
56 for (int j = 0; j < 10; ++j)
64 int g(int) {return 0;}
68 assert(new_called == 0);
70 std::function<int(int)> f = A();
71 assert(A::count == 1);
72 assert(new_called == 1);
73 assert(f.target<A>());
74 assert(f.target<int(*)(int)>() == 0);
75 std::function<int(int)> f2(std::allocator_arg, test_allocator<A>(), f);
76 assert(A::count == 2);
77 assert(new_called == 2);
78 assert(f2.target<A>());
79 assert(f2.target<int(*)(int)>() == 0);
81 assert(A::count == 0);
82 assert(new_called == 0);
84 std::function<int(int)> f = g;
85 assert(new_called == 0);
86 assert(f.target<int(*)(int)>());
87 assert(f.target<A>() == 0);
88 std::function<int(int)> f2(std::allocator_arg, test_allocator<int(*)(int)>(), f);
89 assert(new_called == 0);
90 assert(f2.target<int(*)(int)>());
91 assert(f2.target<A>() == 0);
93 assert(new_called == 0);
95 assert(new_called == 0);
96 non_default_test_allocator<std::function<int(int)>> al(1);
97 std::function<int(int)> f2(std::allocator_arg, al, g);
98 assert(new_called == 0);
99 assert(f2.target<int(*)(int)>());
100 assert(f2.target<A>() == 0);
102 assert(new_called == 0);
104 std::function<int(int)> f;
105 assert(new_called == 0);
106 assert(f.target<int(*)(int)>() == 0);
107 assert(f.target<A>() == 0);
108 std::function<int(int)> f2(std::allocator_arg, test_allocator<int>(), f);
109 assert(new_called == 0);
110 assert(f2.target<int(*)(int)>() == 0);
111 assert(f2.target<A>() == 0);