News

It’s Great That You Provide Operator Overloads, But It’s Also Nice to Have Names -- Raymond Chen

RaymondChenPic.pngOperator overloading. Looks great. Reduces verbosity. Until it doesn’t.

It’s Great That You Provide Operator Overloads, But It’s Also Nice to Have Names

by Raymond Chen

From the article:

Consider this overloaded function call operator:

struct StorageLoader
{
    template<DataType>
    DataType operator()(StorageOptions<DataType> const* options);
};

The idea is that you can use the function call operator on a Storage­Loader object to load data from storage, using a StorageOptions to describe how you want it to be loaded.

 

CppCon 2022 Template Meta-Programming in C++ -- Kris Jusiak

Template_Meta-Programming_in_Cpp_Kris_Jusiak.pngRegistration 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 videos of some of the top-rated talks from last year's conference. Here’s another CppCon talk video we hope you will enjoy – and why not register today for CppCon 2023!

Lightning Talk: MP: Template Meta-Programming in C++

by Kris Jusiak

Summary of the talk:

In this lightning talk, Kris attempts to teach template meta-programming in 5 minutes with the use of C++20 and ranges.
 

Object Lifetime -- Ilya Doroshenko

Today, we are going to talk about an object. Without further ado, let’s dive deeper!

Object Lifetime

by Ilya Doroshenko

From the article:

What is an object? According to the C++ standard, part 3.9.8 under the name of [basic.types]

 An object type is a (possibly cv-qualified) type that is not a function type, not a reference type, and not a void type.

Now is int i an object? Yes.

Is void* p an object? Still yes, because pointers are types themselves, they are not references.

As we said, references are not types, but what if we declare something like struct S{ int& ref;}; would that be an object type? 

 

CppCon 2022 Back to Basics: Templates in C++ -- Nicolai Josuttis

CppCon_2022_Back_to_Basics_Templates_Nicolai_Josuttis.pngRegistration 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 videos of some of the top-rated talks from last year's conference. Here’s another CppCon talk video we hope you will enjoy – and why not register today for CppCon 2023!

Back to Basics: Templates in C++

by Nicolai Josuttis

Summary of the talk:

Templates are among the most powerful features of C++, but they remain misunderstood and underutilized, even as the C++ language and development community have advanced. This talk shows when and how to use modern templates to build software that's cleaner, faster, more efficient, and easier to maintain. We will cover all basic aspects of templates you have to know when programming generic code in Modern C++

Dealing with Mutation: Guarded Suspension -- Rainer Grimm

dealingwithmutation.pngGuarded Suspension applies a unique strategy to deal with mutation. It signals when it is done with its modification.

Dealing with Mutation: Guarded Suspension

by Rainer Grimm

From the article:

The guarded suspension basic variant combines a lock and a precondition that must be satisfied. If the precondition is not fulfilled, that checking thread puts itself to sleep. The checking thread uses a lock to avoid a race condition that may result in a data race or a deadlock.

Various variants of the Guarded Suspension exist:

  • The waiting thread can passively be notified about the state change or actively ask for the state change. In short, I call this push versus pull principle.
  • The waiting can be done with or without a time boundary.
  • The notification can be sent to one or all waiting threads.

I present in this post only the rough idea. Let me start with the push principle.

You often synchronize threads with a condition variable or a future/promise pair. The condition variable or the promise sends the notification to the waiting thread. A promise has no notify_one or notify_all member function. Typically, a valueless set_value call is used to ...

CppCon 2022 The Lambda Calculus in C++ Lambdas -- David Stone

cppcon-2022-the-lambda-calculus-in-cpp-lambdas-david-stone.pngRegistration 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 videos of some of the top-rated talks from last year's conference. Here’s another CppCon talk video we hope you will enjoy – and why not register today for CppCon 2023!

Lightning Talk: The Lambda Calculus in C++ Lambdas

by David Stone

Summary of the talk:

The lambda calculus is a foundation of computation equivalent in power to Turing machines.

