We have classes and structs:

Classes:
- Default Storage: GC Heap
- Indirection Overhead: Yes
- Semantics: Reference
- Passed By: Copying the Data's Address

Structs:
- Default Storage: Stack
- Indirection Overhead: No
- Semantics: Value
- Passed By: Copying the Data (except where the compiler can determine it can safely and more efficiently pass by reference...at least, IIUC)

But we seem to have a lot of need for stuff in-between: emplace for classes, @disable this and move/moveEmplace for structs.

Just tossing this out there: What if there was a third version, an alternate to struct that: - Prohibited implicit copying (perhaps unless the compiler knew the original was never used again?) - Was always passed by moving (except where the compiler can determine it can safely and more efficiently pass by reference)? - And, after passing it to a function, it would automatically be moved back to the caller (unless compiler can determine it doesn't have to bother).

Ie:
Move-Structs:
- Default Storage: Stack
- Indirection Overhead: No
- Semantics: Reference-like
- Passed By: Moving the Data (except where compiler...blah blah blah)

IIUC, this would give it the *effect* of reference semantics, but without the indirection (and vtable) overhead, and would allow it to perform RAII cleanup in its dtor when it goes out of scope without ever needing reference counting.

Is this nothing more than reinventing the future "struct with copy constructor and @disable-ed default constructor...and...maybe some other necessary part of the idiom I'm overlooking"?

Is it really just (badly) re-inventing some other XYZ except for differences UVW?

Or would this be a horrible thing to exist?

Any tweaks that would change it from a horrible idea to a fantastic one?

Or is it all just total nonsense?

Reply via email to