5 ms·
This is becoming such a tiresome opinion. How are concepts fixing a problem created by previous features to the langue? What about ranges? Auto? Move semantics?
by blux 2y ago
This is becoming such a tiresome opinion. How are concepts fixing a problem created by previous features to the langue? What about ranges? Auto? Move semantics? Coroutines? Constexpr? Consteval? It is time for this narrative to stop.
- bicarbonato 2y ago> How are concepts fixing a problem created by previous features to the langue? Concepts fix implicit template requirements > What about ranges? Fix the bad iterators > Auto Fix the the overly long type names > Move semantics This is mostly necessary because of excessive copies that cpp does > Consteval Fix cases where constexpr couldn't do it at comptime
- nialv7 2y agoHonestly can't tell if this is sarcasm. XD
- nurettin 2y agoI thought the whole point of ranges is to solve problems created by iterators, move semantics to take care of scenarios where nrvo doesn't apply, constexpr and auto because we were hacking around it with macros (if you can even call it that)?
- gpderetta 2y agoIteratively improving in previously released features does not imply fixing issues caused by those features. Constexpr and auto have nothing to do with macros.
- nurettin 2y agoTo me, redoing things that are not orthogonal implies that the older version is being fixed. Being fixed implies that it was incorrect. And to clarify, sure, auto types and constexpr are entirely new things we didn't have (auto changed meaning but yeah), but we were trying to "get something like that" using macros.
- gpderetta 2y ago> To me, redoing things that are not orthogonal implies that the older version is being fixed The older version is being improved, especially for ergonomics. Regarding your examples, ranges do not obsolete iterators, they are just a convenient way to pass around iterator pairs, but actual range are better implemented in terms of iterators when they are not just a composition of ranges. Similarly move semantics has little to do with nrvo (and in fact using move often is suboptimal as it inhibits nrvo). Again, I have no idea how constexpr and auto have anything to do with macros.
- kringlezz 2y agoMove semantics is only needed because C++ introduced implicit copies (copy constructor) and they of course fucked it up my making them non-destructive so they aren't even 'zero cost'. Constexpr and consteval are hacks that 1) should have just been the default, and 2) shouldn't even be on the function definition, it should instead have been a keyword on the usage site: (and just use const) int f() { ... } // any old regular function const int x = f(); // this is always get evaluated at compile time, (or if it can't, then fail to compile) int y = f(); // this is evaulated at runtime That would be the sane way to do compile time functions.
- serbuvlad 2y agoEh not really accurate because C's const means immutable not actually constant. So I get introducing constexpr to actually mean constant. But, yeah, constexpr x = f() should probably have worked as you described.
- jlokier 2y agoconst is different in C++ from const in C. const variables in C++ are proper compile-time constants. In C they are not (the nearest equivalents are #define and enum values). So in C++ "const x = EXPR" would make sense to request compile-time evaluation, but in C it wouldn't.
- OskarS 2y agoThey absolutely are not. Look at this range for-loop: for (const auto item: vec) { ... } `item` is not a compile-time constant. It's different every run of the loop.
- jlokier 2y agoOuch, but thanks. I learned something today - something I'd long forgotten. I like your example, it shows the point well. (Though, there are circumstances when a compiler can unroll such a loop and infer a compile-time constant, it wouldn't qualify as a constant expression at the language level.) It's been so long since I used C++ for serious work that we weren't using C++11, so neither auto nor range-for were available. It would be uncommon to see "const type = " with a non-reference type and a non-constant initialiser. Even with your example, some styles avoid "const auto item", using either "auto item" or "const auto& item" instead, because the "const" matters when taking a reference, not so much with a copy. But I appreciate your point applies to const variables with non-constant initialisers in general, in the language. There was once a big deal in literature about const in C++ being the "better" alternative to how #define is commonly used with C for constant values, and it seemed applicable to the thread as a key distinction between C and C++, which the parent commenter seemed to have conflated by mistake. But I'd forgotten about const (non-reference) variables accepting non-constant initialisers, and as I hadn't used C++ seriously in a while, and the language is always changing, I checked in with a couple of C++ tutorials before writing. Unfortunately those tutorials were misleading or too simple, as both tutoruals said nothing about "const type x = " (non-reference/pointer) being uwed in any other way than for defining compile-time constants. It's bit embarrssing, as I read other parts of the C++ standard quite often despite not using it much these days. (I'm into compiler guts, atomics, memory models, code analysis, portability issues, etc.). Yet I had forgotten this part of the language. So, thanks for sending me down a learning & reminder rabbit-hole and correcting my error :-)
- TheRealPomax 2y agoIt might be getting tiresome because it keeps being true, so people keep pointing it out.
- groby_b 2y agoauto is fixing the problem of long-ass type names for intermediaries thanks to templates and iterators. Move is fixing the problem of unnecessary mass-construction when you pass around containers. std::ranges was introduced because dear fucking god the syntax for iterating over a partial container. (And the endless off-by-one errors) concepts, among other things, fix (sorta) the utter shit show that templates brought to error messages, as well as debacles like SFINAE and std::enable_if. You're right. They're not fixing problems created by previous features. They're all fixing problems created or made massively worse by templates.