digitalmars.D.bugs - [Issue 8409] New: Proposal: implement arr.dup in library
- d-bugmail puremagic.com (46/46) Jul 22 2012 http://d.puremagic.com/issues/show_bug.cgi?id=8409
- d-bugmail puremagic.com (10/10) Sep 09 2012 http://d.puremagic.com/issues/show_bug.cgi?id=8409
http://d.puremagic.com/issues/show_bug.cgi?id=8409
Summary: Proposal: implement arr.dup in library
Product: D
Version: D2
Platform: All
OS/Version: All
Status: NEW
Severity: enhancement
Priority: P2
Component: druntime
AssignedTo: nobody puremagic.com
ReportedBy: k.hara.pg gmail.com
If issue 8408 is fixed, we can use following dup function definition.
template hasMutableIndirection(T)
{
enum hasMutableIndirection = !is(typeof({ Unqual!T t = void; immutable T u
= t; }));
}
static assert(!hasMutableIndirection!(int));
static assert(!hasMutableIndirection!(int[3]));
static assert( hasMutableIndirection!(Object));
property auto dup(E)(inout(E)[] arr) pure trusted
{
static if (hasMutableIndirection!E)
{
auto copy = new E[](arr.length);
copy[] = cast(E[])arr[]; // assume constant
return cast(inout(E)[])copy; // assume constant
}
else
{
auto copy = new E[](arr.length);
copy[] = arr[];
return copy;
}
}
In above dup function,
- If E has some mutable indirections, returns inout(E) and has constant purity.
- If E has no mutable indirections, return E[] and has string purity.
That means: return value is implicitly convertible to immutable(E)[] with
issue 5081, and can make a immutable duplication from mutable array.
Finally, we can remove the duplication of built-in dup/idup.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 22 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8409
Kenji Hara <k.hara.pg gmail.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |pull
https://github.com/D-Programming-Language/druntime/pull/298
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 09 2012








d-bugmail puremagic.com