www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 8368] New: std.algorithm.sort's template constraint is inadequate

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8368

           Summary: std.algorithm.sort's template constraint is inadequate
           Product: D
           Version: unspecified
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: jmdavisProg gmx.com



PDT ---
This code fails to compile

import std.algorithm;

void main()
{
    auto str = ["foo", "bar"].map!(x => x);
    auto f = str.sort();
}

giving this string of errors

/home/jmdavis/dmd2/linux/bin/../../src/phobos/std/algorithm.d(7272): Error:
r[i2] is not an lvalue
/home/jmdavis/dmd2/linux/bin/../../src/phobos/std/algorithm.d(7273): Error:
r[i1] is not an lvalue
/home/jmdavis/dmd2/linux/bin/../../src/phobos/std/algorithm.d(7201): Error:
template instance std.algorithm.swapAt!(Result) error instantiating
/home/jmdavis/dmd2/linux/bin/../../src/phobos/std/algorithm.d(7285):       
instantiated from here: getPivot!(binaryFun,Result)
/home/jmdavis/dmd2/linux/bin/../../src/phobos/std/algorithm.d(7034):       
instantiated from here: sortImpl!(binaryFun,cast(SwapStrategy)0,Result)
q.d(8):        instantiated from here: sort!("a <
b",cast(SwapStrategy)0,Result)
/home/jmdavis/dmd2/linux/bin/../../src/phobos/std/algorithm.d(7285): Error:
template instance std.algorithm.getPivot!(binaryFun,Result) error instantiating
/home/jmdavis/dmd2/linux/bin/../../src/phobos/std/algorithm.d(7034):       
instantiated from here: sortImpl!(binaryFun,cast(SwapStrategy)0,Result)
q.d(8):        instantiated from here: sort!("a <
b",cast(SwapStrategy)0,Result)
/home/jmdavis/dmd2/linux/bin/../../src/phobos/std/algorithm.d(7239): Error:
r[j] is not an lvalue
/home/jmdavis/dmd2/linux/bin/../../src/phobos/std/algorithm.d(7242): Error:
r[j] is not an lvalue
/home/jmdavis/dmd2/linux/bin/../../src/phobos/std/algorithm.d(7357): Error:
template instance std.algorithm.optimisticInsertionSort!(binaryFun,Result)
error instantiating
/home/jmdavis/dmd2/linux/bin/../../src/phobos/std/algorithm.d(7034):       
instantiated from here: sortImpl!(binaryFun,cast(SwapStrategy)0,Result)
q.d(8):        instantiated from here: sort!("a <
b",cast(SwapStrategy)0,Result)
/home/jmdavis/dmd2/linux/bin/../../src/phobos/std/algorithm.d(7034): Error:
template instance std.algorithm.sortImpl!(binaryFun,cast(SwapStrategy)0,Result)
error instantiating
q.d(8):        instantiated from here: sort!("a <
b",cast(SwapStrategy)0,Result)
q.d(8): Error: template instance std.algorithm.sort!("a <
b",cast(SwapStrategy)0,Result) error instantiating

Clearly, sort's template constraint didn't properly catch the fact that the
range being passed to map wouldn't compile with sort. sort fails to even test
that the range is a random-access range! sort needs a proper template
constraint which fails to compile with any range which won't work with it
(either that or static asserts which give informative error messages when the
type isn't going to work with sort). And some of the helper functions should
probably have proper template constraints as well - e.g. the actual line that
fails to compile is in swapAt, which has no template constraint.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 10 2012
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8368


monarchdodra gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |rburners gmail.com



*** Issue 9071 has been marked as a duplicate of this issue. ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 02 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8368




Commit pushed to master at https://github.com/D-Programming-Language/phobos

https://github.com/D-Programming-Language/phobos/commit/2973b7ed2d50ca848628e7d5dcbbffbfa7f0b6ca


Issue 8368 - Insufficient constraints for sort

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 13 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8368


Alex Rønne Petersen <alex lycus.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |alex lycus.org
         Resolution|                            |FIXED


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 13 2013