Centralizable configured compile-time class instantiation

shd alienballance at gmail.com
Sun Jul 10 06:10:37 PDT 2011


Hello,
Original goal i'd like to achieve is to completely abstract user of my
`library` from concrete code implementations which would be set in one
centralized place (such as config file). While it's common to do that in C++ at
runtime, i'd like to let compiler optimize more by making this in compile-
time.
So, the first solution i came up is to make a 'cfg' or 'impl' template, which
accepts interface as an argument. It would be something like configurable
std.container : make. Inside this template, i could read and parse simple
configuration file to find proper implementation, and return it for user.
Unfortunately, i'm not aware of any method of instantiating any class in
template like this.
That's why i started to implementing other, simpler method. I assumed, that
CMake which I'm using, will control include paths correctly and swap
implementations on every build. What a dissapointment i met, when after
refactoring my code in this way, user can see only interface because this is
the first matching file module. Well, it's quite my fault because i believe it
was mentioned in TDPL, that module = 1 file.

So, to sum up:
My project is divided in two sections:
* interfaces
* implementations
How to make in my D library possibility of configurable instantiation (lookup
at compile time) by having only interface at client side?

Thanks,
Mariusz Gliwiński


More information about the Digitalmars-d-learn mailing list