Using C++20 and C++23

Using C++20 and C++23

Start adopting modern language and library features that pay off quickly.

Using C++20 and C++23

High-value features to adopt early

Example: std::span

void print_all(std::span<const int> values) {
    for (int value : values) {
        std::cout << value << '\n';
    }
}

Example: concepts

template <typename T>
concept Printable = requires(T value) {
    std::cout << value;
};

Adoption strategy

Add modern features where they improve readability immediately. Do not rewrite stable code just to chase newer syntax.

More library features worth knowing

Example: std::expected

std::expected<int, std::string> parse_count(std::string_view text) {
    if (text.empty()) {
        return std::unexpected("empty input");
    }
    return 42;
}

Modules and coroutines

These two features are real parts of modern C++, but they require more build-system and library support than features like std::span or concepts. Adopt them deliberately rather than mechanically.

Practical rollout order

Start with concepts, ranges, std::span, std::string_view, std::format, and std::expected. Move to modules and coroutines when your toolchain, CI, and surrounding libraries are ready.