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