Re: Making one struct work in place of another for function calls.

2024-04-17 Thread cc via Digitalmars-d-learn
On Wednesday, 17 April 2024 at 03:13:46 UTC, Liam McGillivray wrote: On Wednesday, 17 April 2024 at 02:39:25 UTC, Paul Backus wrote: This is called [row polymorphism][1], and it does not exist in D. You could approximate it by making `someFunction` a template, and accepting any type `T` that

Re: Making one struct work in place of another for function calls.

2024-04-16 Thread Andy Valencia via Digitalmars-d-learn
On Wednesday, 17 April 2024 at 03:13:46 UTC, Liam McGillivray wrote: Is there a way I can replace "`TypeB`" in the function parameters with another symbol, and then define that symbol to accept `TypeB` as an argument, but also accept `TypeA` which would get converted to `TypeB` using a

Re: Making one struct work in place of another for function calls.

2024-04-16 Thread Liam McGillivray via Digitalmars-d-learn
On Wednesday, 17 April 2024 at 02:39:25 UTC, Paul Backus wrote: This is called [row polymorphism][1], and it does not exist in D. You could approximate it by making `someFunction` a template, and accepting any type `T` that has the necessary members instead of only accepting `typeB`. But

Re: Making one struct work in place of another for function calls.

2024-04-16 Thread Paul Backus via Digitalmars-d-learn
On Wednesday, 17 April 2024 at 01:36:59 UTC, Liam McGillivray wrote: To better understand what I mean, take the following example, where I have a function, and two structs. ``` struct typeA { // Some member variables here } struct typeB { // Some similar member variables here, but in a

Making one struct work in place of another for function calls.

2024-04-16 Thread Liam McGillivray via Digitalmars-d-learn
I have two structs that serve roughly the same purpose, and I would like one to be accepted when the other is declared as a function parameter. To better understand what I mean, take the following example, where I have a function, and two structs. ``` struct typeA { // Some member