www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 16033] New: std.algorithm.sorting.sort should be possible


          Issue ID: 16033
           Summary: std.algorithm.sorting.sort should be possible with
                    const/immutable object
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: phobos
          Assignee: nobody puremagic.com
          Reporter: greensunny12 gmail.com

The following yields:

void main()
    import std.algorithm.sorting : sort;
    const(int)[] arr = [1, 2, 3];

foo.d(6): Error: template std.algorithm.sorting.sort cannot deduce function
from argument types !()(const(int)[]), candidates are:
std.algorithm.sorting.sort(alias less = "a < b", SwapStrategy ss =
SwapStrategy.unstable, Range)(Range r) if ((ss == SwapStrategy.unstable &&
(hasSwappableElements!Range || hasAssignableElements!Range) || ss !=
SwapStrategy.unstable && hasAssignableElements!Range) &&
isRandomAccessRange!Range && hasSlicing!Range && hasLength!Range)

In my understanding elements can be immutable and const, but assigning elements
isn't. So shouldn't it be possible to use emplace to swap them around?

May 17 2016