API boundaries & vocabulary types

Design7 standards

span, optional, expected, enum class, strong types.

The first wave: unique_ptr in signatures (ownership in the type), enum class (no implicit int), chrono::duration (typed time). The anti-pattern to kill: boolean and raw-integer parameters.

void connect(Endpoint ep, std::chrono::milliseconds timeout);
enum class Mode { passive, active };
void scan(Mode m);                     // not scan(bool)

chrono and string literals (100ms, "x"s) make the typed vocabulary pleasant at call sites.

The core set lands: string_view (borrowed text), optional (maybe), variant (one-of), byte (raw memory), filesystem::path. Signatures start carrying real meaning.

std::optional<Entry> find(std::string_view key);
void write(std::span<const std::byte> data);  // span itself is C++20

std::span completes the view family for contiguous data, and concepts name the requirements a template API really has.

std::expected (result-or-error), std::mdspan (multidimensional view with layout policies), std::move_only_function (owning move-only callable) round out the boundary types.

std::expected<Image, DecodeError> decode(std::span<const std::byte>);
using Grid = std::mdspan<float, std::dextents<size_t, 2>>;

std::function_ref (non-owning callable), std::optional<T&> (nullable reference), std::inplace_vector (fixed capacity, no heap) — plus std::text_encoding for naming encodings at boundaries.

void walk(const Tree&, std::function_ref<void(const Node&)> visit);
std::inplace_vector<Lane, 8> lanes;    // capacity in the type
C++29direction · not adopted

Stable; direction is mostly more views and better interop between the existing vocabulary (ranges, simd, mdspan).

C++26 per the final working draft; C++29 rows are proposals and direction, not adopted features.