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 #ifndef FUNCTION_TYPES_H
10 #define FUNCTION_TYPES_H
11 
12 
13 class FunctionObject
14 {
15     int data_[10]; // dummy variable to prevent small object optimization in
16                    // std::function
17 public:
18     static int count;
19 
FunctionObject()20     FunctionObject() {
21         ++count;
22         for (int i = 0; i < 10; ++i) data_[i] = i;
23     }
24 
FunctionObject(const FunctionObject &)25     FunctionObject(const FunctionObject&) {++count;}
~FunctionObject()26     ~FunctionObject() {--count; ((void)data_); }
27 
operator()28     int operator()() const { return 42; }
operator()29     int operator()(int i) const { return i; }
operator()30     int operator()(int i, int) const { return i; }
operator()31     int operator()(int i, int, int) const { return i; }
32 };
33 
34 int FunctionObject::count = 0;
35 
36 class MemFunClass
37 {
38     int data_[10]; // dummy variable to prevent small object optimization in
39                    // std::function
40 public:
41     static int count;
42 
MemFunClass()43     MemFunClass() {
44         ++count;
45         for (int i = 0; i < 10; ++i) data_[i] = 0;
46     }
47 
MemFunClass(const MemFunClass &)48     MemFunClass(const MemFunClass&) {++count; ((void)data_); }
49 
~MemFunClass()50     ~MemFunClass() {--count;}
51 
foo()52     int foo() const { return 42; }
foo(int i)53     int foo(int i) const { return i; }
foo(int i,int)54     int foo(int i, int) const { return i; }
foo(int i,int,int)55     int foo(int i, int, int) const { return i; }
56 };
57 
58 int MemFunClass::count = 0;
59 
FreeFunction()60 int FreeFunction() { return 42; }
FreeFunction(int i)61 int FreeFunction(int i) {return i;}
FreeFunction(int i,int)62 int FreeFunction(int i, int) { return i; }
FreeFunction(int i,int,int)63 int FreeFunction(int i, int, int) { return i; }
64 
65 #endif // FUNCTION_TYPES_H
66