www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 12029] New: Swap on std.container.Array?

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

           Summary: Swap on std.container.Array?
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: bearophile_hugs eml.cc



I'd like to use std.algorithm.swap on the items of std.array.Array.

Currently it's not possible, as shown here:

void main() {
    import std.container: Array;
    import std.range: hasSwappableElements;
    auto arr = Array!int([1, 2]);
    pragma(msg, hasSwappableElements!(typeof(arr)));
}

With dmd 2.065beta it outputs at compile time:

false


Current workaround is to swap the items manually:

void main() {
    import std.container: Array;
    auto arr = Array!int([1, 2]);
    // Swap:
    auto aux = arr[0];
    arr[0] = arr[1];
    arr[1] = aux;
    assert(arr[0] == 2 && arr[1] == 1);
}


If std.container.Array was designed this way on purpose, perhaps to keep its
memory tightly sealed inside the container itself, then close down this
enhancement request.

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 29 2014
parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=12029


Peter Alexander <peter.alexander.au gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |peter.alexander.au gmail.co
                   |                            |m



11:57:12 PST ---
They should be swappable once the containers are unsealed.

https://github.com/D-Programming-Language/phobos/pull/1857

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 29 2014