Files
swift-mirror/test/Interop/Cxx/stdlib/Inputs/std-function.h
Egor Zhdan d7212ff7f5 [cxx-interop] Add one more test for std::function
While initializing a `std::function` that takes `const std::string&` as a parameter currently crashes, changing the parameter type to `std::string` should work fine.
2024-07-22 13:54:09 +01:00

28 lines
850 B
C++

#ifndef TEST_INTEROP_CXX_STDLIB_INPUTS_STD_FUNCTION_H
#define TEST_INTEROP_CXX_STDLIB_INPUTS_STD_FUNCTION_H
#include <functional>
#include <string>
using FunctionIntToInt = std::function<int(int)>;
using FunctionStringToString = std::function<std::string(std::string)>;
using FunctionStringToStringConstRef = std::function<std::string(const std::string&)>;
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); }
std::string invokeFunctionTwice(FunctionStringToString f, std::string s) {
return f(f(s));
}
std::string invokeFunctionTwiceConstRef(FunctionStringToStringConstRef f, std::string s) {
return f(f(s));
}
#endif // TEST_INTEROP_CXX_STDLIB_INPUTS_STD_FUNCTION_H