Capital-Asterisk / longeronpp

"Longeron++" C++17 library for simple memory-efficient or 'data-oriented' structures
MIT License
32 stars 3 forks source link

Custom asserts #7

Closed Capital-Asterisk closed 2 years ago

Capital-Asterisk commented 2 years ago

Resolves #4

This is not an assertion library, so I'd rather keep it simple.

It's customizable, and produces nice readable messages. It has an option to list variables related to the assertion:

This code:

IdRegistry<int> reg(64); // construct with reserved size of 64
reg.remove(42);

errors with this message:

Assertion Failed: ID does not exist
* File: /home/neal/Desktop/Compile-Hawthorn/longeron++/src/longeron/id_management/registry.hpp
* Line: 77
* Func: void lgrn::IdRegistry<ID_T, NO_AUTO_RESIZE>::remove(ID_T) [with ID_T = int; bool NO_AUTO_RESIZE = false]
* Expr: exists(id)
* Vars:
  * std::size_t(id): 42

using this assert:

void remove(ID_T id)
{
    LGRN_ASSERTMV(exists(id), "ID does not exist", std::size_t(id));

    m_deleted.set(id_int_t(id));
}