Jump to content

The Standard C++ News

Latest from the ISO C++ Website.

  1. Started by Horizon,

    The 2025-03 mailing of new standards papers is now available. WG21 Number Title Author Document Date Mailing Date Previous Version Subgroup N5004 2025 Sofia Meeting Invitation and Information Vassil Vassilev 2025-01-14 2025-03 All of WG21 N5005 WG21 2025-01 Hagenberg Admin telecon minutes Nina Ranns 2025-01-31 2025-03 All of WG21 N5006 2025 WG21 admin telecon meetings (revised 2025-02-20) Herb Sutter 2025-03-03 2025-03…

    • 0 replies
    • 0 views
  2. Today, we’ll look at a crash that occurred when trying to erase an element from a std::set. The Case of the Crash When Trying to Erase an Element from a std::set by Raymond Chen From the article: rax=000001f565bc046e rbx=000001f589b20340 rcx=000001f565bc046e rdx=000000e6658feca8 rsi=000001f589b20690 rdi=000001f589b203c0 rip=00007ffdd4726bc4 rsp=000000e6658fec30 rbp=0000388a1713ab55 r8=000001f589b895d0 r9=000001f589b895d0 r10=000001f589000140 r11=0000000000000000 r12=0000000000000001 r13=000000007ffe0385 r14=0000000000000000 r15=000001f589b8f900 LitWare!std::_Tree<std::_Tset_traits<WidgetWatcher *, std::less<WidgetWatcher *>, …

    • 0 replies
    • 0 views
  3. In today's post, I'll learn how modern C++ can influence the code you write for your embedded system. You will see code using up to C++23. The example I show you below circles around at least two questions I got various times from customers: What is consteval good for? What is that user-defined literal operator, and why should I care? C++ for Embedded Systems: constexpr and consteval by Andreas Fertig From the article: Chapter One: What is a MAC address? I teach a lot of classes to customers who are developing embedded systems. That makes sense. I worked for a long time in that domain, and I enjoyed it so much. One recurring topic is networ…

  4. The std::map subscript operator ([]) is a convenient but sometimes dangerous feature, as it can create unintended default-constructed entries. By understanding the behavior of various map insertion and lookup methods—such as insert, emplace, try_emplace, and insert_or_assign—developers can write more efficient and predictable code while avoiding unnecessary key-value creations and duplicate lookups. A Simplified Overview of Ways to Add or Update Elements in a std::map by Raymond Chen From the article: Some time ago, I mentioned how the std::map subscript operator is a dangerous convenience. In that article, I linked to an overview of the insertion empl…

    • 0 replies
    • 7 views
  5. C++26 introduces pack indexing as a core language feature, making it significantly easier to extract specific elements from parameter packs using a familiar subscript syntax. This improvement, proposed by Corentin Jabot and Pablo Halpern, eliminates the need for cumbersome workarounds like recursive templates or boolean expression tricks, providing a more intuitive and readable approach. C++26: pack indexing by Sandor Dargo From the article: C++11 introduced parameter packs to provide a safer way to pass an undefined number of parameters to functions instead of relying on variadic functions. While packs are a useful feature, and since C++17 it’s s…

    • 0 replies
    • 28 views
  6. In this blog post, we’ll explore ways to improve the safety of a simple configuration manager. We’ll handle common pitfalls like dangling references and excessive stack usage. Additionally, we’ll see how C++26 helps enforce safer coding practices with stricter diagnostics and improved handling of large objects. Improving Code Safety in C++26: Managers and Dangling References by Bartlomiej Filipek From the article: Step 1: The Buggy Implementation Below is a simple example of a manager object that stores various configs in a map and provides a method to retrieve them. When a requested configuration isn’t found, the code attempts to return a def…

    • 0 replies
    • 16 views
  7. Last time,┬áwe looked at how the Microsoft C++ standard library implements┬áwait┬áand┬ánotify_*┬áfor┬ástd::atomic<std::shared_ptr<T>>. Today, weΓÇÖll look at the other library that (as of this writing) implements┬ástd::atomic<std::shared_ptr<T>>: libstdc++. Inside STL: Waiting for a std::atomic<std::shared_ptr<T>> to change, part 2 by Raymond Chen From the article: The first thing to note is that the traditional ΓÇ£wait for a value to changeΓÇ¥ mechanism on unix is the futex, but futexes (futexen?) are limited to 4-byte values, which is insufficient for a 64-bit pointer, much less the┬átwo┬ápointers inside a┬áshared_…

    • 0 replies
    • 18 views
  8. The ACCU conference has a range of workshops, including online options, this year: Workshops for Everyone by ACCU Conference From the article: See all the offerings, from Jason Turner, Nicolai Josuttis, Robert Seacord, Gail Ollis, Mateusz Pusz, Phil Nash and Mike Shah. View the full article

    • 0 replies
    • 30 views
  9. Started by Horizon,

    Should you start new projects in C++, these days? Is language safety an issue for you? What can be done, today? Making C++ Safer by Greg Law From the article: I believe that over time C++ will become a lot safer, maybe even some kind of ΓÇÿsafeΓÇÖ. Competition is good: Clang was the best thing to happen to GCC, and Rust might turn out to be the best thing to happen to C++. That journey has already begun, with proposals for the evolution of the language including Contracts and Profiles, and simply changing some of the defaults in C++26. While the language custodians work to make the language itself safer, what can you do today? ┬á View the full arti…

    • 0 replies
    • 15 views
  10. When using std::atomic<std::shared_ptr<T>>, the C++ standard defines a "change" as a modification to either the stored pointer or the control block pointer. However, since atomic wait mechanisms typically track only a single memory address, the Microsoft implementation handles this limitation by using a timeout-based polling strategy to detect changes in the control block. Inside STL: Waiting for a std::atomic<std::shared_ptr<T>> to change, part 1 by Raymond Chen From the article: Like other┬ástd::atomic┬áspecializations,┬ástd::atomic<std::shared_ptr<T>>┬ásupports the┬áwait┬áand┬ánotify_*┬ámethods for waiting for the…

    • 0 replies
    • 21 views
  11. In this post, we are going to discuss a core language feature proposed by Corentin Jabot and Micheal Park in P2169R4. With the new standard we get a cool unnamed placeholder. C++26: A Placeholder with No Name by Sandor Dargo From the article: By convention, when we have a variable whose value we donΓÇÖt want to use or care about, we often name it┬á_. The problem is that with higher warning levels (-Wunused-variable), our compilation might fail because┬á_┬áis unused. int foo() { return 42; } auto _ = foo(); /* error: unused variable '_' [-Werror,-Wunused-variable] */ To avoid this problem, we must mark it┬á[[maybe_unused]]. ┬á View the full art…

    • 0 replies
    • 28 views
  12. PVS-Studio 7.35 has been released. Support for the MISRA C standard, the plugin for Qt Creator 15.x, modified file analysis in Visual Studio, and that's not all. PVS-Studio 7.35: MISRA C 2023 support, Qt Creator 15 plugin, and more by Vladislav Bogdanov From the article: We've begun work to expand the PVS-Studio's coverage of the MISRA C standard. With the release of 7.35, the first eight diagnostic rules have already been implemented, and more are on the way. The full list of implemented rules is provided below. We plan to cover at least 85% of MISRA C and support the latest version of MISRA C 2023.   View the full article

    • 0 replies
    • 39 views
  13. Since its introduction, the constexpr keyword in C++ has steadily evolved with each new standard, becoming an increasingly powerful tool for compile-time computation and optimization. In this article, IΓÇÖll share a real-world example of how constexpr helped optimize memory usage and improve performance for an embedded system project, showcasing its potential to transform how we approach C++ programming. Write More C++ Code Thanks to constexpr by Andreas Fertig From the article: Since the keyword┬áconstexpr┬áand its behavior got included in C++, it has been improved in each and every new standard of the language. I'm a big fan of┬áconstexpr┬áand a…

    • 0 replies
    • 31 views
  14. Started by Horizon,

    Sometimes, we all need a way to iterate over a container in the opposite direction. There are several ways to reverse-iterate a container, and in this article, weΓÇÖll explore them. Reverse Iterations by Coral Kashri From the article: Probably the simplest way, taken from C is to iterate using an index location: for (int64_t index = ssize(container); index >= 0; --index) { ┬á┬á┬á┬á// do something with `container[index]` } This way is highly not recommended as it might lead to infinite loops if done incorrectly (for example by using┬áuint64_t┬áor┬ásize_t┬áfor the index type), and you can find more issues with this way in some┬ápreviou…

    • 0 replies
    • 38 views
  15. static_assert┬áfurther evolves with C++26. Our tool for compile-time assertion will support user-generated error messages. As such, weΓÇÖll be able to reuse messages as well as enrich them with information available at compile-time making diagnostics easier to read. C++26: user-generated static_assert messages by Sandor Dargo From the article: Our first quest into the world of C++26 was about┬á=delete┬áwith an optional error message, which improves the readability of the source code and potentially the error messages. In this next part of our journey, we will continue to focus on readability improvements, particularly those for error messages. Wit…

    • 0 replies
    • 48 views
  16. With the success of the trainings after Meeting C++ 2024, I've decided to offer more opportunities for you to learn C++. Klaus Iglberger starts next week with C++ Software Design. With these trainings following in March: ┬á┬á┬á Generic programming in C++ with templates and auto with Nicolai Josuttis (10th March, 1 day) ┬á┬á┬á Embedded C++ Basic Training with Richard Kaiser (10th March, 4 days) ┬á┬á┬á C++ Fundamentals You Wish You Had Known Earlier with Mateusz Pusz (13th March, 2 days) ┬á┬á┬á Concepts, Ranges, and Views - The New Way of Programming in C++ with Nicolai Josuttis (17th March, 1 day) ┬á┬á┬á Introduction to C++ - Five Day Online Training with Slo…

    • 0 replies
    • 49 views
  17. In this article, you’ll see eight larger examples that illustrate the changes in C++23. 8 More C++23 Examples by Bartlomiej Filipek From the article: C++23 brings a ton of cool features, as you can see in my two previous articles (here and here). So far, we explored each new addition one by one, but I’d like to share more examples that combine multiple features. Here we go: 1. std::ranges::to<>  The ranges::to<> feature allows you to convert ranges into containers easily: View the full article

    • 0 replies
    • 40 views
  18. When tasked with diagnosing why a pointer passed through a pipeline emerged offset from its original value, I discovered an interesting culprit: the misuse of a wrapper function around SubmitWork. While the wrapper aimed to simplify usage by allowing both raw pointers and references to standard layout types, it inadvertently caused ambiguous overload resolution, leading to incorrect behavior. This analysis explores how the issue arose, the debugging process, and improvements to ensure robust and predictable pointer handling in similar scenarios. In C++, failure to meet the requirements does not always mean that you fail if you donΓÇÖt meet the requirements by Ra…

    • 0 replies
    • 35 views
  19. Back in the day, being a witch was considered a grave crime. Today, weΓÇÖre diving into one of C++ΓÇÖs lesser-known spells: ADL (Argument-Dependent Lookup).┬á ADL ΓÇô Avoid Debugging Later by Coral Kashri From the article: But before we explore this arcane magic, you must heed a warningΓÇöblack magic comes with consequences. ADL is particularly treacherous, often leading to frustrating and hard-to-debug issues. Whenever possible, itΓÇÖs wise to avoid casting this spell unless absolutely necessary. Ingredients Every spell needs ingredients, this time the only ingredients you need are a C++ compiler and a function that accepts at least one paramet…

    • 0 replies
    • 43 views
  20. Started by Horizon,

    It is now 45+ years since C++ was first conceived. As planned, it evolved to meet challenges, but many developers use C++ as if it was still the previous millennium. This is suboptimal from the perspective of ease of expressing ideas, performance, reliability, and maintainability. 21st Century C++ by┬áBjarne Stroustrup About the article: Here, I present the key concepts on which performant, type safe, and flexible C++ software can be built: resource management, life-time management, error-handling, modularity, and generic programming. At the end, I present ways to ensure that code is contemporary, rather than relying on outdated, unsafe, and hard-to-ma…

    • 0 replies
    • 38 views
  21. Alex shows in his small framework a different approach for serialization of data structures. Serialization by contract By Alex Marmer From the article: In any project, when a function is created for serialization, another function is created for unserialization. Serialization by contrast uses another approach - a contract with name and data structures is declared, and then serialization and unserialization of the data are automatic. View the full article

    • 0 replies
    • 31 views
  22. In this article, we briefly explain everything you need to know to get started with Contracts as proposed for C++26 in P2900. Contracts for C++ explained in 5 minutes by Timur Doumler From the article: With P2900, we propose to add contract assertions to the C++ language. This proposal is in the final stages of wording review before being included in the draft Standard for C++26. It has been suggested by some members of the C++ standard committee that this feature is too large, too complicated, and hard to teach. As it turns out, the opposite is true: contract assertions are actually very simple and can be explained in just five minutes. In this…

    • 0 replies
    • 29 views
  23. I wanted to use VS Code with the MS C/C++ Extension for some C++ teaching. In the process, I discovered that setting the C++ language standard to build your C++ code is not as easy and intuitive as one would expect. I discussed the details in this article: VS Code with MS C/C++ Extension: A Confusing UI Design Choice by Giovanni Dicanio From the article: I pressed Ctrl+Shift+P, selected C/C++ Edit Configurations (UI), and in the C/C++ Configurations page, selected c++20 for the C++ standard. Then I pressed F5 to start a debugging session, preceded by a build process, and saw that the build process failed. I took a look at the error message …

    • 0 replies
    • 23 views
  24. The C++20 standard introduced a specialization of┬ástd::atomic┬áfor shared pointers:┬ástd::atomic<shared_ptr<T>>. How does it work? Inside STL: The atomic shared_ptr by Raymond Chen From the article: Recall that a normal┬áshared_ptr┬áconsists of two pointers: A stored pointer that the┬áshared_ptr┬áreturns when you call┬áget()┬áand a pointer to a control block which holds the strong reference count, the weak reference count, and a pointer to the managed object. The atomic version of the┬áshared_ptr┬áhas the same layout, with one change: The bottom two bits of the pointer to the control block are used as flags. Exercise: Why use the…

    • 0 replies
    • 16 views
  25. Do you want to stay ahead of the curve and start to use polymorphic allocators in your projects? Are you undeterred even by the cost of virtual calls? If so, it's time to talk about the nuances with a lifetime and why you can't just replace containers with analogs from the 'pmr' namespace. How frivolous use of polymorphic allocators can imbitter your life by Grigory Semenchev From the article: The developers' prayers have been answered! Starting with C++17, you can use polymorphic allocators. Their idea is a little different from what we need. What is important is that they allow you to specify a buffer from which the allocator will take memory. Such a…

    • 0 replies
    • 26 views

Recently Browsing 0

  • No registered users viewing this page.