Skip to content

C++23

C++23 (ISO/IEC 14882:2024) continues the direction of C++20, further refining and extending the four pillars.

Core Features

FeatureDescription
std::expected<T,E>Return value with error type, alternative to exceptions
std::print / std::printlnModern printing, alternative to iostream
std::mdspanMultidimensional array view
std::generatorStandard coroutine generator implementation
deducing thisExplicit object parameter, eliminates CRTP and redundant code
if constevalConditional branching between compile-time and runtime
Multidimensional subscript operatormatrix[i, j] syntax
std::flat_map / flat_setContainers based on sorted vectors
import stdImport the entire standard library
std::ranges::toConstruct containers from ranges
std::views::zip / zip_transformParallel iteration over multiple ranges
std::to_underlyingConvert enum class to underlying type

Highlights

deducing this

cpp
struct Widget {
    // C++20 requires two versions (const and non-const)
    // C++23 handles both with one
    template<typename Self>
    auto&& name(this Self&& self) { return std::forward<Self>(self).name_; }
};

std::print

cpp
// No need for <iostream>, type-safe unlike printf
std::print("Hello, {}! pi = {:.2f}\n", "world", 3.14159);

import std

cpp
// One line replaces all #include
import std;

Compiler Support

CompilerSupport Status
GCC14+ (partial features)
Clang18+ (partial features)
MSVCVS 2022 17.8+ (partial features)

Further Reading

Released under the MIT License