Originally posted by lowflyer
View Post
The C++ version similar to the Rust one would look something like this:
Code:
auto process_stuff(const std::vector<float> & value, int index) -> float { return value.at(index); } [...] try { auto fut1 = std::async(process_stuff, vec, 7); auto fut2 = std::async(process_stuff, vec, 12); auto fut3 = std::async(process_stuff, vec, 3); print_result(fut1.get()); print_result(fut2.get()); print_result(fut3.get()); } catch (std::exception& e) { fmt::print("Error: {}\n", e.what()); }
It's not even really equivalent to the Rust version because even if exceptions propagated across threads, it still wouldn't really work because to my best knowledge, you can't write a try/catch block in C++ that would catch one error all the while letting the remaining threads finish.
To your credit, you implicitly acknowledged this by writing your tortuous imitation of the Result type to prove that it "can" be done in C++. There are of course many problems with that, among others the fact that with your solution you can only return strings containing error messages and not actual, structured errors (that would need more boilerplate), but it's an excellent example of the fanboyism I was deriding: you obviously don't care about engineering outcomes or code provability, you care about making a point about "your" language which seems to sit somewhere alongside your football club. For every problem in C++, anyone can of course devise a labyrinthine solution to work around it in one particular case. That doesn't constitute any merit though.
Comment