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

Exception guarantees #105

Closed
Morwenn opened this issue Mar 20, 2017 · 1 comment
Closed

Exception guarantees #105

Morwenn opened this issue Mar 20, 2017 · 1 comment

Comments

@Morwenn
Copy link
Owner

Morwenn commented Mar 20, 2017

Currently cpp-sort provides no specific guarantee about its sorting algorithms when an exception is thrown except the no-leak guarantee (all the memory allocated by the sorting algorithms is freed when an exception occurs).

While making every algorithm noexcept is impossible, it should still be possible to improve the library with regard to exception safety:

  • Analyze and document the current guarantees
  • Check whether simple algorithms can be conditionally noexcept (it may depend on too many things)
  • When values are moved from a collection and back into it, check whether it is possible to make some algorithms put the extracted values back into the collection, albeit in an unspecified order

No matter what is or isn't done, we need to be more specific in the documentation.

@Morwenn
Copy link
Owner Author

Morwenn commented Feb 17, 2018

Making algorithms conditionally noexcept seems difficult. When an algorithm doesn't throw std::bad_alloc, the following operations might still throw:

  • The comparison function
  • The projection function
  • Operations on iterators
  • Move & swap operations

While it might be possible to provide better guarantees when the comparison or projection functions throw, I'm not sure that it is worth it. Recovering when a move or swap throw seems impossible. I guess that I will merely document what can happen with algorithms and let it be.

@Morwenn Morwenn closed this as completed Feb 17, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant