On Tuesday, 4 September 2018 at 03:38:41 UTC, Nick Sabalausky
(Abscissa) wrote:
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)
<snip>
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.
I have been wanting a hybrid to a class/struct. Which is more
the C++ struct of old. Namely stack based, and inheritance. Where
it would differ is only having like 1-2 levels you could do
inheritance, namely for building very similar structures while
using the same base. Good for smaller building blocks (and
variants of a struct/idea), not for making huge projects with.