Tessil / sparse-map

C++ implementation of a memory efficient hash map and hash set
MIT License
334 stars 36 forks source link

Add support for platforms without exceptions #19

Closed glebm closed 1 year ago

glebm commented 2 years ago

Also allows controlling the use of exceptions on platforms with exceptions.

Fixes #18

Tessil commented 2 years ago

Hi,

Thanks for your PR. It would effectively be nice to support fno-exceptions, I didn't took the time to do it yet for this library.

Could you check out how it was done for the other tsl projects (like in tsl::robin_map) for example) and check if it can eventually be done the same way in the PR for coherence?

Thanks

glebm commented 2 years ago

I've pushed the following changes:

  1. TSL_ENABLE_EXCEPTIONS -> TSL_NO_EXCEPTIONS.
  2. Detection of the default even without CMake.
  3. Changed the throw_ function to a macro.

I think these are better in this PR as compared to the code in robin_map:

  1. std::abort is used instead of std::terminate, because std::terminate is not available on some platform without exceptions.
  2. fprintf instead of cerr avoids the heavy iostreams dependency.
  3. Always prints the error message before aborting. The other version does so only if TSL_DEBUG is defined.
Tessil commented 2 years ago

Thank you for the update. A few comments.

Yes, we can use std::abort instead but could you then rename TSL_SM_THROW_OR_TERMINATE to TSL_SH_THROW_OR_ABORT

Could you only print when TSL_DEBUG is enabled? I would like to avoid importing cstdio and printing to stderr by default.

Thanks

Tessil commented 1 year ago

I modified a bit your PR to address some of my comments, mainly moving things to sparse_growth_policy.h to avoid a new file, renaming to TSL_SH_* prefix and adapting the test to run an extra -fno-exceptions CI. Hope it is alright for you.

I will merge the PR, thanks.

glebm commented 1 year ago

Thanks for following up on my PR!