Understanding C++ value categories

Slide header

Masterclass on value categories in C++.

Abstract

In C++ today, do you know what an xvalue is? Or a prvalue? Why would you want to know? Because it matters! In C++, each expression is characterized by a value category. These value categories are used to describe parts of the C++ standard, and are often used in books and articles. You might have heard of terms like ’lvalue’ or ‘rvalue’, which are the most commonly known ones. Over the years, changes to the C++ language changed the meaning of value categories. This means a lot of information about value categories is outdated or just plain wrong. In this talk, I will explain what expression value categories are in today’s C++ standard. It turns out that knowledge about value categories can really be beneficial. Not only will it enrich your understanding of C++ in general, it will deepen your understanding of mechanisms like move semantics. Also, it can help you to make better choices about code. These choices can then leverage language rules to enable compilers to generate efficient code without redundant copies. Other, related topics that will be covered: copy elision, return value optimization, temporary materialization.

Audience

This session is for professionals in software engineering, level novice to advanced, interested in C++. In-depth knowledge of value categories in C++ is an enabler for further advanced development (e.g. on move semantics).

Topic listing

These are the main topics addressed in the talk:

  1. What are value categories?
  • Expressions in C++
  • The value categories in C++
  • History of value categories
  1. Value categories in the wild
  • Copy elision
  • Guaranteed copy elision
  • Temporary materialization
  • Copy/move elision since C++17
  • Return value optimization (RVO)
  • Function call mechanics

Conferences

A slimmed-down version of this session was presented at C++ Day 2020, of the Italian C++ community, see here for the recording.