Re: writeln the struct from the alis this Example from the home page

2021-11-19 Thread Martin Tschierschke via Digitalmars-d-learn
On Thursday, 18 November 2021 at 16:08:22 UTC, Paul Backus wrote: On Thursday, 18 November 2021 at 13:51:42 UTC, Martin Tschierschke wrote: [...] You can define a `toString` method, like this: ```d string toString() { import std.conv; return p.to!string; } ``` You can find more

Nice example for operator overload resulting in readable linear algebra expressions

2021-11-19 Thread Martin Tschierschke via Digitalmars-d-learn
I just want to share a view lines of code. The availability of operator overloading can result in very short and precise code for linear algebra. To test/explore it a little I just modified the alias this example: ``` #!/usr/bin/env rdmd struct Point { double[2] p; // Forward all

Re: Why does this call the copy constructor 2 times and the assigment constructor once?

2021-11-19 Thread rempas via Digitalmars-d-learn
On Friday, 19 November 2021 at 14:22:07 UTC, Paul Backus wrote: When you pass a struct instance to a function by value, or return a struct instance from a function by value, a copy is made, and the copy constructor is called. Your `opAssign` takes `rhs` by value, and returns a `str` by

Re: Why does this call the copy constructor 2 times and the assigment constructor once?

2021-11-19 Thread Paul Backus via Digitalmars-d-learn
On Friday, 19 November 2021 at 14:05:40 UTC, rempas wrote: So, when I assign the value of the variable "name" in the "other_name", first it will call the copy constructor, then it will call the assignment constructor and then it will call the copy constructor again. Why is this happening? I

Why does this call the copy constructor 2 times and the assigment constructor once?

2021-11-19 Thread rempas via Digitalmars-d-learn
Hi! I'm trying to make my own string type for my library. Anyway, I'm not very experienced with structs/classes so I don't understand what's going one here. I will not post the full code because I don't think that anyone would like it so I will just post the important parts that play a role

Re: Are templated functions always re-constructed?

2021-11-19 Thread rempas via Digitalmars-d-learn
On Wednesday, 17 November 2021 at 17:02:45 UTC, H. S. Teoh wrote: Regular (non-recursive) templates generally will not cause a noticeable change in compilation times. The trouble usually only starts when you start using recursive templates. Or when your templates are nested unreasonably

Re: Null pointer in __vptr

2021-11-19 Thread Adam D Ruppe via Digitalmars-d-learn
On Friday, 19 November 2021 at 15:37:59 UTC, frame wrote: Is a null pointer entry in the __vptr[] valid or always a sign for corruption/wrong cast somewhere? thx The `destroy` function (as well as other class destruction) will null out the whole vtable to help make use-after-free an obvious

Efficient way to create/copy immutable struct instance with modified data

2021-11-19 Thread Merlin Diavova via Digitalmars-d-learn
Hi all, I'm trying to figure out the most efficient way to create modified instances of immutable structs. Currently, I'm doing the following: ```d immutable struct Node { string label; Node parentNode; NetworkPort port; auto withLabel(string newLabel)

How to read a single character in D language?

2021-11-19 Thread BoQsc via Digitalmars-d-learn
Let's say I want to write a simple program that asks for an input of a single character. After pressing a single key on a keyboard, the character is printed out and the program should stop.

Null pointer in __vptr

2021-11-19 Thread frame via Digitalmars-d-learn
Got a suspicious interface instance in the debugger and question myself: Is a null pointer entry in the __vptr[] valid or always a sign for corruption/wrong cast somewhere? thx

Re: How to read a single character in D language?

2021-11-19 Thread Adam D Ruppe via Digitalmars-d-learn
On Friday, 19 November 2021 at 17:36:55 UTC, BoQsc wrote: Let's say I want to write a simple program that asks for an input of a single character. After pressing a single key on a keyboard, the character is printed out and the program should stop. This is platform specific. About 10 lines of

Re: Null pointer in __vptr

2021-11-19 Thread frame via Digitalmars-d-learn
On Friday, 19 November 2021 at 15:46:41 UTC, Adam D Ruppe wrote: The `destroy` function (as well as other class destruction) will null out the whole vtable to help make use-after-free an obvious error. Possible that happened to you. So, a partial nulled table shouldn't exist, right? like

Re: Efficient way to create/copy immutable struct instance with modified data

2021-11-19 Thread Adam D Ruppe via Digitalmars-d-learn
On Friday, 19 November 2021 at 17:38:53 UTC, Merlin Diavova wrote: I'm trying to figure out the most efficient way to create modified instances of immutable structs. This might not be the best way but it is a kinda cool trick anyway: structs have a `tupleof` property you can slice. So you

Re: Null pointer in __vptr

2021-11-19 Thread Adam D Ruppe via Digitalmars-d-learn
On Friday, 19 November 2021 at 18:04:17 UTC, frame wrote: So, a partial nulled table shouldn't exist, right? like this: Indeed. I've gotten that before as a result of a compiler bug... I had an abstract method that wasn't implemented but the compile time error got swallowed by a bug and

Re: How to read a single character in D language?

2021-11-19 Thread BoQsc via Digitalmars-d-learn
On Friday, 19 November 2021 at 18:01:57 UTC, Adam D Ruppe wrote: On Friday, 19 November 2021 at 17:36:55 UTC, BoQsc wrote: Let's say I want to write a simple program that asks for an input of a single character. After pressing a single key on a keyboard, the character is printed out and the

Re: How to read a single character in D language?

2021-11-19 Thread Imperatorn via Digitalmars-d-learn
On Friday, 19 November 2021 at 17:36:55 UTC, BoQsc wrote: Let's say I want to write a simple program that asks for an input of a single character. After pressing a single key on a keyboard, the character is printed out and the program should stop. If you want to test on Windows you can do

Re: Any additions for write-to-file short program

2021-11-19 Thread Imperatorn via Digitalmars-d-learn
On Friday, 19 November 2021 at 22:21:52 UTC, pascal111 wrote: On Thursday, 18 November 2021 at 23:09:28 UTC, H. S. Teoh wrote: [...] When I compiled the code after adding yours, I found this error message: "untitled20.d:24:8: error: no property 'copy' for type 'ByChunk' 24 |

Re: Null pointer in __vptr

2021-11-19 Thread Ali Çehreli via Digitalmars-d-learn
On 11/19/21 10:04 AM, frame wrote: > On Friday, 19 November 2021 at 15:46:41 UTC, Adam D Ruppe wrote: > >> The `destroy` function (as well as other class destruction) will null >> out the whole vtable to help make use-after-free an obvious error. >> Possible that happened to you. > > So, a

Re: How to read a single character in D language?

2021-11-19 Thread Adam Ruppe via Digitalmars-d-learn
On Friday, 19 November 2021 at 20:51:09 UTC, BoQsc wrote: But the source file overwhelmed me by its size. Yeah, the getch function in there builds on the rest of the events the library offers, so it won't be that useful outside. The OS functions for getch alone though are actually pretty

Re: Any additions for write-to-file short program

2021-11-19 Thread pascal111 via Digitalmars-d-learn
On Thursday, 18 November 2021 at 23:09:28 UTC, H. S. Teoh wrote: On Thu, Nov 18, 2021 at 10:20:48PM +, pascal111 via Digitalmars-d-learn wrote: In next program that rewrites original written texts into new files, I see that it may need some additions or we can accept it like this because

Re: Null pointer in __vptr

2021-11-19 Thread frame via Digitalmars-d-learn
On Friday, 19 November 2021 at 18:14:03 UTC, Adam D Ruppe wrote: I've gotten that before as a result of a compiler bug... I had an abstract method that wasn't implemented but the compile time error got swallowed by a bug and thus the null method made its way to the binary. You got it! It

Re: How to read a single character in D language?

2021-11-19 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Nov 19, 2021 at 10:21:42PM +, Adam Ruppe via Digitalmars-d-learn wrote: [...] > The OS functions for getch alone though are actually pretty simple: > > 1) change the terminal to "raw" mode. the default is to buffer lines, > which means your application doesn't get anything until a