C++17’s Useful Features for Embedded Systems -- Çağlayan Dökme

caglayan.pngRecently, our team at Meteksan Defense is upgrading its development environment to use newer versions of many tools and programming languages. One of the more difficult transitions has been the upgrade of our C++11 code base to C++17 for our embedded applications.

In this article, I will be showing some features of C++17 that can also be helpful in the embedded world.

C++17’s Useful Features for Embedded Systems

by Çağlayan Dökme

From the article:

C++14 had smaller upgrades compared to the ones we saw when migrating to C++11 from C++03. Hence, there are only a few features in C++14 that you can use in an embedded system.

Binary Literals

If you are frequently dealing with bitwise operations and modifying registers, you will love these literals. Some compilers had extensions that support such literals, but now they have a place in the actual standard.

uint8_t a = 0b110; // == 6 
uint8_t b = 0b1111'1111; // == 255 

Constraint relaxed constexpr**

With C++14, the syntax you can use in a constexpr function is expanded. Check out this post on StackOverflow. The constexpr is beneficial in the embedded world since...

CppCon 2022 import CMake, CMake and C++20 Modules -- Bill Hoffman

cppcon-2022-import-cmake-cmake-and-cpp20-modules-bill-hoffman.pngRegistration 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 videos of some of the top-rated talks from last year's conference. Here’s another CppCon talk video we hope you will enjoy – and why not register today for CppCon 2023!

import CMake, CMake and C++20 Modules

by Bill Hoffman

Summary of the talk:

Originally developed as part of the National Institutes of Health (NIH) open source medical segmentation and registration toolkit ITK in 1999, CMake has grown to take on a vital role in the C++ ecosystem. Bill Hoffman, a founder of Kitware (www.kitware.com), and the creator of CMake will talk about where CMake is in 2022. The talk will start with a brief history of CMake and how it fits into the world of C++. It will then talk about recent developments to support C++20 modules.

For most of CMake's history, CMake has played catch up and implemented new features as compilers and IDEs have been released. With C++ modules, CMake developers have engaged the standards committee and compiler vendors to help craft the standard in such a way that CMake and other build systems can more seamlessly implement C++ modules. CMake has worked with Fortran modules for many years and has updated the ninja build tool to be able to dynamically update dependency information as it is discovered. To do this CMake requires a Fortran parser built into CMake. For obvious reasons CMake does not want to get into having its own C++ parser. This is the main driving force for pushing this work into the compilers. This talk will go over the road map for CMake C++ module support.

In addition to the history of CMake, C++ module support, this talk will include material covering important CMake features supporting the seamless building, testing and deployment of C++ across most computing platforms. In summary, listeners will learn about CMake origins, the roadmap of C++ module support in CMake and get an overview of the current set of features in CMake.

Reminder: CppCon 2023 Early Bird ends next Friday

On October 2, CppCon 2023 will start with Bjarne Stroustrup's opening keynote!

If you're interested in savings, the Early Bird discount for on-line and on-site tickets is available until next Friday, June 23. After that tickets will still be available right up to the conference, but at the full ticket price.

To register for CppCon 2023, click this link.

For details of on-line and on-site tickets, see the Registration page which includes information about student registration discounts, group rates, the CppCon Academy, the Diversity Dinner, the "Meet the Presenters" banquet, and much more!

On Writing Functions That Accept Any Specialization of a C++ Template Type -- Raymond Chen

RaymondChenPic.pngSuppose you want to write a template function that accepts any specialization of std::vector? What may work today may not work tomorrow.

On Writing Functions That Accept Any Specialization of a C++ Template Type

by Raymond Chen

From the article:

Suppose you want to write a template function that accepts any specialization of std::vector. Your first try would probably be something like this:

template<typename Value>
void accept_any_vector(std::vector<Value> v);

However, this does not actually accept any vector specialization. There is a second template argument for the allocator, which has a default value that nearly everyone uses. But if somebody has a vector with a custom allocator, then your function won’t match.