Unique vs. shared return values
bearophileHUGS at lycos.com
Thu Feb 2 18:31:34 PST 2012
> That side question was more like "may be the justify functions should
And my answer was: "nope".
> Otherwise, how is it possible to e.g. left-justify a string in a
> field shorter than the string? Since the function cannot achieve that
> task, perhaps it should throw. But that's just a musing...
Justify job is not to shorten the input string. So not throwing is needed, and they need to be tagged with "nothrow".
> But the main question remains: Some functions sometimes return a
> reference to passed-in data, sometimes a reference to a newly-allocated
> data. Is that a good design? Something that I've thought of just now:
> Maybe a generic copy-on-write reference type should be returned?
strongly pure functions, pure "new" for arrays, and uniqueness typing, are three solutions. We have the first already, the second is probably coming, and the third is an option for D3.
More information about the Digitalmars-d