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
Key modern language and library features worth adopting in current codebases.
consteval, constinit<=>)<=>: default comparison for value typesstd::spanstd::jthreadstd::formatstd::source_locationvoid process(std::span<const int> values);
std::jthread worker([](std::stop_token) {});
auto line = std::format("value = {}", 42);
std::expectedstd::printstd::mdspanstd::optionalThese additions continue the same direction: stronger vocabulary types, better formatting, and more expressive range composition.
template <typename T>
concept Incrementable = requires(T x) {
++x;
};
std::spanvoid process(std::span<const int> values);
std::span, and ranges early.std::spanstd::expectedstd::thread ownership -> std::jthreadstd::formatstd::optional<int> maybe_port;
std::variant<int, std::string> result;
std::expected<std::string, Error> loaded_name;
std::optional<T>: a value may be absent.std::variant<...>: one of several closed alternatives.std::expected<T, E>: either a value or a typed error.std::expected<int, std::string> parse_port(std::string_view text);
export module math;
export int add(int a, int b) { return a + b; }
task<int> compute() {
co_return 42;
}
std::span, std::string_view, [[nodiscard]]std::formatstd::jthread, std::expected[[nodiscard]] for error-prone APIs.<=> for value objects with natural ordering.std::span, std::string_view, std::expected, and std::jthread in new code when they match the design.#include <optional>
std::optional<int> value() {
return 42;
}
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());
}