15 ms·
C++20 Is Feature Complete; Here’s What Changes Are Coming
- ilaksh 7y agoSounds amazing. Anyone have code examples that integrate a lot of the newer stuff? Dumb question. Why isn't omitting 'return' always an error in gcc rather than just a warning?
- plorkyeran 7y agoint foo() { bar(); } is a perfectly well-formed function as long as bar() never returns. Allowing this without requiring bar() to be annotated as noreturn is generally considered a mistake, but correcting it would break existing valid programs.
- ComputerGuru 7y agoC++17 already made backward compatibility a non-goal (within reason, obviously) and broke previously valid programs.
- ComputerGuru 7y agoI don’t care that my previous comment post has been downvoted, but I do want to clarify that I wasn’t being facetious; C++17 removes a number of old features and constructs that had been previously deprecated and there exist programs that compiled under C++14 that need non-trivial changes to compile under C++17.
- temac 7y ago> but correcting it would break existing valid programs That's very often the case when enhancing static safety guarantees. And that's often worth it.
- ahartmetz 7y agoIn any case, just add -Werror=return-type to your compiler flags... After I had forgotten a return once, that option saved me several times.
- Gibbon1 7y agoLikely answer is, doesn't really cause problems for anyone in practice. Experienced C++ programmers fix warnings. Also the ABI specifies how to call and get the return value of a function. The long and the short if it is the execution thread doesn't go off the rails if there is a mismatch in expected behavior. Your data may be garbage tho.
- DerekL 7y agoIt would be nice if the program would abort if a non-void function returns without a value. The only cost would be a slightly larger executable.
- Ididntdothis 7y agoLooks pretty good. But I don’t understand why they don’t do string interpolation like C# and others do. “I= {I}” Is much better and less error prone than “I= {}”, I Or am I missing something?
- _hardwaregeek 7y agoProbably some syntactical reason. If you allow arbitrary expressions inside string interpolation, you'd need to have some form of state in your lexer to figure out when to lex the characters into tokens or just keep them as raw characters. It's not so easy as looking for another brace, as you can have expressions that have braces (lambdas). Plus, string interpolation can then be nested, which you may not want.
- royjacobs 7y agoI don't think you'd be able to evaluate your expression without some kind of runtime reflection. Specifically, how is a standard library method supposed to interpolate {l}? It doesn't have any information about which variables are present in some kind of format string.
- Ididntdothis 7y agoI am pretty sure C# does the interpolation at compile time but it probably helps that it has a string type as first class citizen to the compiler has more information.
- plorkyeran 7y agoThe format library is a pre-existing library which is being standardized. String interpolation cannot be implemented in a library, and requires language extensions. Perhaps they should have done that instead, but that's a significantly more complicated task than merely adopting something that's already well tested and proven (and even that was far from trivial).
- hawski 7y agoI am not necessarily opposing string interpolation as a language feature, but I have an idea how could it work as a library. Implement string suffix and overload comma operator or overload reminder operator. It would look like this: "Hello {} {}!"i, 2, "worlds" Or with reminder operator as in Python: "Hello {} {}!"istr % istr(2, "worlds") But yeah, enough of this.
- gigatexal 7y agoI’m not a C++ dev. I took one class of it in college and even then it was 90% C and only hit pointers and classes on the final unit. But holy smokes this is not your grandmother’s C++, is it just me or is the language trying to be all things to all people? It’s getting too big, no? I mean how long do you have to be writing C++ code to fully master the language? Or can you be a high level dev without ever touching the new features? I’m assuming production codebases are likely still stuck on older versions of the language and might never move on. I hope golang doesn’t grow this large over time.
- sp332 7y agoOh yeah, C++ has been huge for decades. You pick a subset and program in that. The changes in C++11 had structural implications that took years to work through which is why it was late. The working name was C++0x because they expected to release it in '08 or maybe '09. http://www.stroustrup.com/C++11FAQ.html http://www.stroustrup.com/C++11FAQ.html
- empyrical 7y agoDespite the slight differences they have from the C99 version of them, I'm pretty happy to see designated initializers in C++20
- ncmncm 7y agoThis article might seem confusing. That's because it is. There is hardly a paragraph in it that is wholly correct, where they actually mean anything. C++ itself is much easier to understand than the article. The real purpose for all the constexpr-related apparatus, as well as much of Concepts, is to make it much rarer that anybody needs to do "template metaprogramming". Instead of writing Template Metaprograms to run at compile time (a very strange functional pattern-matching language practically nothing like C++) you can usually write ordinary C++ code. Coroutines are a new flow control primitive showing up in lots of languages lately. The C++ version is the same as the others. The main benefit you will see from Concepts is overwhelmingly better error messages when you misuse a library component, whether Standard or your own. Modules is a big step toward enabling a modern build infrastructure, as already seen in lots of newer languages that got benefit of hindsight. All the old stuff is still there, because billions of lines of old code still use it. You don't have to use it in new code, but it all still works. The biggest difference between old and new C++ code is that good new code uses value types more, and reference types less, making everything safer. Coding modern C++ is overwhelmingly more fun than coding C++98 was, but it is just as fast as ever, and better than ever for writing fast, powerful, nice-to-use, no-compromise libraries.
- hackandtrip 7y agoI got had to fight with template metaprogramming lately, and I can't be happier than reading about this. Do you have any sources when one can learn in a non-confusing way about this new stuff, especially Concepts?
- favorited 7y agoIf you're looking for a high-level example, the Wikipedia article one where a function is constrained to only accept an argument which implements operators "==" and "!=". https://en.wikipedia.org/wiki/Concepts_(C%2B%2B) https://en.wikipedia.org/wiki/Concepts_(C%2B%2B)
- hawski 7y agoI am C++ developer by career and I am pretty much bashing the language all the time. To preserve my sanity I like to use C in after-hours. However looking up C++20 and the direction whole language is going I see there are things I would really like to see in C, while preserving C simplicity. Standardized attributes like [[fallthrough]] and others for functions seem nice. Anonymous functions are nice. They look a bit ugly, but function pointers already look even worse. It would not hurt to have modules and consteval functions in C, but then one still needs templates to really ditch the preprocessor and that's a tough one to solve. Having said all that C++ is really in a need of a clean cut between legacy features and the blessed way. Backwards compatibility is a noble cause, but there is also the whole weight it pulls around. Maybe something like [[deprecated]] attribute could be extended to handle more cases. Maybe C++ needs it's own "unsafe" block, something like [[unsafe]] { *((void*)0) = 0xDEAD; } Essentially having an ability to clearly mark all those different styles of different versions of C++ really. So that compiler could help you to control it and in case of a green field project totally guide you to use only the most modern idioms with an escape hatch. Of course the problem is that to help with the complexity more complexity would have to be added. I am a bit on the crossroads. From one side I start to see, that there is some hope for C++. But on the other I feel like running away, especially since I'm looking for a job. In no particular order: C, Rust, Java, Kotlin, Scheme, Julia, Go, OCaml, Free Pascal, Swift, TypeScript, Lua/Terra, Zig. I had a funny thing with C++. One project I worked on was used in the debug version all the time, to be able to drop to debugger when needed. At that point I started to wonder why not just use Java already, instead of trying to do a manual Java and fail at it.
- lousken 7y agoI've had C++98 at school, but how would I learn C++17? Scott Meyers wrote C++14 but he retired from C++ development so what are the best alternatives?
- antisemiotic 7y agoChanges from c++14 to c++17 are nowhere near as dramatic as c++98 to c++11, so you can go with Scott Meyers and fill in the gaps from cppreference.com, for example.