I have this code:
struct Foo{
int sum;
Foo() : sum(0) {}
Foo(int x) : sum(x) {}
Foo bar(int x){
return Foo(sum + 1);
}
Foo bar(std::vector<int> x){
return Foo(sum + 1);
}
Foo bar(const char* str){
return Foo(sum + 1);
}
};
template <typename ... T>
int foo(T ... args){
Foo foo;
//(foo.bar(args), ...);
return foo.sum;
}
int main() {
foo(1, 2, "hello", std::vector<int>());
return 0;
}
I want to create the call hierarchy like this:
Foo foo;
foo = foo.bar(1);
foo = foo.bar(2);
foo = foo.bar("hello");
based on variadic templated arguments args.
I was looking at fold expressions, but that seems to be not working as I need. I can fold methods to be called separatelly, but cannot call the next one on the result from the previous one.
Is there any way how to do this with?