// // 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 "boost/di/extension/providers/heap.hpp" #include #include namespace di = boost::di; class new_call; class del_call; struct example { template static auto &calls() { static auto i = 0; return i; } void *operator new(size_t size) { ++calls(); return ::operator new(size); } void operator delete(void *ptr) { ++calls(); ::operator delete(ptr); } }; int main() { struct heap_config : di::config { auto provider(...) const noexcept { return di::extension::heap{}; } }; auto injector = di::make_injector(); assert(0 == example::calls()); assert(0 == example::calls()); injector.create(); assert(1 == example::calls()); assert(1 == example::calls()); }