target_type.pass.cpp revision f5256e16dfc425c1d466f6308d4026d529ce9e0b
1//===----------------------------------------------------------------------===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. 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
20class A
21{
22    int data_[10];
23public:
24    static int count;
25
26    A()
27    {
28        ++count;
29        for (int i = 0; i < 10; ++i)
30            data_[i] = i;
31    }
32
33    A(const A&) {++count;}
34
35    ~A() {--count;}
36
37    int operator()(int i) const
38    {
39        for (int j = 0; j < 10; ++j)
40            i += data_[j];
41        return i;
42    }
43
44    int foo(int) const {return 1;}
45};
46
47int A::count = 0;
48
49int g(int) {return 0;}
50
51int 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