Re: Dub says that there is an invalid semVer format, but I don't see how.

2021-11-19 Thread Ruby The Roobster via Digitalmars-d-learn
On Friday, 12 November 2021 at 21:22:32 UTC, Ruby The Roobster wrote: On Thursday, 11 November 2021 at 01:57:10 UTC, rikki cattermole wrote: On 11/11/2021 2:13 PM, Ruby The Roobster wrote: Branch ~master: Invalid SemVer format: testing.0.0 Branch ~testing: Invalid SemVer format: testing.0.0

Re: Any additions for write-to-file short program

2021-11-19 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Nov 19, 2021 at 10:21:52PM +, pascal111 via Digitalmars-d-learn wrote: [...] > When I compiled the code after adding yours, I found this error message: > > "untitled20.d:24:8: error: no property 'copy' for type 'ByChunk' >24 |.copy(outputFile.lockingBinaryWriter); // copy

Re: Any additions for write-to-file short program

2021-11-19 Thread pascal111 via Digitalmars-d-learn
On Friday, 19 November 2021 at 23:05:03 UTC, H. S. Teoh wrote: On Fri, Nov 19, 2021 at 10:21:52PM +, pascal111 via Digitalmars-d-learn wrote: [...] When I compiled the code after adding yours, I found this error message: "untitled20.d:24:8: error: no property 'copy' for type 'ByChunk'

Re: Dub says that there is an invalid semVer format, but I don't see how.

2021-11-19 Thread rikki cattermole via Digitalmars-d-learn
Don't use ~> for branches. alpha@DESKTOP-RB97SA4 /tmp/dutils $ dub build Invalid SemVer format: stable.0.0 alpha@DESKTOP-RB97SA4 /tmp/dutils $ nano dub.json alpha@DESKTOP-RB97SA4 /tmp/dutils $ dub build Performing "debug" build using C:\Tools\D\dmd_2.097.2\windows\bin\dmd.exe for