✅ Replace enum with class name
I'm working on an API right now which, for those familiar with OpenMP, is a parallel programming API which aims to implement OpenMP functionality as faithfully as possible.
With that said, the current API has the following syntax for declaring a parallel-for loop:
I am looking at the possibility of implementing custom schedulers as defined by the user through some sort of consistent interface. I am not looking for API/ABI compatibility, but source code compatibility would be highly desired. What I would like is to be able to have the
DotMP.Schedule
enum be replaced with classes that implement the IScheduler
interface. How would I incorporate this into the type signature to be source-compatible? For instance:
(Before you ask: yes, I know about the TPL. Yes, I have my reasons for not using it. No, I don't want to get into them in this thread, I want to focus on the issue at hand. The provided function is extremely similar to System.Threading.Tasks.Parallel.For
on the surface, but it is implemented significantly different, and there's much more to my library besides this that the TPL is not flexible enough to do.)2 Replies
Use an interface?
Oh you mentioned that. What's the issue exactly?
i guess what type i need to accept in the function to be able to pass a class name and instantiate it, presupposing that it implements the interface
sorry for the late response
like my type signature would need to be
the "normal" solution would be to supply a generic argument but that doesn't mesh well with source compatibility
(also how would I verify that said type implements
IScheduler
and instantiate an object of that type)
@mtreit sorry for ping just wanted to bring your attention to this
nevermind, i got it all figured out. it's a mess but it's source-compatible and performant