Making one struct work in place of another for function calls.
Liam McGillivray
yoshi.pit.link.mario at gmail.com
Wed Apr 17 03:13:46 UTC 2024
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 this is only possible if
> you are free to modify the definition of `someFunction`.
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 function? I'm willing to make a
function template if it's rather simple.
More information about the Digitalmars-d-learn
mailing list