Boost logo

Boost :

From: Krzysztof Jusiak (krzysztof_at_[hidden])
Date: 2021-02-23 15:03:53


>
> This is clearly stupendously clever.
>
> What I don't understand is what specific thing is linking the bound
> Allocator type in the injector to the specialisation point in the app's
> constructor. Is it this:
> template<class TAllocator = class Allocator>
> ?
>
> This is going to need to be meticulously documented and spelled out in
> small words for people like me who obviously live in your intellectual
> shadow.
>
>
Yeah, templates are bound by default types names (notice that it also allow
concepts - AllocatorConcept = class Allocator) whilst constructor
parameters are deduced.
Firstly, types are rebound and then proper constructor parameters are
being injected. If anything is missing in the wiring compilation error will
be triggered.

template<class TAllocator = class Allocator>

auto injector = di::make_injector(
   di::bind<class Allocator>.to<my_allocator<int>>() // rebind class
Allocator to my_allocator
);


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk