head const (again), but for free?
Ola Fosheim Grøstad
ola.fosheim.grostad at gmail.com
Mon Jan 11 17:15:39 UTC 2021
So, I find that I increasingly miss head-const for immutable. And
I understand that people don't want yet another way to modify the
access patterns for a type, but maybe it is possible to avoid
that, and do both.
So here is the idea:
Introduce "readonly" as head-immutable. That means that all
values in an immutable array are immutable, including the address
of reference, but not the objects being pointed to.
Then let "immutable" types be redefined to be a recursion of
"readonly applications!
When you test a type for "immutable" the the checker would then
not actually test for immutable, but test that the composite type
is "readonly" at all levels.
Then we have two variants for the price of one!
What are the gotchas?
(You could probably do the same with const, but I think immutable
has some potential performance benefits.)
More information about the Digitalmars-d
mailing list