```
import std.stdio;
void main(){
auto a=new int[][] (0,0);
a~=[1,2];
a~=[3,4];
auto b= a.dup;
a[0]=[5,6];
a[1][1]=7;
writeln(b);
}
```
Program above outputs [[1, 2], [3, 7]]
Which means a[1][1] and b[1][1] point to the same memory location.
But a[0] occupies a different memory location as
On Wednesday, 2 June 2021 at 15:32:38 UTC, Sean wrote:
...
You can implement deep copy using template recursion:
import std;
T[] rdup(T : U[], U)(T[] duped) {
return duped.map!(arr => arr.rdup).array;
}
T[] rdup(T)(T[] duped) {
return duped.dup;
}
On Wednesday, 2 June 2021 at 17:50:13 UTC, Sean wrote:
On Wednesday, 2 June 2021 at 15:32:38 UTC, Sean wrote:
if so, how can I get the behavior i am searching for? Thank
you.
My current solution, if anyone wonders :
https://github.com/patefacio/d-help/blob/master/d-help/opmix/dup.d
You may
On Wednesday, 2 June 2021 at 15:32:38 UTC, Sean wrote:
if so, how can I get the behavior i am searching for? Thank you.
My current solution, if anyone wonders :
https://github.com/patefacio/d-help/blob/master/d-help/opmix/dup.d
On Wednesday, 2 June 2021 at 16:50:16 UTC, Gavin Ray wrote:
On Wednesday, 2 June 2021 at 16:07:35 UTC, Basile.B wrote:
works a expected. The reason why is that your array elements
are fat pointers, so when you dup a, you dup some fats
pointer, so you got the same elements as "a" but accessible
On Wednesday, 2 June 2021 at 16:07:35 UTC, Basile.B wrote:
works a expected. The reason why is that your array elements
are fat pointers, so when you dup a, you dup some fats pointer,
so you got the same elements as "a" but accessible from another
chunck of memory.
Would it be worth
On 6/2/21 11:32 AM, Sean wrote:
Is this normal behavior of dup? if so, how can I get the behavior i am
searching for? Thank you.
Yes. `dup` is a shallow copy.
To get the behavior you want:
```d
auto deepdup(T)(T[] arr)
{
import std.algorithm, std.array;
static if(is(T == U[], U))
On Wednesday, 2 June 2021 at 16:18:03 UTC, Basile.B wrote:
Maybe Mir would help.
Tried.
However, I am more of a mathematician, than a software developer.
So writing my own code was easier than to follow through the
design philosophy and internalize the idioms and styles of Mir.
When this
On Wednesday, 2 June 2021 at 16:08:14 UTC, Sean wrote:
On Wednesday, 2 June 2021 at 15:59:38 UTC, Basile.B wrote:
works as you expect
Okey, so I have to copy every (N-1) dimensional element - one
after one - if the array is N dimensional, with N > 1, and
repeat it for every element if they
On Wednesday, 2 June 2021 at 15:59:38 UTC, Basile.B wrote:
On Wednesday, 2 June 2021 at 15:32:38 UTC, Sean wrote:
works as you expect
On Wednesday, 2 June 2021 at 15:59:38 UTC, Basile.B wrote:
```d
import std;
void main() {
auto a = new double[][] (0,0);
a ~= [ 1.0, 2.45];
a ~=
On Wednesday, 2 June 2021 at 15:59:38 UTC, Basile.B wrote:
works as you expect
Okey, so I have to copy every (N-1) dimensional element - one
after one - if the array is N dimensional, with N > 1, and repeat
it for every element if they themselves are arrays with dimension
M > 1 ?
This
On Wednesday, 2 June 2021 at 15:32:38 UTC, Sean wrote:
Hello
I have seen this :
https://forum.dlang.org/thread/1473526717.1917.20.ca...@winder.org.uk
Now, please consider this code:
import std.stdio;
import std.math;
import std.stdio;
import std.conv;
import std.format;
import std.math;
Hello
I have seen this :
https://forum.dlang.org/thread/1473526717.1917.20.ca...@winder.org.uk
Now, please consider this code:
import std.stdio;
import std.math;
import std.stdio;
import std.conv;
import std.format;
import std.math;
import std.algorithm;
import std.net.curl;
import
13 matches
Mail list logo