Why dtor are not executed when removing a struct from associative arrays?

2021-09-20 Thread Learner via Digitalmars-d-learn
I was expecting something like going out of scope for that ```(D) import std.stdio; struct S { ~this() { writeln("S is being destructed"); } } void main() { S[int] aa; aa[1] = S(); aa.remove(1); writeln("Why no dtor call on remove?"); } I was expecting

Re: I do not understand copy constructors

2021-08-12 Thread Learner via Digitalmars-d-learn
On Thursday, 12 August 2021 at 16:12:39 UTC, Paul Backus wrote: On Thursday, 12 August 2021 at 15:39:40 UTC, Learner wrote: [...] You have forgotten to add a member variable of type `A` to your `B` struct. If you add one, you will see the following error message: [...] "implicit

Re: I do not understand copy constructors

2021-08-12 Thread Learner via Digitalmars-d-learn
On Thursday, 12 August 2021 at 15:50:05 UTC, Tejas wrote: On Thursday, 12 August 2021 at 15:39:40 UTC, Learner wrote: On Thursday, 12 August 2021 at 14:57:16 UTC, Steven Schveighoffer wrote: [...] It is not clear to me why the inout generated copy constructor of the B structure is not able

Re: I do not understand copy constructors

2021-08-12 Thread Learner via Digitalmars-d-learn
On Thursday, 12 August 2021 at 14:57:16 UTC, Steven Schveighoffer wrote: On 8/12/21 10:08 AM, Learner wrote: On Thursday, 12 August 2021 at 13:56:17 UTC, Paul Backus wrote: On Thursday, 12 August 2021 at 12:10:49 UTC, Learner wrote: That worked fine, but the codebase is @safe: ```d cast

Re: I do not understand copy constructors

2021-08-12 Thread Learner via Digitalmars-d-learn
On Thursday, 12 August 2021 at 13:56:17 UTC, Paul Backus wrote: On Thursday, 12 August 2021 at 12:10:49 UTC, Learner wrote: That worked fine, but the codebase is @safe: ```d cast from `int[]` to `inout(int[])` not allowed in safe code ``` So copy constructors force me to introduce trusted

Re: I do not understand copy constructors

2021-08-12 Thread Learner via Digitalmars-d-learn
On Thursday, 12 August 2021 at 11:32:03 UTC, Paul Backus wrote: On Thursday, 12 August 2021 at 11:19:34 UTC, drug wrote: ```D struct A { int[] data; this(ref return scope inout A rhs) /* no inout here */ { data = rhs.data.dup; } } ``` The problem is that if you qualify the ctor itself

Re: I do not understand copy constructors

