What's new in C++26 (part 1)
C++26 is developing features like specifying reasons for deleted functions, unnamed placeholder variables, structured binding in control statements, and user-generated messages in static_assert, enhancing code clarity and usability.
Read original articleC++26 is currently under development, introducing several new language and library features. One significant addition allows developers to specify reasons for deleting functions, enhancing clarity for API authors. This feature enables a more informative error message when a deleted function is invoked, rather than a generic compiler error. Another notable change is the introduction of unnamed placeholder variables using a single underscore (_), which can simplify code by allowing the declaration of variables that are not used. This feature also automatically applies the [[maybe_unused]] attribute to such variables, preventing compiler warnings. Additionally, C++26 permits structured binding declarations in the conditions of if, while, or for statements, which streamlines code by allowing multiple variables to be declared and initialized in a single statement. Lastly, the static_assert feature has been enhanced to accept user-generated string-like objects for error messages, improving the flexibility and clarity of compile-time assertions. These updates aim to improve code readability and usability in C++ programming.
- C++26 introduces the ability to specify reasons for deleted functions.
- Unnamed placeholder variables can now be declared using a single underscore (_).
- Structured binding declarations can be used in the conditions of control statements.
- User-generated string-like objects can be used in static_assert messages.
- These features enhance code clarity and usability in C++.
Related
Malloc() and free() are a bad API (2022)
The post delves into malloc() and free() limitations in C, proposing a new interface with allocate(), deallocate(), and try_expand(). It discusses C++ improvements and emphasizes the significance of a robust API.
New Features in C++26
The ISO released new C++ standards on a three-year cycle, with C++26 proposals open until January 2025. Updates include hazard pointers, user-space RCU support, debugging headers, and template enhancements for improved functionality.
What's so hard about constexpr allocation?
C++20 allows allocations during constant evaluation, but they must be deallocated in the same context, limiting constructs like `constexpr std::vector`. Challenges include constant destruction and access problems, requiring clearer rules.
Safer code in C++ with lifetime bounds
Daniel Lemire's blog emphasizes using lifetime bounds in C++ to improve code safety and performance, highlighting the role of std::string_view in avoiding unnecessary copies and preventing dangling references.
Improving _Generic in C2y
The C programming community is enhancing the _Generic feature for the C2y standard to resolve issues from C23, focusing on simplifying type matching and addressing limitations in usability and behavior.
- 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.
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.
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.
Source: I've been writing C++ for 8 years.
I'm not into plusplus, however i'm curious. How the tuple get evaluated to a condition ? is that lowered to if `to && ec` ?
It seems to be down.
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.
The standards committee are thorough in their mission to including everything and the kitchen sink in C++.
Related
Malloc() and free() are a bad API (2022)
The post delves into malloc() and free() limitations in C, proposing a new interface with allocate(), deallocate(), and try_expand(). It discusses C++ improvements and emphasizes the significance of a robust API.
New Features in C++26
The ISO released new C++ standards on a three-year cycle, with C++26 proposals open until January 2025. Updates include hazard pointers, user-space RCU support, debugging headers, and template enhancements for improved functionality.
What's so hard about constexpr allocation?
C++20 allows allocations during constant evaluation, but they must be deallocated in the same context, limiting constructs like `constexpr std::vector`. Challenges include constant destruction and access problems, requiring clearer rules.
Safer code in C++ with lifetime bounds
Daniel Lemire's blog emphasizes using lifetime bounds in C++ to improve code safety and performance, highlighting the role of std::string_view in avoiding unnecessary copies and preventing dangling references.
Improving _Generic in C2y
The C programming community is enhancing the _Generic feature for the C2y standard to resolve issues from C23, focusing on simplifying type matching and addressing limitations in usability and behavior.