C++ Logo

std-proposals

Advanced search

Explicit Order

From: Ryan Nicholl <rnicholl_at_[hidden]>
Date: Thu, 27 Feb 2020 16:37:27 +0000
Imagine for a moment you have a structure,

struct foo
{
bar a;
baz b;
bing c;
};

Now, what if we want to change the order of initialization of the members, we have to reorder them. This might cause problems if the order "a b c" in the struct is optimal for performance cache wise, but the members must actually be initialized in the order "c a b".

Currently this must be done with placement new... not terse!

I propose the following, in any class or struct, allow "explicit order { ... };" declaration. Where "order" is a contextual keyword.

E.g.

struct foo
{
bar a;
baz b;
bing c;

explicit order { c, a, b };
};

Now all constructors/destructors will run in the order of construction, c, a, then b, but the binary ABI layout is still a b c.

Received on 2020-02-27 10:40:14