Comments (5)
Well, I played with factory and ASSISTED a bit more and I'm now more certain there's a bug somewhere.
E.g. I just slightly modified this example from the fruit test source code: tests/register_factory.cpp:
The following would not compile. I guess it's related to my issue.
#include <fruit/fruit.h>
#include <iostream>
using fruit::Component;
using fruit::Injector;
using fruit::Assisted;
using fruit::createComponent;
struct X {
INJECT(X()) = default;
};
class Scaler {
private:
double factor;
int factor2;
public:
INJECT(Scaler(ASSISTED(double) factor, ASSISTED(int) factor2, X))
: factor(factor), factor2(factor2) {
}
double scale(double x) {
return x * factor * factor2;
}
};
using ScalerFactory = std::function<std::unique_ptr<Scaler>(double, int)>;
Component<ScalerFactory> getScalerComponent() {
return createComponent();
}
int main() {
Injector<ScalerFactory> injector(getScalerComponent());
ScalerFactory scalerFactory(injector);
std::unique_ptr<Scaler> scaler = scalerFactory(12.1, 3);
std::cout << scaler->scale(3) << std::endl;
return 0;
}
Compilation error:
In file included from /usr/include/fruit/fruit.h:25:0,
from ../di/RegisterFactoryTest.cpp:1:
/usr/include/fruit/impl/injection_errors.h: In instantiation of ‘struct fruit::impl::FunctorSignatureDoesNotMatchError<Scaler(double, int), Scaler(int, double)>’:
/usr/include/fruit/impl/component.defn.h:58:3: required from ‘fruit::Component<Types>::Component(fruit::PartialComponent<Bindings ...>) [with Bindings = {}; Params = {std::function<std::unique_ptr<Scaler, std::default_delete<Scaler> >(double, int)>}]’
../di/RegisterFactoryTest.cpp:31:26: required from here
/usr/include/fruit/impl/injection_errors.h:214:3: error: static assertion failed: Unexpected functor signature (it should be the same as ExpectedSignature minus any Assisted types).
static_assert(
^
In file included from /usr/include/fruit/component.h:498:0,
from /usr/include/fruit/fruit.h:28,
from ../di/RegisterFactoryTest.cpp:1:
/usr/include/fruit/impl/component.defn.h: In instantiation of ‘fruit::Component<Types>::Component(fruit::PartialComponent<Bindings ...>) [with Bindings = {}; Params = {std::function<std::unique_ptr<Scaler, std::default_delete<Scaler> >(double, int)>}]’:
../di/RegisterFactoryTest.cpp:31:26: required from here
/usr/include/fruit/impl/component.defn.h:61:3: error: no type named ‘Result’ in ‘fruit::impl::meta::OpForComponent<>::ConvertTo<fruit::impl::meta::Comp<fruit::impl::meta::Vector<>, fruit::impl::meta::Vector<fruit::impl::meta::Type<std::function<std::unique_ptr<Scaler, std::default_delete<Scaler> >(double, int)> > >, fruit::impl::meta::Vector<fruit::impl::meta::Pair<fruit::impl::meta::Type<std::function<std::unique_ptr<Scaler, std::default_delete<Scaler> >(double, int)> >, fruit::impl::meta::Vector<> > >, fruit::impl::meta::Vector<>, fruit::impl::meta::EmptyList> > {aka struct fruit::impl::meta::Error<fruit::impl::FunctorSignatureDoesNotMatchErrorTag, Scaler(double, int), Scaler(int, double)>}’
(void)typename fruit::impl::meta::CheckIfError<fruit::impl::meta::Eval<fruit::impl::meta::CheckNoLoopInDeps(typename Op::Result)>>::type();
^
In file included from /usr/include/fruit/component.h:498:0,
from /usr/include/fruit/fruit.h:28,
from ../di/RegisterFactoryTest.cpp:1:
/usr/include/fruit/impl/component.defn.h:64:15: error: no match for call to ‘(Op {aka fruit::impl::meta::Error<fruit::impl::FunctorSignatureDoesNotMatchErrorTag, Scaler(double, int), Scaler(int, double)>}) (fruit::impl::ComponentStorage&)’
Op()(storage);
^
from fruit.
Thanks for the report, it was indeed a bug.
I'm releasing version 2.0.1 soon with this fix.
from fruit.
FYI, I now released 2.0.1 with this fix and the binary packages have been updated. Please update to get the fix.
from fruit.
I gave 2.0.1 a try. It indeed fixed the problem. Thanks a lot!
from fruit.
Now 2.0.2 has been released with the fix to the other related bug.
from fruit.
Related Issues (20)
- Fruit does not build in Visual Studio Versions 2019, 2022 or 2022 Preview with CMake HOT 8
- what should I do to use a string as an annotion of some bind? HOT 3
- VS2022 Just My Code for Fruit Library fails using CMAKE HOT 6
- Create a fruit::Component by iterating over a list of fruit::Components HOT 7
- Can fruit be used with C language? HOT 2
- Handling lifetimes HOT 6
- Providing non-injected arguments to DI Objects HOT 14
- Build fails with Visual Studio 2022 with C++20 HOT 8
- Fruit with QT HOT 4
- Factories with reference types broken in fruit 3.7.0
- Generic binding? HOT 2
- Defining Factory Functions for Objects with Multiple Constructors HOT 11
- Replace boost HOT 1
- Creating Collections of DI Objects HOT 3
- [Suggestion] ExtractFirstError meta function SHOULD be non-error safe HOT 2
- Can no longer build examples in VS2022 Preview built by Visual Studio, VS CMake builds OK HOT 7
- Examples miss virtual dtor
- bindInstance with copy HOT 13
- Understanding Compiler error messages in Fruit HOT 6
- Adding a special constructor to one implementation of an interface HOT 13
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fruit.