2 ms·
Rvalue references et al are a valuable addition to the language if you're trying to avoid gratuitous copying. The performant alternative is a messy variety of f
by jprete 2y ago
Rvalue references et al are a valuable addition to the language if you're trying to avoid gratuitous copying. The performant alternative is a messy variety of functions that have the same effect as move semantics, except with ad hoc (or no!) compile-time checking. Using them correctly does requires a lot more background knowledge and conscious decision-making from the user than the rest of the language.
Templates are not that bad as a user, but as a template author, they're a completely different programming language that makes it much harder to express even simple ideas. (Concepts may have changed that, but I haven't had a chance to use them.)
- whiterknight 2y agoThe solution for move semantics before was specializing the swap function for container types. This was a much more pragmatic approach
- fsloth 2y ago”Templates are not that bad as a user” My take would be they are bad for both users and authors. In 2024 the expected compiler output for a syntax error in a statically typed language is a specific-as-possible report where in the written source the syntax fails - not 40 lines of illegible template error messages. There are some cases where templates are the best design option. But they should be used only as the last resort when it’s obvious that’s the best way.
- pjmlp 2y agoIn 2024, I expect people implementing templates making use of concepts, and if not possible, at very least static_assert alongside enable_if. Naturally reality often times doesn't match expectations.