shared_ptr// freestandingspan::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_ptrinout_ptrexpectedspanmdspanOn 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".
out_ptr and inout_ptr have mandates involving shared_ptr.
shared_ptr is not freestanding.
This paper leaves those mandates in place, without changing the freestanding status of shared_ptr.
Implementations are expected to #if out those mandates as needed.
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 shared_ptr and weak_ptr facilities, as well as one static_assert in out_ptr_t and one static_assert in inout_ptr_t.
The tests worked as is, except for the ones specifically testing shared_ptr.
| 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 comment to the following declarations:
out_ptr_tout_ptrinout_ptr_tinout_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.