string_view::contains
All of the added classes are fundamentally compatible with freestanding, except for a few methods that throw (e.g. array::at). We explicitly =delete these undesirable methods.
The main driving factor for these additions is the immense usefulness of these types in practice.
Since we aren’t changing the semantics of any of the classes (except deleted non-critical methods), it is fair to say that all of the (implementer and user) experience gathered as part of hosted applies the same to freestanding.
The only question is, whether these classes are compatible with freestanding. To which the answer is yes! For example, the [Embedded Template Library] offers direct mappings of the std types. Even in kernel-level libraries, like Serenity’s [AK] use a form of these utilities.
Our decision to delete methods we can’t mark as freestanding was made to keep overload resolution the same on freestanding as hosted.
An additional benefit here is, that users of these classes, who might expect to use a throwing method, which was not provided by the implementation, will get a more meaningful error than the method simply missing. This also means we can keep options open for reintroducing the deleted functions into freestanding. (e.g. operator<<(ostream, string_view), should <ostream> be added).
The predecessor to this paper used //freestanding, partial
to mean a class (template) is only required to be partially implemented, in conjunction with //freestanding, omit
meaning a declaration is not in freestanding.
In this paper, we mark not fully freestanding classes templates as // freestanding-partial
, and use P2338's // freestanding-delete
to mark which pieces of the class should be omitted.
We no longer annotate all the class members, favoring terseness over explicitness.
In this paper, we mark std::visit as freestanding, even though it is theoretically throwing. However, the conditions for std::visit to throw are as follows:
It is possible for a variant to hold no value if an exception is thrown during a type-changing assignment or emplacement.
This means a variant will only throw on visit if a user type throws (library types don’t throw on freestanding). In this case, std::visit throwing isn’t a problem, since the user’s code is already using, and (hopefully) handling exceptions.
This however has the unfortunate side-effect that we need to keep bad_variant_access freestanding.
By getting rid of std::get, we force users to use std::get_if. Since std::get_if returns a pointer, one can only access the value of a variant by dereferencing said pointer, obtaining an lvalue, discarding the value category of the held object. This is unlikely to have an impact on application code, but might impact highly generic library code.
std::forward_like can help in these cases. The value category of the variant can be transferred to the dereferenced pointer returned from set::get_if.
A class type declaration or class template declaration in a header synopsis that is followed by a comment that includes freestanding-partial is a freestanding item, except that it contains at least one freestanding deleted function.[ Example:template <class T, size_t N> struct array; //freestanding-partial
-end example]
Subclause | Header(s) | |
---|---|---|
[…] | […] | […] |
?.? [optional] | Optional objects | <optional> |
?.? [variant] | Variants | <variant> |
?.? [string.view] | String view classes | <string_view> |
?.? [array] | Class template array |
<array> |
[…] | […] | […] |
// freestanding
comment to every item in the synopsis except:
bad_optional_access
optional
// freestanding-partial
comment to the following items:
optional
// freestanding-delete
comment to every overload of value
.
Please append a // freestanding
comment to every item in the synopsis except the get
overloads.
Please append a // freestanding-delete
comment to every get
overload in the synopsis.
// freestanding
comment to every item in the synopsis except:
basic_string_view
operator<<
// freestanding-partial
comment to the following items:
basic_string_view
//freestanding-delete
to the following items:
at
copy
substr
compare(size_type pos1, size_type n1, basic_string_view s)
compare(size_type pos1, size_type n1, basic_string_view s, size_type pos2, size_type n2)
compare(size_type pos1, size_type n1, const charT* s)
compare(size_type pos1, size_type n1, const charT* s, size_type n2)
// freestanding
comment to every item in the synopsis except array
// freestanding-partial
comment to array
// freestanding-delete
comment to every overload of at
.
#define __cpp_lib_freestanding_array 20XXXXL //also in <array> #define __cpp_lib_freestanding_optional 20XXXXL //also in <optional> #define __cpp_lib_freestanding_string_view 20XXXXL //also in <string_view> #define __cpp_lib_freestanding_variant 20XXXXL //also in <variant>