Article

Using C++17 std::optional

Unknown ·C++ Stories ·Published 2026-09-28 ·5 min read

This article describes std::optional, a helper type added in C++17 that can either contain a value or be empty. It discusses its usefulness and how it enhances type safety and expressiveness in C++ programming.

From the article

Let’s take a pair of two types <YourType, bool> - what can you do with such composition?

In this article, I’ll describe std::optional - a helper “vocabulary” type added in C++17. It’s a wrapper that either contains a value of your type or is empty. Let’s see where it can be useful and how you can use it.

By adding the boolean flag to other types, you can achieve a thing called “nullable types”. As mentioned, the flag is used to indicate whether the value is available or not. Such wrapper represents an object that might be empty in an expressive way (so not via comments :))


Share this resource


Discovered 2026-09-29 Source C++ Stories Archive 2026-09 →