Re: Key and value with ranges

2023-10-01 Thread Imperatorn via Digitalmars-d-learn
On Monday, 2 October 2023 at 02:47:37 UTC, Joel wrote: ```d import std; auto data=“I went for a walk, and fell down a hole.”; void main(string[] args) { int[string] dic; struct WordCnt { string word; ulong count; string toString() const { return

Re: The difference between T[] opIndex() and T[] opSlice()

2023-10-01 Thread Steven Schveighoffer via Digitalmars-d-learn
On 10/1/23 1:41 PM, Salih Dincer wrote: Hi, What is the difference between T[] opIndex() and T[] opSlice(), which haven't parameters? None. It used to be that opSlice was the only way, and the mechanisms opSlice uses are still valid. -Steve

Re: Straight Forward Arrays

2023-10-01 Thread Steven Schveighoffer via Digitalmars-d-learn
On 10/1/23 1:13 PM, dhs wrote: It may not be a problem in practice. My concern was performance, because each time we add an element to the array, the garbage collector has to map the slice to the allocation it belongs to. FWIW, there is a cache that makes this decently fast, so it doesn't

Key and value with ranges

2023-10-01 Thread Joel via Digitalmars-d-learn
```d import std; auto data=“I went for a walk, and fell down a hole.”; void main(string[] args) { int[string] dic; struct WordCnt { string word; ulong count; string toString() const { return text("Word: ", word, " - number of instances: ", count);

Re: The difference between T[] opIndex() and T[] opSlice()

2023-10-01 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, October 1, 2023 11:51:17 AM MDT Salih Dincer via Digitalmars-d- learn wrote: > On Sunday, 1 October 2023 at 17:41:08 UTC, Salih Dincer wrote: > > Also, is it correct to use [] when returning? > > > > Thanks... > > [Here](https://dlang.org/spec/operatoroverloading.html#slice), > the

Re: Straight Forward Arrays

2023-10-01 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, October 1, 2023 11:13:43 AM MDT dhs via Digitalmars-d-learn wrote: > 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

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: The difference between T[] opIndex() and T[] opSlice()

2023-10-01 Thread Salih Dincer via Digitalmars-d-learn
On Sunday, 1 October 2023 at 17:41:08 UTC, Salih Dincer wrote: Also, is it correct to use [] when returning? Thanks... [Here](https://dlang.org/spec/operatoroverloading.html#slice), the opIndex() is proposed and an example of parameterized the opSlice() is given for multidimensional

The difference between T[] opIndex() and T[] opSlice()

2023-10-01 Thread Salih Dincer via Digitalmars-d-learn
Hi, What is the difference between T[] opIndex() and T[] opSlice(), which haven't parameters? ```d struct S(T) {    T[] arr;        T[] opIndex() => arr[];/*    T[] opSlice() => arr;//*/ } alias Type = int; void main() {    auto s = S!Type([1,2,3]);    auto arr = s[]; // calls

Re: Straight Forward Arrays

2023-10-01 Thread Steven Schveighoffer via Digitalmars-d-learn
On 10/1/23 10:34 AM, Steven Schveighoffer wrote: The complexity is from the way d does operator overloading and indexing. It should be pretty straightforward. I’ll see if I can post a simple wrapper. I didn't tackle any attribute or memory safety issues, or many operator overloads, but

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-01 Thread Steven Schveighoffer via Digitalmars-d-learn
On Sunday, 1 October 2023 at 13:24:27 UTC, dhs wrote: 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: [...] Std::vector uses value semantics. D does not have anything like that. It could be done someone just has to

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 Imperatorn via Digitalmars-d-learn
On Sunday, 1 October 2023 at 13:24:27 UTC, dhs wrote: 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

Re: Straight Forward Arrays

2023-10-01 Thread Adam D Ruppe via Digitalmars-d-learn
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. Only then can they go on and add elements. Why is this a

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 Steven Schveighoffer via Digitalmars-d-learn
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). [...] Std::vector uses value semantics. D does not have anything like

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:

Re: Associate information with a pointer address.

2023-10-01 Thread bachmeier via Digitalmars-d-learn
On Sunday, 1 October 2023 at 09:41:39 UTC, BoQsc wrote: The package dependency `emsi_containers` that can be found in https://code.dlang.org/packages/emsi_containers might be a viable way to resolve the problem. ``` /+dub.sdl: dependency "emsi_containers" version="~>0.7" +/ import std;

Re: Straight Forward Arrays

2023-10-01 Thread bachmeier via Digitalmars-d-learn
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: (pointer to elements, length, capacity). I tried two

Re: Straight Forward Arrays

2023-10-01 Thread bachmeier via Digitalmars-d-learn
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). I tried two implementations: D's dynamic array and std.container.array.

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: 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

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: Associate information with a pointer address.

2023-10-01 Thread BoQsc via Digitalmars-d-learn
The package dependency `emsi_containers` that can be found in https://code.dlang.org/packages/emsi_containers might be a viable way to resolve the problem. ``` /+dub.sdl: dependency "emsi_containers" version="~>0.7" +/ import std; void main(string[] args) @nogc { import containers;

Re: Meaning of the dot-function syntax

2023-10-01 Thread evilrat via Digitalmars-d-learn
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 in the source code for Phobos. Thanks, dhs It is

Re: Straight Forward Arrays

2023-10-01 Thread Imperatorn via Digitalmars-d-learn
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). [...] https://dlang.org/spec/simd.html

Re: Meaning of the dot-function syntax

2023-10-01 Thread Anonymouse via Digitalmars-d-learn
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 in the source code for Phobos. Thanks, dhs Quote

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.

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