Boost C++ Libraries

PrevUpHomeNext
Introduction
Overview
Tutorial
Try It Online!
Benchmarks
User Guide
Examples
Extensions
FAQ
CHANGELOG
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.


PrevUpHomeNext