C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Static-layout types

From: Jens Maurer <Jens.Maurer_at_[hidden]>
Date: Sat, 23 Apr 2022 14:57:36 +0200
On 23/04/2022 12.04, Lauri Vasama via Std-Proposals wrote:
> Hello,
>
> I am looking for feedback on a proposal which concerns a new property of types which I call static layout types. In short these are types which layouts do not vary between objects of type. In practice it excludes types employing virtual inheritance.
>
> https://vasama.github.io/wg21/static-layout

The paper is very slim on motivation. Why do you need
this additional property in the standard?

Just to have a type trait for it seems a bit underwhelming,
since you can't do anything with the query result portably.

As far as I understand, offsetof exists primarily for C
compatibility, so I have little appetite to generalize it
or broaden its applicability beyond "obviously" C-compatible
struct types.

Oh, and a class type with virtual base classes also satisfies
the property that the layout of the object is the same
for all objects of such a class type.

Jens


> I included some wording, but it undoubtedly requires more work. I am also not yet decided on whether the larger concept of /static-//layout type/ is really needed, or if /static//-layout class/ is sufficient.
>
> Beyond offsetof, there are some potential future features which would benefit from the concept of static layout, such as deriving an offset from a pointer-to-data-member of a /static-layout class/, or deriving a reference to an object from a reference to a member subobject and a matching pointer-to-data-member, as was discussed last december [1].
>
> [1] https://github.com/SciresM/containing_object_of_member/blob/master/containing_object_of_member.pdf
>
>

Received on 2022-04-23 12:57:42