1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 // <functional>
10 
11 // class function<R(ArgTypes...)>
12 
13 // const std::type_info& target_type() const;
14 
15 #include <functional>
16 #include <typeinfo>
17 #include <cassert>
18 
19 #include "test_macros.h"
20 
21 class A
22 {
23     int data_[10];
24 public:
25     static int count;
26 
A()27     A()
28     {
29         ++count;
30         for (int i = 0; i < 10; ++i)
31             data_[i] = i;
32     }
33 
A(const A &)34     A(const A&) {++count;}
35 
~A()36     ~A() {--count;}
37 
operator ()(int i) const38     int operator()(int i) const
39     {
40         for (int j = 0; j < 10; ++j)
41             i += data_[j];
42         return i;
43     }
44 
foo(int) const45     int foo(int) const {return 1;}
46 };
47 
48 int A::count = 0;
49 
g(int)50 int g(int) {return 0;}
51 
main(int,char **)52 int main(int, char**)
53 {
54     {
55     std::function<int(int)> f = A();
56     assert(f.target_type() == typeid(A));
57     }
58     {
59     std::function<int(int)> f;
60     assert(f.target_type() == typeid(void));
61     }
62 
63   return 0;
64 }
65