The examples show a way to bind to a constructor and provide some constant value to it. This works in the simple case, but should also work in more complex cases.
Actual Behavior
When the binding to constructor is done indirectly via a binding to an interface, the constant values are not passed to the constructor anymore.
Steps to Reproduce the Problem
namespace di = boost::di;
struct interface {
virtual ~interface() noexcept = default;
};
struct user : public interface
{
explicit user(int value) {
assert(value == 3);
}
};
int main() {
const auto injector = di::make_injector(
di::bind<interface>().to<user>(),
di::bind<user>()(3)
);
injector.create<interface>();
}
Link to CompileExplorer
The assertion fails because value is 0. However when injector.create<user>(); is called it works just fine.
Same behavior with clang and gcc.
Expected Behavior
The examples show a way to bind to a constructor and provide some constant value to it. This works in the simple case, but should also work in more complex cases.
Actual Behavior
When the binding to constructor is done indirectly via a binding to an interface, the constant values are not passed to the constructor anymore.
Steps to Reproduce the Problem
Link to CompileExplorer The assertion fails because value is 0. However when
injector.create<user>();
is called it works just fine. Same behavior with clang and gcc.