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 // <functional>
11 
12 // class function<R(ArgTypes...)>
13 
14 // const std::type_info& target_type() const;
15 
16 #include <functional>
17 #include <typeinfo>
18 #include <cassert>
19 
20 class A
21 {
22     int data_[10];
23 public:
24     static int count;
25 
A()26     A()
27     {
28         ++count;
29         for (int i = 0; i < 10; ++i)
30             data_[i] = i;
31     }
32 
A(const A &)33     A(const A&) {++count;}
34 
~A()35     ~A() {--count;}
36 
operator ()(int i) const37     int operator()(int i) const
38     {
39         for (int j = 0; j < 10; ++j)
40             i += data_[j];
41         return i;
42     }
43 
foo(int) const44     int foo(int) const {return 1;}
45 };
46 
47 int A::count = 0;
48 
g(int)49 int g(int) {return 0;}
50 
main()51 int main()
52 {
53     {
54     std::function<int(int)> f = A();
55     assert(f.target_type() == typeid(A));
56     }
57     {
58     std::function<int(int)> f;
59     assert(f.target_type() == typeid(void));
60     }
61 }
62