Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inject std::vector<std::shared_ptr<T>> #569

Open
KilianBl opened this issue Oct 22, 2024 · 0 comments
Open

Inject std::vector<std::shared_ptr<T>> #569

KilianBl opened this issue Oct 22, 2024 · 0 comments

Comments

@KilianBl
Copy link

Expected Behavior

di.hpp should not cause compilation errors or inject empty vectors

Actual Behavior

boost::di::bind<Base*[]>().to({std::make_shared<Derived>(1), std::make_shared<Derived>(2)}) -> cannot pass initializer list to variadic method compilation error

boost::di::bind<Base*[]>().to(vec) -> an empty vector is injected

Steps to Reproduce the Problem

#include <iostream>

#include "di.hpp"

struct Base {
};

struct Derived : Base {
    explicit Derived(const int integer) {
        std::cout << integer << std::endl;
    }
};

struct Test {
    explicit Test(std::vector<std::shared_ptr<Base>> vec) {
        std::cout << vec.size() << std::endl;
    }
};

int main() {
    std::vector<std::shared_ptr<Base>> vec{std::make_shared<Derived>(1), std::make_shared<Derived>(2)};

    const auto injector = boost::di::make_injector(
        // boost::di::bind<Base *[]>().to({std::make_shared<Derived>(1), std::make_shared<Derived>(2)}),
        boost::di::bind<Base *[]>().to(vec));

    std::ignore = injector.create<Test>();

    return 0;
}

Am I doing something wrong? Is there any alternative to get what I need?

Specifications

  • Version: 1.3.0
  • Platform: macOS
  • Compiler: Apple clang version 14.0.3 (clang-1403.0.22.14.1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant