News

CppCon 2023 Back to Basics: Templates -- Rainer Grimm

Registration is now open for CppCon 2023! The conference starts on October 1 and will be held in person in Aurora, CO. To whet your appetite for this year’s conference, we’re posting some upcoming talks that you will be able to attend this year. Here’s another CppCon future talk we hope you will enjoy – and register today for CppCon 2023!

Back to Basics: Templates

Monday, October 2 • 11:00am - 12:00pm

by Rainer Grimm

Summary of the talk:

The future of C++ speaks templates. Therefore, a professional C++ programmer must know the basics of templates. In this talk, I will provide this basic knowledge about function and class templates, template arguments and parameters, and template specialization. Additionally, thanks to C++ Insights, I can further deepen your intuition about templates.

Inside STL: The Pair and The Compressed Pair -- Raymond Chen

RaymondChen_5in-150x150.jpgThe C++ language comes with a standard library. When you’re debugging your C++ code, you may have to go digging inside the implementation to extract information from crash dumps. This mini-series is going to look at how various C++ standard library types are implemented by the three major implementations (clang, gcc, and msvc).

Inside STL: The Pair and The Compressed Pair

By Raymond Chen

From the article:

The C++ language comes with a standard library. When you’re debugging your C++ code, you may have to go digging inside the implementation to extract information from crash dumps. This mini-series is going to look at how various C++ standard library types are implemented by the three major implementations (clang, gcc, and msvc).

We’ll start with the lowly std::pair. Its definition is quite simple.

template<typename T1, typename T2>
struct pair
{
    T1 first;
    T2 second;
};

The names of the members of std::pair are required by the C++ language standard, so you don’t see any variation here. Here’s how it looks in the Windows debugger:

0:000> ?? t
struct std::pair<int,int>
   +0x000 first            : 0n42
   +0x004 second           : 0n99

CppCon 2023 Delivering Safe C++ -- Bjarne Stroustrup

Registration is now open for CppCon 2023! The conference starts on October 1 and will be held in person in Aurora, CO. To whet your appetite for this year’s conference, we’re posting some upcoming talks that you will be able to attend this year. Here’s another CppCon future talk we hope you will enjoy – and register today for CppCon 2023!

Delivering Safe C++

Monday, October 2 • 8:45am - 10:30am

by Bjarne Stroustrup

Summary of the talk:

Type safety was one of the key initial C++ design ideals. We have evolved C++ to the point where we can write C++ with no violations of the type system, no resource leaks, no memory corruption, no garbage collector, no limitation of expressiveness or performance degradation compared to well-written modern C++.

We face three major challenges: To define what “safe” means in the context of various C++ uses, to guarantee such safety where guarantees are needed, and to get developers to write such verified safe code.

I outline an approach based on safety profiles to address these challenges, describe an approach to eliminate dangling pointers, and suggest how to eliminate all dangling pointers and all range errors. My aim for key applications is verified type-and-resource-safe C++. An emphasis is on minimizing costly run-time checks through the use of abstractions. I see the current emphasis on safety as an opportunity to complete one aspect of C++’s fundamental aims in real-world code.

Understanding Ranges Views and View Adaptors Objects in C++20/C++23 -- Bartlomiej Filipek

rangesviews-filipek.pngIn this article, we’d shed some light on the implementation of ranges::reverse_view and std::views::reverse. We’ll compare them to understand the differences between views and their adaptor objects.

Understanding Ranges Views and View Adaptors Objects in C++20/C++23

By Bartlomiej Filipek

From the article:

Let’s look at an example to understand how these views work. Assume we have a range r of integers from 1 to 5. When we apply std::views::reverse to r, it creates a view representing the elements of r in the reverse order.
#include <ranges> 
#include <vector> 
#include <iostream>  

int main() {
  std::vector<int> r = {1, 2, 3, 4, 5};  
  auto reversed = r | std::views::reverse;  
  for (auto i : reversed)  
     std::cout << i << " ";   

  // same as:  
  for (auto i : r | std::views::reverse)  
     std::cout << i << " "; 
}

No, C++ static analysis does not have to be painful -- Geoffray Adde

Static analysis as part of your CI pipeline has long been possible -- but tedious, at best, to setup. Sonar are upending that with an innovative new approach.

No, C++ static analysis does not have to be painful

by Geoffray Adde

From the article:

It seems impossible to offer serious C++ static analysis with a great configuration experience. Users must suffer the pain, or not use it at all.
Well, at Sonar we believe in making the impossible, possible and so we've gone ahead and solved this once and for all!

Perfect Forwarding Forwards Objects Not Braced Things Trying To Become Objects -- Raymond Chen

RaymondChen_5in-150x150.jpgIn C++, perfect forwarding is the act of passing a function’s parameters to another function while preserving its reference category. It is commonly used by wrapper methods that want to pass their parameters through to another function, often a constructor.

Perfect Forwarding Forwards Objects, Not Braced Things That Are Trying To Become Objects

By Raymond Chen

From the article:

In C++, perfect forwarding is the act of passing a function’s parameters to another function while preserving its reference category. It is commonly used by wrapper methods that want to pass their parameters through to another function, often a constructor.

template<typename T, typename... Args>
std::unique_ptr<T> make_unique(Args&&... args)
{
    return std::unique_ptr<T>(
        new T(std::forward<Args>(args)...));
}

The make_unique function takes its parameters, forwards them to the T constructor, and then puts the pointer to the newly-constructed T inside a unique_ptr. Those parameters are forwarded perfectly into the constructor: If the original parameters were rvalue reference, then the constructor receives rvalue reference. If the original parameters were lvalue references, then the constructor receives lvalue reference.

But the catch is that it can forward only objects. It can’t forward “braced things that are trying to become objects”.

C++ exceptions and memory allocation failure -- Wu Yongwei

C++ exceptions are habitually disabled in many software projects. A related issue is that these projects also encourage the use of new (nothrow) for fear of exceptions. Is it good practice or bad practice? Also, how likely are we to really encounter out-of-memory errors? I will investigate on this topic and discuss strategies to deal with memory issues.

C++ Exceptions and Memory Allocation Failure

By Wu Yongwei

From the article:

In fact, every time we initialize or modify a string, vector, or map, we may be allocating memory on the heap. If we think that new will end in an exception (and therefore choose to use new (nothrow)), exceptions may also occur when using these mechanisms. In a program that has disabled exceptions, the result will inevitably be a program crash.

Ignoring abnormal scenarios like allocating more memory than the physical memory size at a time (which would likely be a logic error in the program), can a reasonable program still experience memory allocation failures?

Dynamic CUDA with NVIDIA's Runtime Compilation -- Richard Thomson

Utah C++ Programmers has released a new video:

Dynamic CUDA with NVIDIA's Runtime Compilation

by Richard Thomson

From the video description:

Using CUDA is great way to accelerate tasks on the GPU. Regular CUDA programming compiles your C++ code into code that can execute on the GPU. But what if your problem domain is more dynamic and requires generation of code on the fly?

On the CPU you can use techniques like LLVM to compile code Just-in-Time (JIT) into the native CPU instruction set and call this code directly from your application. What about on the GPU?

The NVRTC (Runtime Compilation) library accepts CUDA C++ source code and creates modules of GPU ready code that you can execute on the GPU.

This month, Richard Thomson will give us an introduction to using the NVRTC library for runtime compilation and nvJitLink for runtime linking of CUDA C++ source code to execute code on the GPU. We'll use a simple fractal generator as the example, with a user provided "iteration formula" to generate a fractal image in the complex plane.

https://www.youtube.com/watch?v=9OCQb5RA-s0

C++23: static operator() and static operator[] -- Sandor Dargo

sandordargo.jpgIn this article, we are going to review two new features of C++23. Now the language allows the call operator (operator()) and the subscription operator (operator[]) to be static.

C++23: static operator() and static operator[]

By Sandor Dargo

From the article:

static operator()

As we saw earlier in our big C++ algorithms tutorial, function objects are extensively used in the standard library to customise the behaviour of several functions. With the introduction of ranges in C++20 (and of earlier non-standard libraries), the usage of function objects became even more widespread.

Many function objects are extremely simple. Let’s take an implementation of isEven.

auto isEven = [](int i) {return i % 2 == 0;};

2023-08 Mailing Available

The 2023-08 mailing of new standards papers is now available.

 

WG21 Number Title Author Document Date Mailing Date Previous Version Subgroup
N4956 Concurrency TS2 PDTS Michael Wong 2023-08-15 2023-08   All of WG21
N4958 Working Draft, Programming Languages -- C++ Thomas Köppe 2023-08-14 2023-08   All of WG21
N4959 Editors' Report, Programming Languages -- C++ Thomas Köppe 2023-08-14 2023-08   All of WG21
N4960 Business Plan and Convener's Report: ISO/IEC JTC1/SC22/WG21 (C++) Herb Sutter 2023-08-09 2023-08   All of WG21
P0124R7 Linux-Kernel Memory Model Paul E. McKenney 2023-08-22 2023-08 P0124R6 SG1 Concurrency and Parallelism,SG5 Transactional Memory,SG14 Low Latency
P0124R8 Linux-Kernel Memory Model Paul E. McKenney 2023-08-22 2023-08 P0124R7 SG1 Concurrency and Parallelism,SG5 Transactional Memory,SG14 Low Latency
P0963R1 Structured binding declaration as a condition Zhihao Yuan 2023-08-14 2023-08 P0963R0 EWG Evolution
P1068R8 Vector API for random number generation Ilya Burylov 2023-08-08 2023-08 P1068R7 LEWG Library Evolution
P1967R11 #embed - a simple, scannable preprocessor-based resource acquisition method JeanHeyd Meneide 2023-08-21 2023-08 P1967R10 CWG Core
P2407R5 Freestanding Library: Partial Classes Ben Craig 2023-07-26 2023-08 P2407R4 LWG Library
P2521R5 Contract support -- Record of SG21 consensus Andrzej Krzemieński 2023-08-15 2023-08 P2521R4 SG21 Contracts
P2728R6 Unicode in the Library, Part 1: UTF Transcoding Zach Laine 2023-08-14 2023-08 P2728R5 SG16 Unicode,LEWG Library Evolution
P2746R3 Deprecate and Replace Fenv Rounding Modes Hans Boehm 2023-08-14 2023-08 P2746R2 SG6 Numerics,LEWG Library Evolution
P2795R3 Erroneous behaviour for uninitialized reads Thomas Köppe 2023-07-28 2023-08 P2795R2 SG12 Undefined and Unspecified Behavior,SG23 Safety and Security,EWG Evolution,CWG Core
P2821R4 span.at() Jarrad J. Waterloo 2023-07-26 2023-08 P2821R3 SG23 Safety and Security,LEWG Library Evolution
P2833R1 Freestanding Library: inout expected span Ben Craig 2023-08-19 2023-08 P2833R0 LEWG Library Evolution
P2845R2 Formatting of std::filesystem::path Victor Zverovich 2023-07-23 2023-08 P2845R1 SG16 Unicode,LEWG Library Evolution
P2863R1 Review Annex D for C++26 Alisdair Meredith 2023-08-16 2023-08 P2863R0 EWG Evolution,LEWG Library Evolution
P2864R1 Remove Deprecated Arithmetic Conversion on Enumerations From C++26 Alisdair Meredith 2023-08-16 2023-08 P2864R0 SG22 Compatability,EWG Evolution
P2865R2 Remove Deprecated Array Comparisons from C++26 Alisdair Meredith 2023-08-16 2023-08 P2865R1 SG22 Compatability,EWG Evolution
P2868R1 Remove Deprecated `std::allocator` Typedef From C++26 Alisdair Meredith 2023-08-15 2023-08 P2868R0 LEWG Library Evolution
P2869R1 Remove Deprecated `shared_ptr` Atomic Access APIs From C++26 Alisdair Meredith 2023-08-16 2023-08 P2869R0 LEWG Library Evolution
P2870R1 Remove `basic_string::reserve()` From C++26 Alisdair Meredith 2023-08-16 2023-08 P2870R0 LEWG Library Evolution
P2871R1 Remove Deprecated Unicode Conversion Facets From C++26 Alisdair Meredith 2023-08-08 2023-08 P2871R0 LEWG Library Evolution
P2875R1 Undeprecate `polymorphic_allocator::destroy` For C++26 Alisdair Meredith 2023-08-15 2023-08 P2875R0 LEWG Library Evolution
P2878R5 Reference checking Jarrad J. Waterloo 2023-08-10 2023-08 P2878R4 SG23 Safety and Security
P2885R1 Requirements for a Contracts syntax Timur Doumler 2023-08-15 2023-08 P2885R0 SG21 Contracts,EWG Evolution
P2890R0 Contracts on lambdas Timur Doumler 2023-08-17 2023-08   SG21 Contracts
P2894R0 Constant evaluation of Contracts Timur Doumler 2023-08-22 2023-08   SG21 Contracts
P2896R0 Outstanding design questions for the Contracts MVP Timur Doumler 2023-08-22 2023-08   SG21 Contracts
P2905R2 Runtime format strings Victor Zverovich 2023-07-23 2023-08 P2905R1 LWG Library
P2909R0 Dude, where's my char? Victor Zverovich 2023-08-13 2023-08   SG16 Unicode,LEWG Library Evolution
P2933R0 std::simd overloads for <bit> header Daniel Towner 2023-08-01 2023-08   SG1 Concurrency and Parallelism,LEWG Library Evolution
P2935R0 An Attribute-Like Syntax for Contracts Joshua Berne 2023-08-15 2023-08   SG21 Contracts
P2944R1 Comparisons for reference_wrapper Barry Revzin 2023-08-17 2023-08 P2944R0 LEWG Library Evolution
P2951R2 Shadowing is good for safety Jarrad J. Waterloo 2023-08-10 2023-08 P2951R1 SG23 Safety and Security
P2952R0 auto& operator=(X&&) = default Arthur O'Dwyer 2023-08-10 2023-08   EWGI SG17: EWG Incubator,EWG Evolution
P2953R0 Forbid defaulting operator=(X&&) && Arthur O'Dwyer 2023-08-10 2023-08   EWGI SG17: EWG Incubator,EWG Evolution
P2954R0 Contracts and virtual functions for the Contracts MVP Ville Voutilainen 2023-08-03 2023-08   SG21 Contracts
P2955R0 Safer Range Access Jarrad J. Waterloo 2023-08-10 2023-08   SG23 Safety and Security
P2956R0 Add saturating library support to std::simd Daniel Towner 2023-08-01 2023-08   SG1 Concurrency and Parallelism,LEWG Library Evolution
P2957R0 Contracts and coroutines Andrzej Krzemieński 2023-08-15 2023-08   SG21 Contracts
P2958R0 typeof and typeof_unqual JeanHeyd Meneide 2023-08-21 2023-08   EWG Evolution
P2960R0 Concurrency TS Editor's report for N4956 Michael Wong 2023-08-16 2023-08   All of WG21