I currently have a number of data accessors like:
template <typename Fn>
typename std::result_of<Fn(DataA)>::type GetDataA(Fn fn) {
DataA a = DoSomeWorkToGetA();
return fn(a);
}
template <typename Fn>
typename std::result_of<Fn(DataB)>::type GetDataB(Fn fn) {
DataB b = DoSomeWorkToGetB();
return fn(b);
}
Which are used like:
auto computation_result_a = GetDataA([](DataA a) {
return DoCustomProcessingOnA(a);
});
auto computation_result_b = GetDataB([](DataB a) {
return DoCustomProcessingOnB(b);
});
What I'd like, is for a way to automatically generate combinations of these Getters, like:
template <typename Fn>
typename std::result_of<Fn(DataA, DataB)>::type GetDataAandB(Fn fn) {
DataA a = GetDataA([](DataA a) { return a; });
DataB b = GetDataB([](DataB b) { return b; });
return fn(a, b);
}
I have seen this type of thing done in the past, with a user API like:
auto computation_result_a = GetData<A>([](Data a) { /**/ });
auto computation_result_b = GetData<A>([](Data b) { /**/ });
auto computation_result_ab = GetData<A,B>([](Data a, Data b) { /**/ });
But am unsure how to accomplish this.