Generic binding?
vrecluse opened this issue · 2 comments
vrecluse commented
Is it possible to auto bind open
generic types?
eg:
template <typename T>
struct Signal {...};
...
fruit::createComponent().bind<Signal<T>>();
...
auto sig_int = injector.get<Singal<int>*>():
auto sig_float = injector.get<Singal<float>*>():
... and others without manual bind for every template type
poletti-marco commented
TL;DR no, each injector can only have a finite number of types bound.
You can define a templated get*Component function and then install multiple instantiations of that for various types. But the set of bound types can't grow after the injector is created.
What are you trying to do?
To avoid the XY problem.
One option might be to bind a single type and then have a method there to construct a Signal. In that case you'd need to handle the lifetime of the Signal objects though (e.g. using unique_ptr or shared_ptr).
vrecluse commented
Ok, thanks.