C++14 Dependency Injection library
Your C++14 one header only Dependency Injection library with no dependencies
boost-ext.di requires only one file. Get the latest header here!
#include
namespace di = boost::di;$CXX -std=c++14 -O2 -fno-exceptions -fno-rtti -Wall -Werror -pedantic-errors file.cppcl /std:c++14 /Ox /W3 file.cppclass ctor {
public:
explicit ctor(int i) : i(i) {}
int i;
};
struct aggregate {
double d;
};
class example {
public:
example(aggregate a, const ctor& c) {
assert(87.0 == a.d);
assert(42 == c.i);
};
};
int main() {
const auto injector = di::make_injector(
di::bind.to(42),
di::bind.to(87.0)
);
injector.create();
}Clang-3.8
GCC-6
MSVC-2015
Compilation Time
0.102s
0.118s
0.296s
Binary size (stripped)
6.2kb
6.2kb
105kb
ASM x86-64xor eax, eax retq
struct interface {
virtual ~interface() noexcept = default;
virtual int get() const = 0;
};
class implementation : public interface {
public:
int get() const override { return 42; }
};
struct example {
example(std::shared_ptr i) {
assert(42 == i->get());
}
};
int main() {
const auto injector = di::make_injector(
di::bind.to()
);
injector.create>();
}Clang-3.8
GCC-6
MSVC-2015
Compilation Time
0.102s
0.118s
0.296s
Binary size (stripped)
6.2kb
6.2kb
105kb
ASM x86-64 (same as `make_unique`)push %rbx mov %rdi,%rbx mov $0x8,%edi callq 0x4008e0 movq $0x400c78,(%rax) mov %rax,(%rbx) mov %rbx,%rax pop %rbx retq
…Clang-3.8
GCC-6
MSVC-2015
Compilation Time
0.102s
0.118s
0.296s
Binary size (stripped)
6.2kb
6.2kb
105kb
ASM x86-64xor eax, eax retq
struct Streamable {
template
auto requires(T&& t) -> decltype(
int( t.read() ),
t.write(int)
);
};
template
class example {
public:
example(Exchange exchange, Engine engine)
: exchange(std::move(exchange)), engine(std::move(engine))
{ }
private:
Exchange exchange;
Engine engine;
};
int main() {
const auto injector = di::make_injector(
di::bind.to(),
di::bind.to()
);
injector.create();
}Clang-3.8
GCC-6
MSVC-2015
Compilation Time
0.102s
0.118s
0.296s
Binary size (stripped)
6.2kb
6.2kb
105kb
ASM x86-64xor eax, eax retq
No open issues yet, or sync has not completed.