// // 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; }; struct implementation : interface {}; //-> /**/ struct example { explicit example(int i, std::unique_ptr up) { assert(i == 42); assert(dynamic_cast(up.get())); } }; /**/ struct custom_provider { template struct is_creatable { static constexpr auto value = true; }; template auto get(const di::type_traits::direct&, const TMemory& // stack/heap , TArgs&&... args) const { return new T(std::forward(args)...); } template auto get(const di::type_traits::uniform&, const TMemory& // stack/heap , TArgs&&... args) const { return new T{std::forward(args)...}; } }; /**/ class config : public di::config { public: static auto provider(...) noexcept { return custom_provider{}; } }; int main() { /*<>*/ // clang-format off auto injector = di::make_injector( di::bind().to(42) , di::bind().to() ); // clang-format on /*<>*/ injector.create(); }