Unique vs. shared return values

Ali Çehreli acehreli at yahoo.com
Thu Feb 2 17:48:47 PST 2012


On 02/02/2012 04:31 PM, bearophile wrote:
 > Ali:
 >
 >> - either a slice of the entire input string when the field is shorter
 >> than the string (this is an optimization)
 >
 >> [A side question is whether leftJustify() should throw when the field
 >> width is shorter than the string.
 >
 > When the field width is shorter than the input string the three 
justify functions just don't add whitespace. So they are nothrow.
 >
 > Bye,
 > bearophile

That side question was more like "may be the justify functions should 
throw". 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...

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?

Looking for opinions and experiences...

Ali



More information about the Digitalmars-d mailing list