[Перевод] Boost.DI: внедрение зависимости в С++28.01.2015 13:33
struct module {
di: injector configure () const {
return di: make_injector (
di: bind
);
}
};
int main () {
auto injector = di: make_injector (
module{}
);
auto ptr = injector.create<
unique_ptr
>();
return ptr!= nullptr;
}
push %rbp mov (%rax),%ecx
push %rbx lea -0×1(%rcx),%edx
sub $0×38,%rsp mov %edx,(%rax)
lea 0×10(%rsp),%rdi cmp $0×1,%ecx
lea 0×8(%rsp),%rsi jne 0×400bcd
callq 0×400bf0 <_ZN5boost2di7exposed> mov (%rbx),%rax
mov 0×18(%rsp),%rdi mov %rbx,%rdi
mov (%rdi),%rax callq *0×10(%rax)
lea 0×30(%rsp),%rsi lea 0xc (%rbx),%rax
callq *0×10(%rax) mov $0×0,%ecx
test %rax,%rax test %rcx,%rcx
setne %bpl je 0×400bb8
je 0×400b57 mov $0xffffffff,%ecx
mov (%rax),%rcx lock xadd %ecx,(%rax)
mov %rax,%rdi mov %ecx,0×30(%rsp)
callq *0×8(%rcx) mov 0×30(%rsp),%ecx
mov 0×20(%rsp),%rbx jmp 0×400bbf
test %rbx,%rbx mov (%rax),%ecx
je 0×400bcd lea -0×1(%rcx),%edx
lea 0×8(%rbx),%rax mov %edx,(%rax)
mov $0×0,%ecx cmp $0×1,%ecx
test %rcx,%rcx jne 0×400bcd
je 0×400b82 mov (%rbx),%rax
mov $0xffffffff,%ecx mov %rbx,%rdi
lock xadd %ecx,(%rax) callq *0×18(%rax)
mov %ecx,0×30(%rsp) movzbl %bpl,%eax
mov 0×30(%rsp),%ecx add $0×38,%rsp
jmp 0×400b89 pop %rbx
pop %rbp
--> retq
© Habrahabr.ru