Checking function parameters in Phobos

Meta jared771 at gmail.com
Wed Nov 20 09:58:09 PST 2013


On Wednesday, 20 November 2013 at 17:56:22 UTC, Meta wrote:
> 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?

That is, a mutating function that takes a sorted range strips the 
SortedRange wrapper and returns the underlying type.


More information about the Digitalmars-d mailing list