https://issues.dlang.org/show_bug.cgi?id=7145
Andrej Mitrovic changed:
What|Removed |Added
Status|NEW |RESOLVED
On 12/21/11, Philippe Sigaud philippe.sig...@gmail.com wrote:
size_t[] arrayLengths(A)(A a) if (isStaticArray!A)
{
static if (isStaticArray!(ElementType!A))
return arrayLengths(a[0]) ~ a.length;
else
return [a.length];
}
That returns an array, but I can't pass an
Ok just realized I can't use a mixin, lengths are dynamic, heheh. That
went over my head. I'll see what else I can do..
On 12/21/11, Andrej Mitrovic andrej.mitrov...@gmail.com wrote:
On 12/21/11, Philippe Sigaud philippe.sig...@gmail.com wrote:
size_t[] arrayLengths(A)(A a) if (isStaticArray!A)
I think it would be cool to have an initializedArray function, which
creates and initializes an array with a *specific* initializer. A
hardcoded example would be:
import std.array;
auto initializedArray(F:float[])(size_t size, float init)
{
auto arr = uninitializedArray!(float[])(size
Ok here's an initial implementation (I've had to put the initializer
first, otherwise I can't use variadic arguments):
http://www.ideone.com/2rqFb
I've borrowed BaseElementType from Philippe Sigaud's template book.
afternote: I didn't actually need to pass that array via ref, I'm only
modifying the elements.
Fish, and
between Fish and and, and and and And, and And and and, and and
and And, and And and and, and and and Chips, as well as after
Chips? — Martin Gardner
On Tuesday, 20 December 2011 at 12:55:18 UTC, Andrej Mitrovic
wrote:
I think it would be cool to have an initializedArray function
I would go even further, and give a *function* as an argument -
function that will be used to initialise values.
On Tue, Dec 20, 2011 at 14:22, Andrej Mitrovic
andrej.mitrov...@gmail.com wrote:
Ok here's an initial implementation (I've had to put the initializer
first, otherwise I can't use variadic arguments):
Why? That works for me:
auto initializedArray(T, I...)(I args)
if (allSatisfy!(isIntegral
On 12/20/11, Dejan Lekic dejan.le...@gmail.com wrote:
I would go even further, and give a *function* as an argument -
function that will be used to initialise values.
Well I don't know about functions yet, but I did need to use another
array as an initializer. So the new implementation takes
*Also those two templates can be merged, I just have to change the constraints.
On 12/20/11, Philippe Sigaud philippe.sig...@gmail.com wrote:
Why?
I didn't think of using tuples first, initially I've tried using
size_t[]... but that was a bad idea.
But I still think it should be the first argument, because it's more
consistent with regards to array dimensions. You never
On Tue, Dec 20, 2011 at 21:27, Andrej Mitrovic
andrej.mitrov...@gmail.com wrote:
On 12/20/11, Philippe Sigaud philippe.sig...@gmail.com wrote:
Why?
I didn't think of using tuples first, initially I've tried using
size_t[]... but that was a bad idea.
But I still think it should be the first
did need to use another
array as an initializer. So the new implementation takes care of that
via lockstep:
from : http://www.ideone.com/gKFTK :
unittest
{
auto arr2 = initializedArray!(int[][])([[1, 2], [3, 4]], 2, 2);
assert(arr2 == [[1, 2], [3, 4]]);
}
1) What's the difference
:
void main()
{
auto a = [[1, 2], [3, 4]];
auto b = a.dup;
a[0][0] = 10;
assert(b[] == [[1, 2], [3, 4]]); // fails, b[0][0] is 10
}
2) You can get the lengths of [[1,2],[3,4]], so the 2,2 args is
redundant. What happens if you type:
auto arr2 = initializedArray!(int[][])([[1, 2
copy, it only copies the first elements. The first
elements are two slices
Ah OK. Where as your version does a deep dupping, I see.
2) You can get the lengths of [[1,2],[3,4]], so the 2,2 args is
redundant. What happens if you type:
auto arr2 = initializedArray!(int[][])([[1, 2], [3, 4]], 4
http://d.puremagic.com/issues/show_bug.cgi?id=7145
Summary: Implement initializedArray in std.array
Product: D
Version: D2
Platform: Other
OS/Version: Windows
Status: NEW
Severity: enhancement
Priority: P2
http://d.puremagic.com/issues/show_bug.cgi?id=7145
Andrej Mitrovic andrej.mitrov...@gmail.com changed:
What|Removed |Added
Attachment #1056|0 |1
http://d.puremagic.com/issues/show_bug.cgi?id=7145
--- Comment #2 from Andrej Mitrovic andrej.mitrov...@gmail.com 2011-12-20
12:28:53 PST ---
Created an attachment (id=1058)
3rd version
This one adds initialization by another array's elements. Basically it's a
deep-copy.
--
Configure
19 matches
Mail list logo