greg7mdp / parallel-hashmap

A family of header-only, very fast and memory-friendly hashmap and btree containers.
https://greg7mdp.github.io/parallel-hashmap/
Apache License 2.0
2.47k stars 234 forks source link

remove unnecessary creation of std *_error objects #197

Closed ilobilo closed 1 year ago

ilobilo commented 1 year ago

remove creation and then casting to (void) of std::*_error objects if exceptions are disabled this also removes the need for those classes to be available to use this library

bpmckinnon commented 11 months ago

Hi, just noticed this one when updating. I've started getting the unused variable warning again.

I've tested out a change that will remove the warning, but also remove the need to have those types defined.

Let me know what you think.

#ifdef PHMAP_HAVE_EXCEPTIONS
  #define PHMAP_THROW_IMPL_MSG(e, message) throw e(message)
  #define PHMAP_THROW_IMPL(e) throw e
#else
  #define PHMAP_THROW_IMPL_MSG(e, message) do { (void)(message); std::abort(); } while(0)
  #define PHMAP_THROW_IMPL(e) std::abort()
#endif
}  // namespace

static inline void ThrowStdLogicError(const std::string& what_arg) {
  PHMAP_THROW_IMPL_MSG(std::logic_error, what_arg);
}
static inline void ThrowStdBadFunctionCall() {
  PHMAP_THROW_IMPL(std::bad_function_call());
}
ilobilo commented 11 months ago

Oh I didn't notice that what_arg wasn't being used anymore with std::abort(), my bad. But yes, your solution should fix the warning and it's cleaner than using [[maybe_unused]] everywhere.

greg7mdp commented 11 months ago

@bpmckinnon 's solution was checked-in earlier this morning, so we should be all set. Thanks to both of you for your contribs.