I need to create a framework that computes the result of the divide-et-conquest algorithm in parallel. To use the framework, the user needs to somehow specify a procedure that implements the โdivisionโ phase (function from T to T), the โwinโ phase (function from D to D), and T and D themselves.
I thought it would be nice to define two abstract classes: BaseDivideand BaseConquer, which declares a pure virtual method computewith the correct types: this way I have a type, (in terms of structure) with a user-defined function that is enabled through the output of abstract classes.
I was thinking of using templates to pass types to the framework, so the user does not need to create them to use the framework, so something like this:
template <typename T, typename D, typename Divide, typename Conquer>
D compute(T arg);
My problem is that I want Divide and Conquer to be derived types BaseDivideand BaseConquer: is there a way to force it at compile time? Also: do you think I can achieve a similar result with a cleaner design?
source
share