boost-ext / di

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

lazy extension cannot be wrapped in tuple #434

Open kanstantsin-chernik opened 4 years ago

kanstantsin-chernik commented 4 years ago

Expected Behavior

Expect to construct lazy objects in tuple

Actual Behavior

Errors about not being able to construct lazy object

Steps to Reproduce the Problem

#include "boost/di/extension/injections/lazy.hpp"
#include <tuple>
namespace di = boost::di;

int main() {
  auto injector = di::make_injector(
    di::bind<int>().to(5)
  );
  injector.create<std::tuple<di::extension::lazy<int>>>();
}

Specifications

kanstantsin-chernik commented 4 years ago

Hi @krzysztof-jusiak. Do you have any ideas?

kanstantsin-chernik commented 4 years ago

This is a workaround:

template<class T>
    class LazyProvider {
    public:
        explicit LazyProvider(boost::di::extension::lazy<T >object) : object_(object) {}
        LazyProvider(const LazyProvider& other) : object_(other.object_) {}
        T get() const { return object_.get(); }

    private:
        const boost::di::extension::lazy<T> object_;
    };