std.algorithm.remove and principle of least astonishment

Bruno Medeiros brunodomedeiros+spam at com.gmail
Wed Nov 24 05:07:31 PST 2010


On 22/11/2010 04:56, Andrei Alexandrescu wrote:
> On 11/21/10 22:09 CST, Rainer Deyke wrote:
>> On 11/21/2010 17:31, Andrei Alexandrescu wrote:
>> char[] and wchar[] fail to provide some of the guarantees of all other
>> instances of T[].
>
> What exactly are those guarantees?
>

More exactly, that the following is true for any T: 	

	foreach(character; (T[]).init) {
		static assert(is(typeof(character) == T));
	}
	static assert(std.range.isRandomAccessRange!(T[]));

It is not true for char and wchar (the second assert fails).
Another guarantee, similar in nature, and roughly described, is that 
functions in std.algorithm should never fail or throw when using an 
array as a argument (assuming the other arguments are valid). So for 
example:

	std.algorithm.filter!("true")(anArray)

Should not throw, for any value of anArray. But it may if anArray is of 
type char[] or wchar[] and there is an encoding exception.


I'll leave the arguing of whether we want those guarantees for other 
subthreads, but it should be well agreed by now, that the above is not 
guaranteed.


-- 
Bruno Medeiros - Software Engineer


More information about the Digitalmars-d mailing list