-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GB-087 20.2.6 [obj.lifetime] std::start_lifetime_as API is broken and inconsistent for arrays #458
Comments
Proposed resolution is P2679 cplusplus/papers#1345 |
TODO: Bryce |
POLL: We want to reject the proposed resolution of GB-087.
Attendance: 20 + 3 # of Authors: 1 Author Position: SF Outcome: Strong consensus |
2022-11 Library Evolution Electronic Poll OutcomesPoll 1.12: Reject C++23 National Body comment GB-087 start_lifetime_as Is Broken And Inconsistent For Arrays as per [P2679R1] Fixing start_lifetime_as For Arrays .
Outcome: Consensus in favor. |
Rejected. There was no consensus for a change. |
The API of std::start_lifetime_as is broken and inconsistent for arrays.
First, is inconsistent with other APIs in the standard library that create objects and accept both array and non-array types, such as std::make_shared and std::make_unique. These have a version for non-array types, a version for array types of known bound, and a version for array types of unknown bound, respectively, all with the same name.
Further, the current naming is also inconsistent with itself in multiple ways: the overloads that work for arrays of unknown bound have the suffix _array in the name, but the overloads that work for arrays of known bound do not. This does not make any sense and is highly confusing for users.
In the same way that the naming is inconsistent with existing standard APIs and also with itself, the template parameters are also inconsistent. For std::start_lifetime_as, when used with an array type U[N] of known bound, the template argument that the user needs to provide is the type U[N] of the object being created (for example,
std::start_lifetime_as<int[16]>
), while for std::start_lifetime_as_array, the template argument is not the type U[] of the object being created, but the type of its elements U.Finally, the overloads for arrays of unknown bound (the ones with the suffix _array) return a pointer to the first element of the array, while the overloads without the suffix _array, when used with an array type of known bound, return a pointer to the array itself. In other words, a call to
std::start_lifetime_as_array<int>(p, 16)
will return an int*, but at the same time a call tostd::start_lifetime_as<int[16]>(p)
will return anint(*)[16]
, which makes creating and using arrays with this facility very awkward and unintuitive.Adopt the changes proposed in P2679R0.
The text was updated successfully, but these errors were encountered: