Used Features of Modern C++

Used Feature

Required C++ Standard

Description

std::span

C++20

std::span can be used as a container view that does not own the memory it refers to. A std::span can be constructed from a std::vector, a std::array, or even a raw pointer and a size. It is very common in Vulkan functions to accept a pointer to some memory and an integer specifying the number of elements. std::span provides a type-safe abstraction for this pattern.

std::optional

C++17

std::optional represents an object that may or may not contain a value. It is a great tool for expressing optional values directly in code. A std::optional<T> is either engaged (holding a value of type T) or disengaged (holding no value). This is much clearer than using sentinel values like -1 or nullptr to indicate an invalid or missing value.

lambda expressions

C++11

Lambdas are a great feature that allow you to define small, inline functions anywhere in your code.

constexpr

C++11

Constant expressions are powerful for a variety of reasons. Most importantly, anything declared as constexpr or const is thread-safe by default.

thread_local (thread-local storage, TLS)

C++11

The thread_local keyword allows you to define variables that are unique to each thread, which helps to avoid race conditions.

std::move

C++11

Move semantics are an important feature that allow the programmer to optimize performance by transferring resources instead of copying them unnecessarily.

default member initializer

C++11

A simple and convenient way of initializing member variables directly in their declaration, without needing a constructor initializer list.

deleted functions

C++11

Declaring a function as deleted explicitly prevents it from being used.

std::string_view

C++17

A non-owning view into a string.

std::this_thread

C++11

Provides access to thread-related functionality.

auto keyword

C++11

The auto keyword avoids unnecessary repetition of long or complex type names.

std::source_location

C++20

Provides access to information about the source code location (e.g., file name, line number, function name).

aggregate initialization

C++11

Simplifies initializing structs, especially useful for Vulkan structs.

designated initialization

C++20

Allows explicit member initialization using names, making struct initialization clearer and less error-prone.

<random>

C++11

Standard library facilities for generating pseudo-random numbers.

[[nodiscard]] attribute

C++17

Specifies that the return value of a function should not be ignored.

if with initializer

C++17

Useful for defining and initializing a variable that is only used within the scope of an if or switch statement.

std::filesystem

C++17

Provides facilities for interacting with the file system.

enum class

C++11

Defines scoped enumerations, avoiding name clashes and improving type safety.

Smart pointers

C++11

Used for automatic memory management and avoiding manual delete calls. Includes std::unique_ptr, std::shared_ptr, and std::weak_ptr.

std::make_unique

C++14

Safely creates and returns a std::unique_ptr to a new object.

std::make_shared

C++14

Safely creates and returns a std::shared_ptr to a new object.

nullptr

C++11

A type-safe replacement for NULL or 0 when representing a null pointer.

range-based for loops

C++11

Simplifies iteration over containers.

std::forward

C++11

Used in template programming for perfect forwarding of arguments.

std::function

C++11

A general-purpose wrapper for callable objects (functions, lambdas, functors, etc.).

std::shared_lock

C++14

Used for shared (read) access in synchronization primitives like std::shared_mutex.

std::format

C++20

Provides type-safe, modern string formatting functionality (similar to Python’s format).

constexpr if

C++17

Allows compile-time conditional branching, enabling cleaner and more efficient template code.

structured binding declaration

C++17

Declare multiple variables at once by decomposing a returned object, such as an array, tuple, pair, or struct.

concepts

C++20

Allows template parameters to be constrained with compile-time requirements, making templates safer and easier to read and use.

std::ranges

C++20

Generalization of the algorithms and iterator libraries that makes them more powerful by making them composable and less error-prone.