C++ Logo

STD-PROPOSALS

Advanced search

Subject: [std-proposals] Explicit Order
From: Ryan Nicholl (rnicholl_at_[hidden])
Date: 2020-02-27 10:37:27


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.



STD-PROPOSALS list run by herb.sutter at gmail.com

Standard Proposals Archives on Google Groups