D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 4346 - More flexible std.array.array
Summary: More flexible std.array.array
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: x86 Windows
: P2 normal
Assignee: No Owner
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2010-06-19 06:32 UTC by bearophile_hugs
Modified: 2010-08-18 17:55 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description bearophile_hugs 2010-06-19 06:32:28 UTC
Dmd v2.047 rejects all the following programs:


import std.array: array;
void main() {
    int[2] a = [1, 2];
    assert(array(a) == [1, 2]);
}


import std.container: SList;
import std.array: array;
void main() {
    auto l = SList!int(1, 2);
    assert(array(l) == [1, 2]);
}


import std.container: SList;
import std.array: array;
void main() {
    auto l = SList!int(1, 2);
    assert(array(l[]) == [1, 2]);
}


If a collection can be iterated with foreach, and its items can be copied, then array() has to work on it (and use the Appender for performance where the length of the collection is not known).

See also bug 4114
Comment 1 David Simcha 2010-08-18 17:55:40 UTC
Fixed in changeset 1898.  http://dsource.org/projects/phobos/changeset/1898