#ifndef TEST_INTEROP_CXX_STDLIB_INPUTS_STD_FUNCTION_H #define TEST_INTEROP_CXX_STDLIB_INPUTS_STD_FUNCTION_H #include #include using FunctionVoidToVoid = std::function; using FunctionVoidToInt = std::function; using FunctionIntToVoid = std::function; using FunctionIntToInt = std::function; using FunctionConstIntToInt = std::function; using FunctionConstRefIntToInt = std::function; using FunctionIntIntToInt = std::function; using FunctionStringToString = std::function; using FunctionConstRefStringToString = std::function; using FunctionConstRefStringToConstRefString = std::function; struct HasDeletedCopyCtor { int value; HasDeletedCopyCtor(int value) : value(value) {} HasDeletedCopyCtor(const HasDeletedCopyCtor &other) = delete; HasDeletedCopyCtor(HasDeletedCopyCtor &&other) = default; HasDeletedCopyCtor& operator=(const HasDeletedCopyCtor &other) = delete; HasDeletedCopyCtor& operator=(HasDeletedCopyCtor &&other) = default; ~HasDeletedCopyCtor() = default; }; using FunctionIntToHasDeletedCopyCtor = std::function; using FunctionConstRefHasDeletedCopyCtorToVoid = std::function; using FunctionConstRefHasDeletedCopyCtorToInt = std::function; using FunctionHasDeletedCopyCtor = std::function; int invokeFunctionConstRefHasDeletedCopyCtorToInt(FunctionConstRefHasDeletedCopyCtorToInt f) { HasDeletedCopyCtor arg(123); return f(arg); } struct NonTrivialHasDeletedCopyCtor { int value; bool destroyed = false; NonTrivialHasDeletedCopyCtor(int value) : value(value) {} NonTrivialHasDeletedCopyCtor(const NonTrivialHasDeletedCopyCtor &other) = delete; NonTrivialHasDeletedCopyCtor(NonTrivialHasDeletedCopyCtor &&other) = default; NonTrivialHasDeletedCopyCtor& operator=(const NonTrivialHasDeletedCopyCtor &other) = delete; NonTrivialHasDeletedCopyCtor& operator=(NonTrivialHasDeletedCopyCtor &&other) = default; ~NonTrivialHasDeletedCopyCtor() { destroyed = true; } // makes the type non-trivial }; using FunctionIntToNonTrivialHasDeletedCopyCtor = std::function; using FunctionConstRefNonTrivialHasDeletedCopyCtorToVoid = std::function; using FunctionNonTrivialHasDeletedCopyCtor = std::function; inline FunctionIntToInt getIdentityFunction() { return [](int x) { return x; }; } inline bool isEmptyFunction(FunctionIntToInt f) { return !(bool)f; } inline int invokeFunction(FunctionIntToInt f, int x) { return f(x); } int invokeFunctionIntToIntTwice(FunctionIntToInt f, int i) { return f(f(i)); } int invokeFunctionIntToIntByConstRefTwice(const FunctionIntToInt& f, int i) { return f(f(i)); } int invokeFunctionIntToIntByRValueRefTwice(const FunctionIntToInt& f, int i) { return f(f(i)); } std::string invokeFunctionTwice(FunctionStringToString f, std::string s) { return f(f(s)); } std::string invokeFunctionByConstRefTwice(const FunctionStringToString& f, std::string s) { return f(f(s)); } std::string invokeFunctionTwiceConstRef(FunctionConstRefStringToString f, std::string s) { return f(f(s)); } std::string invokeFunctionTwiceConstRefX2(FunctionConstRefStringToConstRefString f, std::string s) { return f(f(s)); } template int invokeTemplatedCallableIntToInt(Func f) { return f(123); }; template int invokeTemplatedCallableByConstRefIntToInt(const Func& f) { return f(321); }; #endif // TEST_INTEROP_CXX_STDLIB_INPUTS_STD_FUNCTION_H