s-yata / marisa-trie

MARISA: Matching Algorithm with Recursively Implemented StorAge
Other
506 stars 89 forks source link

Use MARISA_DEBUG_IF in scoped-*.h as opposed to MARISA_THROW_IF #32

Closed tony-mak closed 3 years ago

tony-mak commented 3 years ago

Hi folks

With this change, developers can take the marisa library without being forced to enable exceptions for their whole library / application by using "-fexceptions". However, some projects decide to not to enable exceptions.

The reason that we have to enable exceptions for the whole application/library is that the marisa library throws exceptions in header files. If we don't enable exceptions, there will be two implementations of those functions that throw. This violates the ODR.

There are only two places where we throw exceptions from header files in non-debug mode. IMO, it might be reasonable to use MARISA_DEBUG_IF there instead of MARISA_THROW_IF.

Also, I think the new behavior is also closer to unique_ptr::reset. From cppreference:

A test for self-reset, i.e. whether ptr points to an object already managed by *this, is not performed, except where provided as a compiler extension or as a debugging assert.

MARISA_DEBUG_IF is like the debugging assert that it mentions.

What do you think?

Thanks!

s-yata commented 3 years ago

Thank you.