|
| [deleted]
| pbsd wrote:
| You can also achieve the fix using the arguably more natural
| template T const& clamp(T const& v, T const&
| lo, T const& hi) { T const& a = v < lo ? lo : v;
| T const& b = a > hi ? hi : a; return b; }
|
| Either way, the commitee's idea of returning references for the
| C++ max/min/clamp functions was terrible, and it's a constant
| source of problems with temporaries and such. Like this:
| https://godbolt.org/z/j593Mebd6
| secondcoming wrote:
| But it's not unreasonable for a programmer to expect no
| temporaries in code that just uses references.
|
| The rules are too complex, some of this is down to the language
| itself and some is the fault of compiler writers.
|
| I find myself using Compiler Explorer more and more for short
| code snippets to (obviously) see what the compiler is doing
| because I don't really trust my intuition that much any more.
| And the annoying thing is that clang and gcc can differ wildly
| in their codegen.
|
| I don't think anyone can call themselves a C++, or possibly
| Rust, programmer unless they can also understand assembly code.
| Just getting code to compile isn't enough. It seems like a step
| backwards to me.
| jeffbee wrote:
| "LLVM is so cool because it can be used to solve problems it also
| caused" is a weird vibe. GCC w/ libstdc++ doesn't have the issue.
| wyldfire wrote:
| _shrug_ , both projects have bugs. This is an interesting
| article and I didn't quite read it the same way you had.
| jeffbee wrote:
| True. Was just my reaction to the last line of the article. I
| would have chosen "fragile" over "versatile".
| [deleted]
___________________________________________________________________
(page generated 2021-04-09 23:00 UTC) |