aboutsummaryrefslogtreecommitdiff
path: root/test/std/utilities/function.objects/func.wrap/func.wrap.func/function_types.h
blob: f1526544bcfe9f34602ee69722a0f8a7018164e0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
//===----------------------------------------------------------------------===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

#ifndef FUNCTION_TYPES_H
#define FUNCTION_TYPES_H


class FunctionObject
{
    int data_[10]; // dummy variable to prevent small object optimization in
                   // std::function
public:
    static int count;

    FunctionObject() {
        ++count;
        for (int i = 0; i < 10; ++i) data_[i] = i;
    }

    FunctionObject(const FunctionObject&) {++count;}
    ~FunctionObject() {--count; ((void)data_); }

    int operator()() const { return 42; }
    int operator()(int i) const { return i; }
    int operator()(int i, int) const { return i; }
    int operator()(int i, int, int) const { return i; }
};

int FunctionObject::count = 0;

class MemFunClass
{
    int data_[10]; // dummy variable to prevent small object optimization in
                   // std::function
public:
    static int count;

    MemFunClass() {
        ++count;
        for (int i = 0; i < 10; ++i) data_[i] = 0;
    }

    MemFunClass(const MemFunClass&) {++count; ((void)data_); }

    ~MemFunClass() {--count;}

    int foo() const { return 42; }
    int foo(int i) const { return i; }
    int foo(int i, int) const { return i; }
    int foo(int i, int, int) const { return i; }
};

int MemFunClass::count = 0;

int FreeFunction() { return 42; }
int FreeFunction(int i) {return i;}
int FreeFunction(int i, int) { return i; }
int FreeFunction(int i, int, int) { return i; }

#endif // FUNCTION_TYPES_H