2021-08-12 Thread Learner via Digitalmars-d-learn
On Thursday, 12 August 2021 at 11:07:24 UTC, drug wrote: 12.08.2021 12:36, Learner пишет: > It seems that there is no easy way to transition from a postblit to a copy constructor, no? You just need both const and mutable copy ctors to replace inout one: ```D struct A { int[] data;

Re: I do not understand copy constructors

2021-08-12 Thread Learner via Digitalmars-d-learn
On Thursday, 12 August 2021 at 10:10:17 UTC, rikki cattermole wrote: On 12/08/2021 9:36 PM, Learner wrote: It seems that there is no easy way to transition from a postblit to a copy constructor, no? struct Foo { this(ref Foo other) { foreach(i, v; other.tupleof)

Re: I do not understand copy constructors

2021-08-12 Thread Learner via Digitalmars-d-learn
On Thursday, 12 August 2021 at 09:14:02 UTC, Paul Backus wrote: On Thursday, 12 August 2021 at 08:42:27 UTC, Learner wrote: struct A { int[] data this(ref return scope A rhs) { data = ths.data.dup; } } Generating an `inout` copy constructor for `struct B` failed,

I do not understand copy constructors

2021-08-12 Thread Learner via Digitalmars-d-learn
I have a structure like, used by other structures: struct A { int[] data; this(this) { data = data.dup; } } I am trying to upgrade it to use copy constructor: struct A { int[] data this(ref return scope A rhs) { data = ths.data.dup; } }

Re: variant visit not pure?

2020-05-07 Thread learner via Digitalmars-d-learn
On Thursday, 7 May 2020 at 14:53:10 UTC, Steven Schveighoffer wrote: On 5/7/20 5:22 AM, learner wrote: [...] Because VariantN (the base of Algebraic) can literally hold anything, it cannot be pure, @safe, nothrow, @nogc. As others have recommended, I suggest using TaggedAlgebraic. I

Re: variant visit not pure?

2020-05-07 Thread learner via Digitalmars-d-learn
On Thursday, 7 May 2020 at 10:41:01 UTC, Simen Kjærås wrote: On Thursday, 7 May 2020 at 09:22:28 UTC, learner wrote: Good morning, Is there a reason why std.variant.visit is not inferring pure? ``` void test() pure { Algebraic!(int, string) alg; visit!( (string) => 0, (int) =>

variant visit not pure?

2020-05-07 Thread learner via Digitalmars-d-learn
Good morning, Is there a reason why std.variant.visit is not inferring pure? ``` void test() pure { Algebraic!(int, string) alg; visit!( (string) => 0, (int) => 0)(alg); } Error: pure function test cannot call impure function test.visit!(VariantN!(16LU, int, string)).visit ``` Thank

Re: Retrieve the return type of the current function

2020-05-06 Thread learner via Digitalmars-d-learn
On Wednesday, 6 May 2020 at 08:04:16 UTC, Jacob Carlborg wrote: On 2020-05-05 19:11, learner wrote: On Tuesday, 5 May 2020 at 16:41:06 UTC, Adam D. Ruppe wrote: typeof(return) Thank you, that was indeed easy! Is it possible to retrieve also the caller return type? Something like: Yes,

Re: std.uni, std.ascii, std.encoding, std.utf ugh!

2020-05-06 Thread learner via Digitalmars-d-learn
On Tuesday, 5 May 2020 at 19:24:41 UTC, WebFreak001 wrote: On Tuesday, 5 May 2020 at 18:41:50 UTC, learner wrote: Good morning, Trying to do this: ``` bool foo(string s) nothrow { return s.all!isDigit; } ``` I realised that the conversion from char to dchar could throw. I need to validate

std.uni, std.ascii, std.encoding, std.utf ugh!

2020-05-05 Thread learner via Digitalmars-d-learn
Good morning, Trying to do this: ``` bool foo(string s) nothrow { return s.all!isDigit; } ``` I realised that the conversion from char to dchar could throw. I need to validate and operate over ascii strings and utf8 strings, possibly in separate functions, what's the best way to transition

Re: Retrieve the return type of the current function

2020-05-05 Thread learner via Digitalmars-d-learn
On Tuesday, 5 May 2020 at 16:41:06 UTC, Adam D. Ruppe wrote: typeof(return) Thank you, that was indeed easy! Is it possible to retrieve also the caller return type? Something like: ``` int foo() { return magic(); } auto magic(maybesomedefaulttemplateargs = ??)() { alias R =

Retrieve the return type of the current function

2020-05-05 Thread learner via Digitalmars-d-learn
Good morning, Is it possible something like this? ``` int foo() { __traits(some_trait, some_generic_this) theInt = 0; ``` I mean, without using the function name in the body, like ReturnType!foo ?

How define such scheleton classes

2016-07-15 Thread Learner via Digitalmars-d-learn
abstract class AbstractObject(S) if (IsSomeString!S) { } class OtherObject(S, bool R) : AbstractObject!S { int x; void Foo(int a, int b) { x = a + b; static if (R) // error { // more codes . } } } class OtherObjects(S) :

Re: get number of columns and rows in an ndarray.

2016-06-15 Thread learner via Digitalmars-d-learn
On Wednesday, 15 June 2016 at 21:54:22 UTC, Seb wrote: On Wednesday, 15 June 2016 at 21:51:25 UTC, learner wrote: Hi, How can i get the number of cols and rows in and ndarray that has already been created? learner how about `shape`?

get number of columns and rows in an ndarray.

2016-06-15 Thread learner via Digitalmars-d-learn
Hi, How can i get the number of cols and rows in and ndarray that has already been created? learner

Re: How can convert the folowing to D.

2016-04-01 Thread learner via Digitalmars-d-learn
On Friday, 1 April 2016 at 01:09:32 UTC, Ali Çehreli wrote: On 03/31/2016 05:34 PM, learner wrote: Hi, I have the following code in C++. rectangles.erase(rectangles.begin() + index); where rectangles is: std::vector rectangles; how can I do something similar in D. Learner. import

How can convert the folowing to D.

2016-03-31 Thread learner via Digitalmars-d-learn
Hi, I have the following code in C++. rectangles.erase(rectangles.begin() + index); where rectangles is: std::vector rectangles; how can I do something similar in D. Learner.