Is there a more elegant way to do this in D?
Paul Backus
snarwin at gmail.com
Thu Apr 8 22:55:10 UTC 2021
On Thursday, 8 April 2021 at 22:27:38 UTC, Alain De Vos wrote:
> So which concrete types do you give for the two auto's.
The first `auto` is the return type of `to!(ubyte[])`--so, it's
`ubyte[]`.
The second `auto` is the return type of `map`. If you look at the
documentation [2], you'll see that it doesn't give a concrete
type for the return value; it just says that `map` returns "an
input range." That's because the concrete type is a so-called
"Voldemort type" [1]--a type whose name is private to the
function, and can't be used externally.
Why use such a type? Because it gives the authors of `map` the
freedom to change the concrete type without breaking code that
uses `map`, as long as the type they change it to still supports
the input range interface.
[1] https://wiki.dlang.org/Voldemort_types
[2]
https://phobos.dpldocs.info/std.algorithm.iteration.map.map.html
More information about the Digitalmars-d-learn
mailing list