13 ms·
C++17 is formally approved
- humanrebar 9y agoHere's a good rundown of all the changes in C++17: https://stackoverflow.com/questions/38060436/what-are-the-new-features-in-c17/38060437#38060437 https://stackoverflow.com/questions/38060436/what-are-the-ne...
- sddfd 9y agoYou may want to change the link to https://stackoverflow.com/questions/38060436/what-are-the-new-features-in-c17/38060437#38060437 https://stackoverflow.com/questions/38060436/what-are-the-ne...
- humanrebar 9y agoDone. Thanks!
- problems 9y agoDid modules/import not make the final revision? I was quite looking forward to that feature.
- bstamour 9y agoNope, but they are in the pipe. Maybe we'll see them for C++20.
- zelos 9y agoThere are some nice things in there, but the destructuring looks a bit odd: struct S { int x1 : 2; volatile double y1; }; S f(); const auto [ x, y ] = f(); So it's just ordering based, I can't pull out one member by name?
- m-ou-se 9y agoC++ already had syntax for pulling out one member by name: ;) const auto x = f().x1;
- faitswulff 9y agoI'm not sure what the wink means, but I think gp might be talking about destructuring like what you'd find in Javascript: > const {a, b} = {a: 'hey', b: 'there'} undefined > a 'hey' > b 'there'
- jcelerier 9y agoit has to work with unnamed tuples: const auto [ x, y ] = make_tuple(1, 23);
- dvlsg 9y agoTuples are ordered though. I don't usually think of structs by the order the properties are declared - I usually think of them by name. I am, admittedly, not primarily a c++ dev though. Are structs typically ordered data structures in c++?
- 21 9y agoThere is no struct here. x will be an independent variable which will take the first value from the tuple, and y the second one.
- euyyn 9y agoHis point is that it makes sense to destructure in order for tuples, but what makes sense for structs is destructuring by field name.
- jcelerier 9y ago> Tuples are ordered though. I don't usually think of structs by the order the properties are declared - I usually think of them by name. Think for instance of a 2D point structure. There are tons of implementations, all with different naming conventions ; or sometimes storing them in an array. This allows to just do : auto [x, y] = someRandomLibraryPoint();
- everheardofc 9y agoC++ shows that in theory you can fix any flaw in an existing programming language as long as you maintain backwards compatibility by simply adding more features. The only thing you cannot change are implicit defaults (e.g. pass by value is the default, you have to manually opt out to pointers or references). I like modern C++ because for me it's a reasonable compromise between java safety and C safety. Other than out of bounds memory accesses and legacy code I feel there is not much that can go wrong. However compiling C++ projects takes ages and in the projects I've worked on I often have to modify headers that are included almost everywhere. Every trivial changes requires a 5 minute rebuild. After working with several high level programming languages with slow compilers I realised the following: typing is fast, compiling is slow. There is a reason why go is so popular. It offers that tradeoff in fast turn around time / compilation time with reasonably good performance and simplicity in exchange for more keyboard bashing and keyboard bashing is a cheap price to pay for what you're getting back.
- flavio81 9y ago>C++ shows that in theory you can fix any flaw in an existing programming language as long as you maintain backwards compatibility by simply adding more features. Well, "adding more features" can't be done "simply" if you want to "maintain backwards compatibility"; indeed, in the process of doing this is that the "flaws" are potentially augmented.
- pjmlp 9y agoThey also have removed features that were deprecated in C++11 and C++14.
- humanrebar 9y agoYes! These are underrated items on the change list. Establishing precedents and habits for removing harmful things (like trigraphs) is very important to the future of the language.
- gcp 9y agoThere's some funny ones there. std::random_shuffle because it relies on rand() which may be bad, but ironically most (all?) the rng's that are in the standard library would be considered "bad" by modern standards.
- tcbawo 9y agoScanning through the list of features, one I dislike is selection statement initializers: if (init; condition) {} (Ref: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0305r1.html http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p030...). It just seems like clutter. I generally prefer when languages discourage side effects in a branch condition.
- BudVVeezer 9y agoIt's consistent with for (init; condition;) {} and solves a problem like: if (std::vector<int> v = f(); !v.empty()) { // Use v } without requiring an extra compound statement to limit the scope and lifetime of v.
- tcbawo 9y agoI agree that it's consistent, I find it easier to read when the branching condition is front and center. In 99% of cases I've encountered, the scope of the branching condition variable doesn't matter. When it does, an extra set of {} defines a scope clearly.
- leni536 9y agoAn extra set of {} seems to be clutter to me.
- lomnakkus 9y agoThat plus extra indentation. It also obscures the intent since it's not necessarily unambiguous why those braces are there? Is it just to group logically related code (without putting it in a separate method/function) or is it because you're relying on RAII -- it's only possible to tell by searching for destructors on all the classes you're instantiating.
- jacobparker 9y agoThat's sorta the point... the init isn't the branch condition. It gives terser syntax to a common patter where you want to scope something into the body of an if statement. { std::unique_ptr<T> x = foo(); if(x->something()) { // use x } } // x out of scope, destructed becomes if(auto x = foo(); x->something()) { // use x } // x out of scope, destructed It's makes it easier to read the lifetime of x (an important thing you have to manually keep an eye on in C++ in many cases), and to determine what is in scope outside of the if statement. It's analogous to for-loops vs. doing loops "manually" with while. You're just used to for-loops by this point (if you don't like for loops then ok :).) C# is also getting (has got?) this feature.
- ericfrederich 9y agoDoes it have coroutines? Python has had them since 2.5 (2005) and Golang has obviously had them since the beginning. When will C++ finally catch up?
- Sharlin 9y agoCatch up? Everyone has their favorite feature; I could ask you when Python is going to catch up with C++ on static typing, or when Go is going to catch up with C++ on generics. Anyway, Go goroutines and Python generators are very different beasts. Because the term "coroutine" can refer to very different things, implementing any single interpretation of the term would likely leave proponents of other interpretations disappointed. Coroutine support for C++ has been in progress for several years now, and some fundamental design questions have been quite controversial. However, there's now a Technical Specification out [0] and, if all goes well, it should be on track for inclusion in the C++20 standard. [0] http://open-std.org/JTC1/SC22/WG21/docs/papers/2017/n4680.pdf http://open-std.org/JTC1/SC22/WG21/docs/papers/2017/n4680.pd...
- adgasf 9y agoThis is a strange comment. Co-routines in C++ will be very different to co-routines in a VM language.
- pjmlp 9y agoActually co-routines in Kotlin and Scheme are quite similar to C++ idea.
- deleted 9y ago[deleted]
- pjmlp 9y agoWhen will Python finally get rid of the GIL and offer AOT compilation to native code?
- jacobush 9y agoTo be fair, none of these would be part of a language specification, only a specific implementation.
- rb808 9y agoSo I used C++ a long time ago but moved to Java/dotnet/python platforms. I do miss some low level stuff but not random crashes. Is there a reason to use C++ any more? Has anyone gone back and had good experience? I'd kinda like to but am wary of the old problems. (The other problem is that most interesting business logic is no longer in C++.)
- hellofunk 9y agoC++11 changed the language significantly and for the better, and each subsequent version has taken it further in the right direction. You can now use C++ as a high-level tool without much or any concern for manual memory management, and can do a lot of functional-style programming very easily and nicely. C++17 in particular adds features that bring the syntax closer to modern high-level languages almost to the degree that it feels like a scripting language at times. Stuff like automatic destructuring, variable definitions scoped for all branches of conditionals, etc. It's really one of my favorite languages, though this year I'm not getting to use it as much.
- futurix 9y agoIf you had 'random crashes', you probably weren't that good with C++ ...
- kensai 9y agoIt's very nice to hear progress on the C++ all the time. On the other hand, I cannot find any news on the C2x progress, as if C did not evolve.
- doldge 9y agoSo I'd like to learn more about modern C++ and how to write it, but I'm not really sure where to begin. I've tried a couple of times, but coming from a C background, my code tends towards C styling with only the occasional use of C++ features. Is anyone aware of a good tutorial or reference list for writing good modern C++ (C++11 or newer, I guess)?
- lorenzhs 9y agoI really enjoyed "Efficient Modern C++". I'd describe it as a good overview of new features in C++11 and 14, how to use them, and how they fit together, but I'm not sure whether it makes for a good "C++ for C programmers" book.
- deleted 9y ago[deleted]
- pveierland 9y agoThe following is a readable and modern FAQ which describes most language features: https://isocpp.org/faq https://isocpp.org/faq My preferred reference for the language and standard library: http://en.cppreference.com/w/ http://en.cppreference.com/w/ The following is a longer guide on modern C++ style: https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md https://github.com/isocpp/CppCoreGuidelines/blob/master/CppC...
- Veratyr 9y agoAs a newcomer to C++ myself, I found Stanley Lippman's C++ primer to be helpful. The latest edition includes the newer features. And in case it helps, the main things I find myself using differently to C are: - Smart pointers. If you're not using them, use them. They're amazing. Seriously. Never have to worry about freeing something ever again. - Object oriented design. - Const reference arguments. - The occasional auto.
- twoodfin 9y agoI'd add RAII to this list. Also, I find simple template functions to work as an incredibly powerful macro system.
- gumby 9y agoI really hope I can soon replace add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-std=c++1z>) with set (CMAKE_CXX_STANDARD 17) Note: we had a green field application that started with an empty Emacs buffer so figured we could go straight to C++17. I doubt this is a particularly common case right now.
- copx 9y agoDoes anyone know the status of UFCS? I know it's not in C++17, will it be in C++20?