C++20 and C++23 Highlights

C++20 and C++23 Highlights

Key modern language and library features worth adopting in current codebases.

C++20 and C++23 Highlights

C++20 language features

Fast interpretation

C++20 library features

void process(std::span<const int> values);
std::jthread worker([](std::stop_token) {});
auto line = std::format("value = {}", 42);

C++23 highlights

These additions continue the same direction: stronger vocabulary types, better formatting, and more expressive range composition.

Example: concepts

template <typename T>
concept Incrementable = requires(T x) {
    ++x;
};

Example: std::span

void process(std::span<const int> values);

Adoption advice

Good first upgrades for existing code

Error-handling vocabulary types

std::optional<int> maybe_port;
std::variant<int, std::string> result;
std::expected<std::string, Error> loaded_name;
std::expected<int, std::string> parse_port(std::string_view text);

Modules and coroutines in one glance

export module math;
export int add(int a, int b) { return a + b; }
task<int> compute() {
    co_return 42;
}

Quick rollout order

  1. std::span, std::string_view, [[nodiscard]]
  2. concepts, ranges, std::format
  3. std::jthread, std::expected
  4. modules and coroutines when tooling is ready

Fast wins for real codebases

Example in practice

#include <optional>

std::optional<int> value() {
    return 42;
}

Try this variation

Swap one older pattern for a newer standard facility, then compare clarity. This keeps modern C++ grounded in practical tradeoffs instead of feature tourism.

#include <format>
#include <string>

int main() {
    std::string line = std::format("{} items ready", 3);
    return static_cast<int>(line.size());
}