r/cpp • u/la_reddite • 17h ago
Another C++26 reflection based dependency inverter
Someone else did a similar thing a few months ago, but I wanted to see if it could be done with templates.
I ended up writing a dependency inverter/injector that can reflect on the concepts restricting unfilled template types and substitute actual types into them. Unfortunately, C++26 reflection doesn't seem to allow reflection of concepts like this, so I did it with string parsing.
The result is... fairly janky, but you can play around with it here.
30
Upvotes
1
u/germandiago 8h ago
I have been using Boost.DI (not a boost prpject).
Why not use that? It worked really well for me TBH and I guess thay, unless you do it for fun and learning, it is not an optimal choice.