Re: Meaning of the dot-function syntax

2023-10-01 Thread dhs via Digitalmars-d-learn
On Sunday, 1 October 2023 at 09:20:32 UTC, Anonymouse wrote: On Sunday, 1 October 2023 at 08:22:48 UTC, dhs wrote: Hi, What's the meaning of the dot in the call to writeln() below? ```d .writeln("Hello there!"); ``` I haven't found this in the spec or anywhere else. This is used very

Meaning of the dot-function syntax

2023-10-01 Thread dhs via Digitalmars-d-learn
Hi, What's the meaning of the dot in the call to writeln() below? ```d .writeln("Hello there!"); ``` I haven't found this in the spec or anywhere else. This is used very often in the source code for Phobos. Thanks, dhs

Re: Straight Forward Arrays

2023-10-01 Thread dhs via Digitalmars-d-learn
On Sunday, 1 October 2023 at 09:21:37 UTC, Imperatorn wrote: On Sunday, 1 October 2023 at 09:01:53 UTC, dhs wrote: Hi, Is there a straight forward Array type in D similar to C++'s vector class? Something along the lines of the tuple: (pointer to elements, length, capacity). [...]

Re: Straight Forward Arrays

2023-10-01 Thread dhs via Digitalmars-d-learn
On Sunday, 1 October 2023 at 13:05:12 UTC, Steven Schveighoffer wrote: On Sunday, 1 October 2023 at 09:01:53 UTC, dhs wrote: Hi, Is there a straight forward Array type in D similar to C++'s vector class? Something along the lines of the tuple: (pointer to elements, length, capacity). [...]

Re: Straight Forward Arrays

2023-10-01 Thread dhs via Digitalmars-d-learn
On Sunday, 1 October 2023 at 11:43:17 UTC, bachmeier wrote: On Sunday, 1 October 2023 at 11:39:11 UTC, bachmeier wrote: On Sunday, 1 October 2023 at 09:01:53 UTC, dhs wrote: Hi, Is there a straight forward Array type in D similar to C++'s vector class? Something along the lines of the tuple:

Straight Forward Arrays

2023-10-01 Thread dhs via Digitalmars-d-learn
Hi, Is there a straight forward Array type in D similar to C++'s vector class? Something along the lines of the tuple: (pointer to elements, length, capacity). I tried two implementations: D's dynamic array and std.container.array. When D creates a dynamic array, it returns a slice.

Re: Meaning of the dot-function syntax

2023-10-01 Thread dhs via Digitalmars-d-learn
On Sunday, 1 October 2023 at 09:24:39 UTC, evilrat wrote: On Sunday, 1 October 2023 at 08:22:48 UTC, dhs wrote: Hi, What's the meaning of the dot in the call to writeln() below? ```d .writeln("Hello there!"); ``` I haven't found this in the spec or anywhere else. This is used very often

Re: Straight Forward Arrays

2023-10-01 Thread dhs via Digitalmars-d-learn
On Sunday, 1 October 2023 at 17:21:32 UTC, Steven Schveighoffer wrote: On 10/1/23 10:34 AM, Steven Schveighoffer wrote: This should give you a reasonable head-start. -Steve It does. Many thanks!

Re: Straight Forward Arrays

2023-10-01 Thread dhs via Digitalmars-d-learn
On Sunday, 1 October 2023 at 13:51:35 UTC, Imperatorn wrote: D can be very readable and maintainable, but since all the advanced features exist, we are tempted to use them, which can cause otherwise normal code to become a bit obfuscated. OK in any case the forum seems to be very helpful.

Re: Straight Forward Arrays

2023-10-01 Thread dhs via Digitalmars-d-learn
On Sunday, 1 October 2023 at 13:27:37 UTC, Adam D Ruppe wrote: On Sunday, 1 October 2023 at 09:01:53 UTC, dhs wrote: When D creates a dynamic array, it returns a slice. Functions that add or remove elements begin by asking the memory manager for the dynamic array that the slice belongs to.

Re: Straight Forward Arrays

2023-10-04 Thread dhs via Digitalmars-d-learn
On Monday, 2 October 2023 at 02:56:33 UTC, Steven Schveighoffer wrote: FWIW, there is a cache that makes this decently fast, so it doesn't have to go all the way into the GC to get all the information for every append. But it *most definitely* not going to be as fast as reading a local

Re: Straight Forward Arrays

2023-10-06 Thread dhs via Digitalmars-d-learn
On Thursday, 5 October 2023 at 16:57:00 UTC, Jesse Phillips wrote: On Wednesday, 4 October 2023 at 10:51:46 UTC, dhs wrote: D and Go slices have advantages but can be confusing. I don't have a solution, but if anyone is interested, the relevant discussions about slice confusion in the Go

Re: Struct copy constructor with inout

2023-11-14 Thread dhs via Digitalmars-d-learn
On Tuesday, 14 November 2023 at 14:36:57 UTC, dhs wrote: Just to clarify some more: isn't "s1 = ss1" similar to I meant "ss1 = s1" here, sorry.

Re: Struct copy constructor with inout

2023-11-14 Thread dhs via Digitalmars-d-learn
On Tuesday, 14 November 2023 at 13:58:17 UTC, Paul Backus wrote: On Tuesday, 14 November 2023 at 13:41:32 UTC, Steven The error is saying that the copy constructor expects a `const` `this` argument, but you're passing a mutable `this` argument. Thanks you both very much for answering.

Struct copy constructor with inout

2023-11-14 Thread dhs via Digitalmars-d-learn
Hello D experts, I have a question regarding inout in struct copy constructors. From the spec: "The copy constructor can be overloaded with different qualifiers applied to the parameter (copying from a qualified source) or to the copy constructor itself (copying to a qualified destination)"

Re: Struct copy constructor with inout

2023-11-14 Thread dhs via Digitalmars-d-learn
On Tuesday, 14 November 2023 at 09:07:24 UTC, Alexandru Ermicioi wrote: Seems like it isn't called at all, your copy constructor with inout. Could be a bug. My assumption is that default copy constructors are generated alongside inout one, and then picked up for your initialization instead

Re: Struct copy constructor with inout

2023-11-14 Thread dhs via Digitalmars-d-learn
On Tuesday, 14 November 2023 at 14:58:21 UTC, Paul Backus wrote: ```d struct S2 { int* p; this(const int* p) const { // Ok - counts as initialization this.p = p; } } immutable int answer = 42; void main() { S2 s2; // If this were allowed to compile...

Re: Struct copy constructor with inout

2023-11-14 Thread dhs via Digitalmars-d-learn
On Tuesday, 14 November 2023 at 16:51:07 UTC, Paul Backus wrote: There's no assignment. The value is constructed in-place, in `ss2`'s memory. The reason the compiler allows you to construct a `const(S2)` value inside of an `S2` variable is that `const(S2)` implicitly converts to `S2`.