3 ms·
> Rust code, on the other hand, often doesn't look much more elaborate than code I write in much higher level languages I'm curious to see an example. Could yo
by HarHarVeryFunny 4y ago
> Rust code, on the other hand, often doesn't look much more elaborate than code I write in much higher level languages
I'm curious to see an example. Could you show something written in Rust, or another "much higher level language" that you think would be messier or more difficult to write in C++ ?
- emilern 4y agoThe enum example in the article
- HarHarVeryFunny 4y agoOK, that's an interesting language feature, but I can't say it's something that I've often wanted to do in C++. Of course C++ does have std::variant and std::any, although I'm not really a fan. I'd tend to (and have) just use a class that contains the variants and an enum to track which one, then setters and getters. event.SetKeyPress(ch); event.SetMouseButtonPress(pos, but); etc ... switch (event.type) { case EvKeyPress: ch = event.GetKeyPress();
- HarHarVeryFunny 4y agoOf course the Rust features being used by that Event type are runtime polymorphism and type introspection, so another obvious C++ approach would be just to use a pointer to a virtual based class including the type, then: switch (event->type) { case EvKeyPressEvent: { auto kpe - dynamic_cast<KeyPressEvent*>(event) ... } break; }