Date: Wed, 30 Sep 2020 11:17:20 -0400
Based on something brought up on my post to this list "Making bit_cast
useful", I believe its reasonable to require that std::reference_wrapper<T>
have the same layout as T*. As mentioned, because this makes more sense as
a requirement on reference_wrapper, I am moving it to a separate thread.
In all implementations, std::reference_wrapper<T> is implemented with a
single field of type T*. I propose to make this the requirement, with some
limitations.
std::reference_wrapper<T> shall be a Trivially Copyable, Standard Layout
Type, which has the same size and alignment as T*. It shall be treated as
though it has a single private, *exposition-only* field of type T* called
ptr. When std::reference_wrapper<T> is constructed from a reference to type
T (after conversions) that points to an object, ptr shall be initialized to
a pointer to that object. ptr may be altered by the program. If r is an
object of type std::reference_wrapper, and p is a pointer to some object,
an assignment to an lvalue designating r.ptr from p shall be equivalent to
r = std::reference_wrapper{*p};. If p does not point to an object, whether
or not the assignment is permitted, and the result of such an assignment,
is unspecified. If the assignment is not permitted, the behaviour is
undefined (this seeks to allow the compiler to indicate to the optimizer
that the pointer member may have additional requirements, such as whether
or not the pointer is non-null or well-alligned).
useful", I believe its reasonable to require that std::reference_wrapper<T>
have the same layout as T*. As mentioned, because this makes more sense as
a requirement on reference_wrapper, I am moving it to a separate thread.
In all implementations, std::reference_wrapper<T> is implemented with a
single field of type T*. I propose to make this the requirement, with some
limitations.
std::reference_wrapper<T> shall be a Trivially Copyable, Standard Layout
Type, which has the same size and alignment as T*. It shall be treated as
though it has a single private, *exposition-only* field of type T* called
ptr. When std::reference_wrapper<T> is constructed from a reference to type
T (after conversions) that points to an object, ptr shall be initialized to
a pointer to that object. ptr may be altered by the program. If r is an
object of type std::reference_wrapper, and p is a pointer to some object,
an assignment to an lvalue designating r.ptr from p shall be equivalent to
r = std::reference_wrapper{*p};. If p does not point to an object, whether
or not the assignment is permitted, and the result of such an assignment,
is unspecified. If the assignment is not permitted, the behaviour is
undefined (this seeks to allow the compiler to indicate to the optimizer
that the pointer member may have additional requirements, such as whether
or not the pointer is non-null or well-alligned).
Received on 2020-09-30 10:17:33