When Andrei Alexandrescu [introduced][on-iteration] ranges to the [D programming language][D], the gap between built-in and user-defined types (UDTs) narrowed, enabling new abstractions and greater composability. Even today though, UDTs are still second-class citizens in D. One example of this is support for head-mutability - the ability to manipulate a reference without changing the referenced value(s). This document details a pattern that will further narrow the UDT gap, by introducing functions for defining and working with head-mutable user-defined types.
[D][D] is not [Kernel][kernel] or [Scheme][scheme] - it has first-class and second-class citizens. Among its first-class citizens are arrays and pointers. One of the benefits these types enjoy is implicit conversion to head-mutable - for instance, const(T[])
is implicitly convertible to const(T)[]
. Partly to address this difference, D has many ways to define ho