8 ms·
What's new in C++26 (part 1)
- roenxi 2y agoLeading with "Specifying a reason for deleting a function" then following up with "Placeholder variables with no name" did make me check the date of the article. It wasn't April 1. The standards committee are thorough in their mission to including everything and the kitchen sink in C++.
- omnicognate 2y agoC++ has certainly had a lot added, but I don't get your point regarding these particular two features. They seem quite minor, useful, easily implemented and unlikely to interact problematically with other things.
- einpoklum 2y ago"Placeholder variable with no name" is the super-common feature from other language where you write, for example (not exact real syntax): (foo, _, bar) = function_returning_a_triplet(); since you only want the first and third items; the underscore is the placeholder. Useful feature, convenient feature, doesn't complicate your life as a programmer, no need to even remember it, it'll just come to you. Good thing to have in the language IMNSHO.
- giancarlostoro 2y agoSome of those features look like features I've been seeing in all major languages I use. They're mostly ergonomic for the developer.
- bun_terminator 2y ago.
- beached_whale 2y agosure about that? It does, happen to, work on libstdc++/libc++/MS STL but it's not specified to work anywhere but std::tie. The existing practice is to cast to void.
- alexvitkov 2y agocan you show an example how? I can't find a case where std::ignore compiles inside a structured binding declaration. https://godbolt.org/z/sjefeGvPf https://godbolt.org/z/sjefeGvPf https://godbolt.org/z/8a7Ps4KdW https://godbolt.org/z/8a7Ps4KdW
- beached_whale 2y agoit will work for assignment/ construction, but isn't part of std c++ is what i mean. at least not yet. structured binding wont, but in the future c++ 26, _ should work there and other places
- alexvitkov 2y agostd::ignore doesn't work in the context of structured bindings. And even if it did, "we already have this" has never stopped the C++ committee from adding something before :)
- ReleaseCandidat 2y agoYes, the "skill" of the commitee to discuss some feature for a really looooooong time and then come up with a solution which is going to be (half) fixed in the next standard always astonishes mé :). I guess with C++38 we'll get a `always_definetly_ignore_this_wothout_any_diagnostic_whatsoever`.
- ReleaseCandidat 2y agoNo, that's why `maybe_unused` has been needed.
- dundarious 2y agoIf you replace your whole comment with ".", I'm just going to automatically down vote it, so the effect is worse than whatever was originally there. These kinds of "masking" edits prevent good communication. If you want us all to disregard a comment you now totally disown, then just write an edit that prepends/appends that.
- layer8 2y agoMaybe they are fine with being downvoted and just want to prevent readers wasting any further time with their comment.
- dundarious 2y agoWriting that in an edit is completely valid -- we're grown up enough to weigh whether to bother reading the comment then. Replacing the whole thing with just "." is not acceptable, IMO. If they're fine with accepting the down votes either way, I still want to register my complaint, pointless as it may be in practice.
- layer8 2y agoIt's perfectly okay that you downvote, as that supports the goal of demoting the comment. (The effects of up/downvoting on comment ranking trumps the effect on the author's karma, IMO.) However I don't agree that pseudo-deleting is unacceptable, if for example it contained an incorrect argument and the author thinks there is no value anymore in someone reading it.
- dundarious 2y agoSo they presumably think they were fully wrong. Wrong about what? It's often useful to know about mistaken assumptions, etc. Now all the "corrections" in the replies are harder to comprehend. Everybody's work is devalued and made harder as a result of the pseudo-delete.
- 2y ago
- omoikane 2y agoUser-generated static_assert messages would make it easier to build games that can be played entirely using compiler error messages. Something like this old IOCCC entry but nicer: https://www.ioccc.org/years.html#1994_westley https://www.ioccc.org/years.html#1994_westley
- sixthDot 2y ago> if (auto [to, ec] = std::to_chars(p, last, 42)) I'm not into plusplus, however i'm curious. How the tuple get evaluated to a condition ? is that lowered to if `to && ec` ?
- ReleaseCandidat 2y ago`ec` is an error code. What happens is a conversion to bool, see `operátor bool()` https://en.cppreference.com/w/cpp/utility/to_chars_result https://en.cppreference.com/w/cpp/utility/to_chars_result And no, don't ask mé why somebody might think that a bool is a suitable type to check for success or error.
- saagarjha 2y agoWhat is wrong with your keyboard lol
- ReleaseCandidat 2y agoAutocomplete.
- rnallandigal 2y agoThe std::to_chars function returns an object of type std::to_chars_result, which defines an operator bool() checking if ec == std::errc[0]. The if statement determines which branch to take based on the value of the condition. This value is contextually converted to a bool and evaluated[1]. [0] https://en.cppreference.com/w/cpp/utility/to_chars_result https://en.cppreference.com/w/cpp/utility/to_chars_result [1] https://en.cppreference.com/w/cpp/language/if#Condition https://en.cppreference.com/w/cpp/language/if#Condition
- quietbritishjim 2y agoBut there are two variables being defined by the destructuring. I believe OP's question was whether there's a rule for which gets chosen for the condition, rather than about contextual conversion to bool in general (which happens even when there's no initialisation in the if statement at all). Your comment seems to imply the condition is evaluated before initialising the variable(s) at all; is that what you meant? If so, this beast would work (even though it's undefined behaviour to construct a std::string from nullptr, and std::string is not convertible to bool): const char* foo() // may return nullptr if (std::string s = foo())
- logicchains 2y agoThis doesn't mention the most exciting thing coming: static reflection. Finally no need to manually implement printing or serialisation functions for every struct.
- pjmlp 2y agoProbably, it isn't fully backed in, and can happen the same as contracts in C++20.
- pjmlp 2y agoExciting as it may be, to be fully available for portable codebases maybe around 2030, given the current velocity of compilers adoption of ongoing standards, even among the big three. As of today, C++17 is the latest one can aspire to use for portable code, and better not making use of parallel STL features.
- Kelteseth 2y agoI would argue C++20 is totally fine. MSVC does not yet has a C++23 flag and it will be internally replaced with 'latest', aka some C++26 features, when you use it. This took us by surprise, because they deprecated some enum conversions and thus our clang-cl CI failed for openCV, with the latest llvm. I still fail to understand why enabling a specific C++ version, automatically means that it is considered stable. At least give use C++23-experimental or something /rant.
- pjmlp 2y agoWriting C++20 code without modules, ranges, or concepts, is like, what is the point. Naturally when code portability doesn't matter, it is another thing. All my C++ side projects are written against C++latest on Visual C++, and make full use of modules and concepts.
- einpoklum 2y ago> Writing C++20 code without modules, ranges, or concepts, is like, what is the point. * std::span is in! https://stackoverflow.com/q/45723819/1593077 https://stackoverflow.com/q/45723819/1593077 * Designated initializers (like in C99) * Spaceship operator and default comparison ops * More language constructs can be constexpr'ed * Better structured binding * using on enums * Don't need to say "typename" as much :-) * Bunch of minor improvements to the standard library Note I did not say coroutines. I still don't understand how that boondoggle made it into the language the way that it has.
- pjmlp 2y ago
- sohamgovande 2y agoOne major gripe I have with these C++ updates is that the proportion of codebases that actually use recent C++ features (cpp17, cpp20, cpp23) is very close to zero. The more and more esoteric this language becomes, the fewer people who can actually master it. Source: I've been writing C++ for 8 years.
- jb1991 2y agoIn some ways, you’re not wrong. In other ways, there’s been extremely broad support for some major new features in the language in recent years, like coroutines and concepts.
- fooker 2y agoThis is intentional. Most of the new features are for library writers.
- fsloth 2y agoI don’t really get this argument. Large C++ codebases are generally divided to libraries. The internal libraries and vendor libraries should both be of high quality. I’m not familiar with industrial use cases where every C++ user would not be a library writer.
- einpoklum 2y ago> The internal libraries and vendor libraries should both be of high quality. From my limited experience - high-quality internal libraries are simply not the reality; less likely to be achieved than winning the lottery. Companies typically: * are not able to identify candidates able of writing high-quality C++ * do not try to attract SW engineers by committing to high-quality code. * don't believe they should invest developer time in making a library more robust, and bringing them to the level of polish of a popular publicly-available FOSS libraries. * do not have a culture of acquiring, honing and sharing coding skills and expertise, with the help of actual experts. Again, time and effort is mostly not invested in this.
- alecco 2y agohttps://web.archive.org/web/20240907061007/https://mariusbancila.ro/blog/2024/09/06/whats-new-in-c26-part-1/ https://web.archive.org/web/20240907061007/https://mariusban... It seems to be down.
- psyclobe 2y agoC++, the sharpest knife in the drawer.
- D-Coder 2y agoUnfortunately it's the sox-and-T-shirts drawer...
- SuaveSteve 2y agoRegarding the delete feature, can one not just raise in C++ for a deprecated/deleted function?
- Negitivefrags 2y agoThe concept of doing something at runtime that could be done at compile time is anathema for c++ programmers.
- bluGill 2y agoYou could but why when we already know at build time that the function is deleted or deprecated and better yet know exactly where. runtime errors when in a rare path are often never tested until a customer hits that rare case. this is on of the reasons I won't use python for a larga project, eventually you will have critical errors in production because not only didn't you test the code but you didn't even get the minimun proof that it works that a compiler provides.
- chucksmash 2y ago> not only didn't you test the code That's why I won't use C++ programmers in a large project
- jll29 2y agoC++ is a monster. The 2026 proposal has some neat ideas (I like the ability for the developer to give a reasons for modifying behavior that may create otherwise cryptic error messages, for instance); but the more things one packs in there, the uglier, bloated the specs, and the more complicated and buggy compilers will be. Once C with Classes was an experimental pre-processor to try out bringing in some Simula ideas into the C world. Today, C++ has become a language that changes dramatically every half a decade, where the main question is "will it compile" if you receive someone else's code, and where even experienced developers cannot tell from compiler error messages what's wrong (g++). The undoubtedly clever people who have been working on it have nevertheless committed war crimes in anti-orthogonality. Tip: introduce a versioning mechanism like Rust has it, so that you are freed from the burden of having to be backwards-compatible.
- wslh 2y ago> C++ is a monster. I haven’t fuzzed a C++ compiler myself, but our team recently tried fuzzing a relatively simple S-expression-based compiler and discovered several issues in a few weeks [1]. I can only imagine what could be uncovered in C++ compilers. If this hypothesis holds, it suggests a significant attack vector that might elude even the smartest security researchers who are only analyzing repository codes and dependencies. [1] "Why the Fuzz About Fuzzing Compilers?": https://www.coinfabrik.com/blog/why-the-fuzz-about-fuzzing-compilers/ https://www.coinfabrik.com/blog/why-the-fuzz-about-fuzzing-c...
- JonChesterfield 2y agoCompiler engineers like fuzz testing. You'll find a bunch of infra for it in llvm. That should mean the easy targets have already been hit, though I wouldn't be too confident of that stance.
- fruffy 2y agoPlus there are hordes of academics using Clang/GCC as targets for bug-finding papers. The Csmith [1] paper alone has over a thousand citations at this point. I'd assume most of the low-hanging fruits are picked. [1] https://www.cs.tufts.edu/~nr/cs257/archive/john-regehr/finding-c-bugs.pdf https://www.cs.tufts.edu/~nr/cs257/archive/john-regehr/findi...
- binary132 2y agoReflection is awesome, it reminds me a lot of Zig’s comptime functionality.
- layer8 2y agoThere is no reflection feature in TFA.
- binary132 2y agoExcuse my ignorance, but what is TFA? I believe Reflection is being taken very seriously and will be included in standard 26.
- layer8 2y agoThe Fine Article, meaning what the HN submission links to.
- agalunar 2y agoI've always been mystified by that expansion. "The featured article" seems to me to make much more sense.
- spacechild1 2y agoOriginally, it stands for "The Fucking Article", as in "RTFA" (= "Read the fucking article"). The expansion "The Fine Article" is a humorous reference to the former. Note that over the years "TFA" has lost its profane meaning and is generally used in a neutral way.
- pjmlp 2y agoPlanned to be included, it remains open if it will indeed.
- wseqyrku 2y agoWhy they don't just invest in carbonlang instead?
- mattgrice 2y agoWow. Against my better judgment I will keep to the rules of this site and assume that was a good faith question. Rust is already a good systems language and is getting adoption. D is a great c++-alike already and for 20 (?) years. There is a mature C++ toolchain for any processor and OS you can imagine. Simply adopting a different C++ compiler or a newer version of one you are already using can take many months for a large company. Migration to even Carbon would probably take 10x as much effort.
- wseqyrku 2y agoCarbonlang is meant to have a seamless migration path, that is, flip the compiler on the same codebase for starters, no changes. It's not like TS/JS as a superset langauge, but you can have both at the file level and compile side-by-side.
- pjmlp 2y agoFirst there is no Carbonlang, it is called Carbon. Second, it is mostly a Google thing for their C++ use, it is still mostly a frontend implementation at this point, with semantics yet to be fully defined. They are also open that Carbon is basically an experiment.
- wsve 2y agoI often feel that when C++ posts come up, the majority of commenters are people who haven't deeply worked with C++, and there's several things people always miss when talking about it: - If you're working in a large C++ code base, you are stuck working with C++. There is no migrating to something like Rust. The overhead of training your engineers in a new language, getting familiar with a new tool chain, working with a new library ecosystem, somehow finding a way to transition your code so it works with existing C++ code and isn't buggy and adapts to the new paradigms is all extremely expensive. It will grind your product's development to a buggy halt. It's a bad idea. - Every time a new set of features (e.g. reflection, concepts, modules, etc.) is released, people bemoan how complicated C++ continues getting. But the committee isn't adding features for the sake of adding features, they're adding features because people are asking for them, they're spending years of their lives writing papers for the committee trying to improve the language so everyone can write better code. What you find horrifying new syntax, I find a great way of fixing a problem I've been dealing with for years. - Yes, it's a gross homunculus of a language. If I could switch our team to Rust without issues, I would in a heartbeat. But this is the beast we married. It has many warts, but it's still an incredible tool, with an amazingly hard working community, and I'm proud of that.
- nuancebydefault 2y ago> What you find horrifying new syntax, I find a great way of fixing a problem I've been dealing with for years. To prove you are not 'boosting'... could you give a convincing example?
- wsve 2y agoNot familiar with "boosting", but I'm definitely a fan of concepts and reflection. Reflection is absolutely gonna feel completely alien to people for a while, but there's a lot of areas in our codebase where I wish I could simply describe a data layout and have the efficient code generated for me instead of writing tons of boilerplate. Take JSON serialization for example. Currently, you have to write your (de)serialization by hand, but with the new reflection stuff one could do it based on a struct's members, and with less error. It'll be wonderful for writing new libraries that will make our lives easier.
- porphyra 2y agoC++ is a funny chimeric creation that has absorbed some great modern ideas from Rust and other new language but needs to preserve compatibility with its antediluvian C heritage. You could write it in a very clean and somewhat safe modern style or in a familiar C-like style. We use modern C++ at work and, by embracing RAII, it really isn't so bad.
- rldjbpin 2y agohow long before you reckon it would be widely adopted? i feel like the pace of revision (~3 years per standard) seems too fast.
- mckravchyk 2y agoI for one started working on a new project in C++ rather than Rust. I think it's unclear whether Rust is going to be the successor at this point. It's probably never going to pick up in the games industry, QT is C++ (and Rust bindings will always be second class or they could end up unmaintained), has better compile times and is said to be undisputed when it comes to high performance. Obviously the tool for the job factor is most critical. Career wise, many people are picking up Rust and almost no one is picking up C++, while experienced C++ devs either retire or switch to a higher level language due to landscape change. I would trust supply and demand to be in favour of C++ 10 years from now. There are also attempts to make C++ more memory safe like Carbon[1] or Circle compiler [2]. If they succeed, why would anyone want to switch to Rust? Also Rust is not ideal for security from a different perspective - I think the lack of a package manager is one C++ strongest points. After working for 9 years with npm, you really appreciate that the dependency you install is usually just a single dependency (even an option for a single header file is common), when there's a package manager, people will abuse it (like install a package with 3 dependencies of its own for something that could be 50 LOC copy-paste) and managing the security of the supply chain is nearly impossible (it will be a legal requirement soon in EU though). Anyway, I wanted to ask. How is the contracting market looking in C++ world? I'm guessing it depends on the domain heavily? I'm mainly asking about QT and anything that would be desktop / mobile apps / systems programming except video games, but I'm curious in general. [1] https://github.com/carbon-language/carbon-lang https://github.com/carbon-language/carbon-lang [2] https://github.com/seanbaxter/circle https://github.com/seanbaxter/circle