// // Copyright (c) 2012-2020 Kris Jusiak (kris at jusiak dot net) // // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // //<- #include #include //-> #include namespace di = boost::di; //<- struct interface { virtual ~interface() noexcept = default; virtual void dummy() = 0; }; struct implementation : interface { void dummy() override {} }; //-> struct dependency1 { dependency1(std::shared_ptr spi /*shared*/ , const std::shared_ptr& spi_ /*shared*/) : spi_(spi), spi__(spi_) { assert(spi.get() == spi_.get()); } std::shared_ptr spi_; std::shared_ptr spi__; }; struct dependency2 { dependency2(std::shared_ptr spi /*shared*/, int i /*unique*/) : spi_(spi) { assert(i == 0); } std::shared_ptr spi_; }; struct example { example(std::unique_ptr dependency1_ /*unique*/ , const dependency2& dependency2_ /*unique temporary*/) { assert(dependency2_.spi_.get() == dependency1_->spi_.get()); assert(dependency2_.spi_.get() == dependency1_->spi__.get()); } }; int main() { /*<>*/ // clang-format off auto injector = di::make_injector( di::bind().to() // => di::bind().to().in(di::deduce) ); // clang-format on /*<>*/ injector.create(); }