mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
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.
28 lines
850 B
C++
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
|