Skip to content

Support C++20 span types #1747

Description

@legendecas

node-addon-api's buffer-like types pass their backing memory as a raw pointer plus a separate length, both on the way out (Data() + a length accessor) and on the way in (the New/Copy factories). Callers must keep the two values in sync manually, with no bounds information attached to the pointer.

Once C++20 is the minimum supported standard, we should adopt std::span in both directions. These additions are ABI-compatible (existing pointer/length overloads stay), and give callers a single bounds-carrying handle that works with range-based for, <algorithm>, and <ranges>.

This can be an additive change with a C++ version guard.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions