Checking function parameters in Phobos
Meta
jared771 at gmail.com
Wed Nov 20 09:56:21 PST 2013
On Wednesday, 20 November 2013 at 14:14:28 UTC, Timon Gehr wrote:
> On 11/20/2013 02:52 PM, Jacob Carlborg wrote:
>> On 2013-11-20 13:56, Timon Gehr wrote:
>>
>>> We do in any case:
>>>
>>> import std.algorithm, std.range;
>>>
>>> void main(){
>>> auto a = [1,2,3,4,5];
>>> auto s = sort(a);
>>> swap(a[0],a[$-1]);
>>> assert(is(typeof(s)==SortedRange!(int[])) &&
>>> !s.isSorted());
>>> }
>>>
>>
>> I don't understand what this is supposed to show. That the
>> type is
>> "SortedRange" but it's actually not sorted?
>>
>
> Yes, hence SortedRange being sorted is just a convention in any
> case.
Couldn't we have an overload of each of the mutating functions in
std.algorithm that takes a SortedRange and does static assert(0,
"Cannot modify a sorted range")? I suppose there are cases where
we *want* to mutate a sorted range... Unwrap the inner type,
maybe?
More information about the Digitalmars-d
mailing list