Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

is it necessary to have restriction for IComparable? #52

Closed
micampbell opened this issue Oct 28, 2020 · 2 comments
Closed

is it necessary to have restriction for IComparable? #52

micampbell opened this issue Oct 28, 2020 · 2 comments

Comments

@micampbell
Copy link

micampbell commented Oct 28, 2020

For using SimplePriorityQueue...As far as I can tell from the implemented constraint, where TPriority : IComparable<TPriority>,
this is based on the fact that some constructors use Comparer<TPriority>.Default
but what if I have only intend to use IComparer (instead of IComparable) and the TPriority object cannot inherit from IComparable<>?
for example, I want to write something like: var priorityQueue = new SimplePriorityQueue<int, Vertex>(new VertexSorter());
where VertexSorter inherits from IComparer<Vertex>', and not change the class Vertexto inherit fromIComparable`.

I'm not sure that the implementation can have it both ways, but I thought I'd pose the question to you. Otherwise, my options are to write a small wrapper class for Vertex or try to remove the restriction from a local version of your awesome library.

@micampbell
Copy link
Author

Interestingly, I commented where TPriority : IComparable<TPriority> from SimplePriorityQueue (and related: Generic.., IPriorityQueue, and IFixedSize..) and it compiles and runs just fine with my code. However, I'm not going make a pull request because I'm not clear on the implications of this change.

@BlueRaja
Copy link
Owner

Good catch! I forgot to remove this restriction when I added the Comparer constructors. This is fixed in v5.1.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants