boost-ext / di

C++14 Dependency Injection Library
https://boost-ext.github.io/di
1.14k stars 138 forks source link

Incomplete types #425

Open marco6 opened 5 years ago

marco6 commented 5 years ago

I really like this library and I'd really want to use it together with a C library (namely, libpq).

The main problem is that it seems not possible to bind pointers to incomplete types. This workaround won't work as dereferencing the pointer at line 16 will result in a compile error.

Expected Behavior

Being able to work with incomplete types.

Actual Behavior

Does not compile/there is no syntax to express this kind of binding.

Steps to Reproduce the Problem


#include <boost/di.hpp>
#include <iostream>

using namespace std;
namespace DI = boost::di;

struct kkp;

static kkp* get_kkp(void);

int main(int argc, const char** argv) {

    auto injector = DI::make_injector(
        DI::bind<>.to([] {
            return get_kkp();
        })
    );

    injector.create<kkp*>();
}

struct kkp {
    int a;
    kkp(int _a): a(_a) {
        cout << a << endl;
    }
};

static kkp* get_kkp() {
    return new kkp(10);
}

This results in creatable constraint not satisfied.

Specifications