Can a D library have some types determined by the client program?

Liam McGillivray yoshi.pit.link.mario at gmail.com
Thu Mar 7 22:12:21 UTC 2024


In a source library written in D, is it possible to have some 
objects, variables, pointers etc which are determined by the 
program using the library?

An example of where this would be useful is in the library I am 
currently writing. I have a class called `Map`, which holds an 
array of objects of the `Tile` class. A program using my library 
can inherit the Map class if they want to add more functions and 
variables, but what if they want to add more to the Tile class? 
Even if they make a derived class of `Tile`, they can't override 
the use of the base Tile class in the Map class.

In cases like this, it would be useful to allow the client 
program to determine the type for some objects. For it to work 
with types defined in the client software code, the client 
software will also need a way to give it access to a module of 
the client software.

I know that D has something called compile-time function 
evaluation, but I don't know the full capabilities.


More information about the Digitalmars-d-learn mailing list