blob: e9ecfa5539ce525f59b36e5c6620314867dc37b0 [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// <functional>
11
12// class function<R(ArgTypes...)>
13
14// template<class F, class A> void assign(F&&, const A&);
15
16#include <functional>
17#include <cassert>
18
Marshall Clow1b921882013-12-03 00:18:10 +000019#include "test_allocator.h"
Howard Hinnant72552802010-08-20 19:36:46 +000020
21class A
22{
23 int data_[10];
24public:
25 static int count;
26
27 A()
28 {
29 ++count;
30 for (int i = 0; i < 10; ++i)
31 data_[i] = i;
32 }
33
34 A(const A&) {++count;}
35
36 ~A() {--count;}
37
38 int operator()(int i) const
39 {
40 for (int j = 0; j < 10; ++j)
41 i += data_[j];
42 return i;
43 }
44
45 int foo(int) const {return 1;}
46};
47
48int A::count = 0;
49
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000050int main()
51{
Howard Hinnant72552802010-08-20 19:36:46 +000052 {
53 std::function<int(int)> f;
54 f.assign(A(), test_allocator<A>());
55 assert(A::count == 1);
56 assert(f.target<A>());
57 assert(f.target<int(*)(int)>() == 0);
58 }
59 assert(A::count == 0);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000060}