// freestanding
span::at
merge conflictThis proposal is part of a group of papers aimed at improving the state of freestanding. It adds facilities that are largely unrelated to each other, but didn't fit into a better category. Most of these facilities were added in C++23, and missed the last sweep of freestanding utilities.
At a high level, this proposal adds the following facilities:
out_ptr
inout_ptr
expected
span
mdspan
On hosted implementations, the included facilities don't directly require heap allocations, don't use system calls, and don't require exceptions. The facilities are generally useful. This combination keeps the burden low for standard library implementations to single source these facilities as both hosted and freestanding.
All overloads of expected::value
are deleted, as they can throw exceptions.
This follows the precedent from P2407 "Freestanding Library: Partial Classes".
The declaration of shared_ptr
is included, but the template class is left undefined.
This allows out_ptr
and inout_ptr
to disallow certain shared_ptr
usages in the same way in hosted and freestanding.
This approach is less specification work and less implementation work, while still providing reasonable diagnostics to users if they mistakenly use shared_ptr
on a minimal freestanding implementation.
This approach still allows non-minimal freestanding implementations to provide a shared_ptr
implementation that will interact with out_ptr
and inout_ptr
the same as they do on hosted implementations.
This paper mostly follows the guide lines as specified in [P2198R6] "Freestanding Feature-Test Macros and Implementation-Defined Extensions".
However, __cpp_lib_freestanding_mdspan
is added instead of bumping __cpp_lib_mdspan
because I suspect the mdspan authors will be bumping the __cpp_lib_mdspan
macro frequently in the C++26 cycle.
When multiple orthogonal papers bump the same feature test macro, it becomes difficult for users to test for the specific features they care about.
The in flight paper [P2821] "span.at()" paper adds at()
to span
. The at()
function originates exceptions, so it will not be required to be present in a freestanding implementation. This follows the precedent set by array
in P2407 "Freestanding Library: Partial Classes".
[P0323R12 std::expected] cites usage experience on bare metal systems without exceptions enabled.
[P0009R18 MDSPAN] has a reference implementation that is usable with CUDA.
mdspan
uses span
in the implementation and interface, so the CUDA experience extends to span
as well.
The author has prototyped the necessary out_ptr
and inout_ptr
changes with MSVC's STL.
This involved #if
'ing out weak_ptr
, as well as the definitions of shared_ptr
facilities.
The tests worked as is, except for the ones specifically testing shared_ptr
.
Class template declarations followed by a comment that include freestanding-deleted are freestanding deleted class template declarations.On freestanding implementations, it is implementation-defined whether each entity introduced by a freestanding deleted class template declaration is undefined or whether the requirements are the same as the corresponding requirements for a hosted implementation.[ Note: An instantiation of an undefined template yields an incomplete class type (temp.inst#2.sentence-4). -end note][ Example:template<class T> class shared_ptr; // freestanding-deleted
-end example]
Subclause | Header(s) | |
---|---|---|
[…] | […] | […] |
?.? [expected] | Expected objects | <expected> |
?.? [views.contiguous] | Contiguous access | <span> |
?.? [views.multidim] | Multidimensional access | <mdspan> |
[…] | […] | […] |
__cpp_lib_mdspan
is intentionally left unmodified.#define __cpp_lib_freestanding_expected new-val // freestanding, also in <expected> #define __cpp_lib_freestanding_mdspan new-val // freestanding, also in <mdspan> ... #define __cpp_lib_out_ptr202106Lnew-val // freestanding, also in <memory> ... #define __cpp_lib_span202002Lnew-val // freestanding, also in <span>
Please append a // freestanding-deleted
comment to the following declaration:
shared_ptr
// freestanding
comment to the following declarations:
out_ptr_t
out_ptr
inout_ptr_t
inout_ptr
Please insert a // mostly freestanding
comment at the beginning of the [expected.syn] synopsis.
Please append a // partially freestanding
comment to every expected
declaration in the synopsis.
Please append a // freestanding-deleted
comment to every value
overload in the class synopsis.
Please append a // freestanding-deleted
comment to every value
overload in the class synopsis.
Please insert an // all freestanding
comment at the beginning of the [span.syn] synopsis.
Please insert a // mostly freestanding
comment at the beginning of the [span.syn] synopsis.
Please append a // partially freestanding
comment to the span
declaration.
Drafting note: Only apply this change if [P2821] "span.at()" has been merged.
Please append a // freestanding-deleted
comment to every overload of at
.
Please insert an // all freestanding
comment at the beginning of the [mdspan.syn] synopsis.