News

Inside STL: The lists -- Raymond Chen

Raymond ChenThe C++ standard library type list represents a doubly-linked list, and forward_list is a singly-linked list. Fortunately, the implementations of both of these lists are pretty much what you expect.

Inside STL: The lists

By Raymond Chen

From the article:

Let’s start with the simpler forward_list.

template<typename T>
struct forward_list
{
    forward_list_node<T>* head;
};

template<typename T>
struct forward_list_node
{
    forward_list_node<T>* next;
    T value;
};

The forward_list itself is a pointer to the first element of the list, or nullptr if the list is empty. Each subsequent element contains a pointer to the next element, or nullptr if there is no next element.

CppCon 2023 Things Happening in SG14… -- Patrice Roy

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!

CppCon 2023 Things Happening in SG14…

Monday, October 2 • 14:00 - 15:00

by Patrice Roy

Summary of the talk:

The C++ standards committee is made of a small number of working groups and of a larger number of study groups, including SG14 (low-latency, finances, games and embedded systems). Since pandemic times, SG14 has been brewing a number of proposals meant to make C++ 'better for game developers'. We will look at the principles behind this effort, the output of this work and what this means for C++.

Inside STL: The string -- Raymond Chen

Raymond ChenYou might think that a std::string (and all of its friends in the std::basic_string family) are basically a vector of characters internally. But strings are organized differently due to specific optimizations permitted for strings but not for vectors.

Inside STL: The string

By Raymond Chen

From the article:

The starting point for a std::basic_string is this:¹

template<typename T>
struct basic_string
{
    T* ptr;
    size_t size;
    size_t capacity;
};

The ptr is a pointer to the beginning of the string contents.

The size is the number of characters in the string, not including the null terminator.

The capacity is the string capacity, not including the null terminator.

The picture for this simplified version is as follows:

string-chen.png

CppCon 2023 A Long Journey of Changing std::sort Implementation at Scale -- Danila Kutenin

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!

A Long Journey of Changing std::sort Implementation at Scale

Monday, October 2 • 14:00 - 15:00

by Danila Kutenin

Summary of the talk:

Sorting algorithms have been improving for almost 50 years now with claims of better efficiency and various properties but the question of adopting a new one at scale is often left behind. At Google we replaced std::sort in the LLVM libc++ library to test it for hundreds of thousand calls. We faced many challenges which we had been fixing for 2 years including golden tests, efficiency problems, undefined behavior and broken production. In this talk we want to cover issues on how we improved debugging, benchmarking, how much better a new implementation was compared to the old one and what we have learned on this journey of improved sorting.

CppCon 2023 Back to Basics: Functions -- Mike Shah

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: Functions

Monday, October 2 • 14:00 - 15:00

by Mike Shah

Summary of the talk:

Functions are one of the first things programmers learn, granting you the ultimate power to 'resuse' code and build modular programs. In this talk, we are going to provide an overview of functions from the start to the end, on the various powers that are given to us from the ground up. Consider this talk your one stop for learning all of the great things about functions!

We'll start with a basic function example, identifying the function signature and basic abilities of a function. Then we are going to view this function again from the perspective of assembly (using compiler explorer) to show you how a function is structured. From the assembly view, we will then observe that functions have addresses (they must after all!) and that we can store functions in pointers. We'll take a brief aside to show you how modern C++ also gives us the convenient std::function. Functions need not always be 'global' building blocks of our programs, the next step in our journey will be to see how we can have functions at local scope (e.g. lambda's) and how they can be used (and often times in handy ways in the STL). Ah, intrigued are you? We're not quite done! Now with building blocks such as lambda's (and related functors) we can utilize function composition to really unlock the power of functions. Towards the end of this talk, we will talk about grouping related functions (into namespaces) and as member functions in classes. Within our discussion of functions in classes, we'll touch on virtual functions, static functions, and operator overloading. We'll circle back to where we began on these topics, again showing you the assembly. At the end of this talk, you will have had FUN with functions (I couldn't resist...but you will see the complete C++ picture of functions).

CppCon 2023 Lifetime Safety in C++: Past, Present and Future -- Gabor Horvath

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!

Lifetime Safety in C++: Past, Present and Future

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

by Gabor Horvath

Summary of the talk:

How can we make C++ safer without sacrificing its performance and flexibility? Memory safety is a desirable property for any C++ program, but it is not easy to achieve. Recent revisions of the C++ standard rendered some unsafe code ill-formed or harmless, but there are still many gaps. Comprehensive lifetime analysis like that of Rust can help detect memory errors, but it often requires major changes to the code structure. This can be impractical, costly, and risky, especially for legacy code. This talk surveys mitigations available today that can help enhance the safety of our code. These mitigations include warnings and static analysis checks from MSVC, Clang, and GCC, dynamic analysis tools, and changes to the C++ language. It also explores some directions to further improve the safety of the language.

CppCon 2023 Expressive Compile-time Parsers -- Alon Wolf

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!

CppCon 2023 Expressive Compile-time Parsers

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

by Alon Wolf

Alon is a Senior Software Engineer at Medtronic specializing in 3D and computer graphics with a passion for high performance. He has developed many custom simulation and rendering engines for different platforms using modern C++. He also writes a C++ technical blog and participates in game jams.

Inside STL: The vector -- Raymond Chen

RaymondChen_5in-150x150.jpgThe C++ language comes with a standard library, and although implementations are welcome to implement the library types in whatever manner they choose, they are constraints imposed by the standard which often force one of a small number of possible implementations.

Inside STL: The vector

By Raymond Chen

The std::vector is one of those types which is constrained to the point that there’s really only one viable implementation.

Internally, a std::vector basically looks like this:

template<typename T>
struct vector
{
    T* first;
    T* last;
    T* end;
};

The first is a pointer to the beginning of a single memory allocation that holds the vector contents.

The last is a pointer one past the end of the last valid vector element.

The end is a pointer one past the end of the last allocated memory for the vector.

The picture for this is as follows:

insidestlpic-chen.png

CppCon 2023 Customization Methods: Connecting User and Library Code -- Inbal Levi

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!

Customization Methods: Connecting User and Library Code

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

by Inbal Levi

Summary of the talk:

The interface between a library and its users is a major design consideration for every developer, and has been evolving greatly over C++’s lifetime. In this talk we will go over different methods for connecting generic library code with user-side specific code, commonly known as Customization Points. We will cover the benefits and downsides of different methods (including CTS, ADL, Concepts, CTOs, and the latest to be considered - tag_invoke), and present future directions for these mechanisms.

At the end of the talk, you’ll be familiar with the terminology and developments in this field, including the ones planned for C++23 and C++26.

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.