When compiling managed C++ code with the /clr flag, the compiler does not allow the include. I am trying to port my unmanaged C++ code into a managed C++ environment. I see that C# has the alternatives Task and TaskCompletionSource to replace futures and promises but I do not see these options available in managed C++. I need to perform interop with some C++ unmanaged libraries so I cannot switch to C# completely. I still need a C++ layer in between. How can I achieve future/promise functionality in managed C++?
Here is an example of unmanaged code in C++ which compiles without the /clr flag:
int Foo(std::future<int> &fur) {
int result = 1;
int value = fut.get();
// Do something with value
return result;
}
int main() {
int x;
std::promise<int> p;
std::future<int> f = p.get_future();
std::future<int> fut = std::async(Foo, std::ref(f));
int val = 1;
p.set_value(val);
x = fut.get();
}
I want to be able to do this in C++/CLI