modules
wasn't perfect due to missing return type deduction for functions in C++11.
Therefore, I made a decision to reimplement the core using C++14 features which sped up compilation times dramatically
and make the interface cleaner and easier to maintain. Nevertheless, effort was made to support the newest versions of
popular C++ compilers including GCC/Clang and MSVC. If you are interested in C++03 version of the library, please, take
a look into cpp03 branch. Please, also notice that this
branch is not maintained anymore.template <class T = class Greater>
struct example {
using type = T;
};
struct hello {};
int main() {
const auto injector = di::make_injector(
di::bind<class Greater>().to<hello>()
);
auto object = injector.create<example>();
static_assert(std::is_same<hello, decltype(object)::type>{});
}
auto use_gui_view = true/false;
auto injector = di::make_injector(
di::bind<iview>.to([&](const auto& injector) -> iview& {
if (use_gui_view)
return injector.template create<gui_view&>();
else
return injector.template create<text_view&>();
})
, di::bind<>.to(42) // renderer device
);
Check out full example of Dynamic Bindings.