General Purpose Debugging Tools
Empirical vectors and arrays
Empirical contains of intelligent versions of STL vectors and arrays that will warn you if you make common errors, but otherwise behave identically to the STL version. Most importantly, they will detect attempts to index to out-of-bounds locations and throw an error. These features are critical for writing code that will be compiled to Javascript with Emscripten, because Valgrind doesn’t run on Javascript. They also save a lot of debugging time when writing native C++ code.
“But wait,” you might say, “surely all of these additional checks slow down your code!” This is true when you compile in debug mode (the default). However, when you compile with the -DNDEBUG flag, these objects are directly replaced with their STL equivalent, removing any slowdown. That way, you can get all the debugging benefits while you’re writing your program, but all the speed benefits when you’re actually using it.
emp::vector Example
#include "Empirical/include/emp/base/vector.hpp"
emp::vector<int> vec({1,2,3});
// You can treat this just like an std::vector<int>
emp::array Example
#include "Empirical/include/emp/base/array.hpp"
emp::array<int, 3> array({1,2,3});
// You can treat this just like an std::array<int, 3>
Empirical asserts
These asserts function similarly to normal asserts, with a few important additional features:
If compiled with Emscripten they will provide pop-up alerts when run in a web browser.
emp_assert can take additional arguments. If the assert is triggered, those extra arguments will be evaluated and printed.
if NDEBUG or EMP_NDEBUG is defined, the expression in emp_assert() is not evaluated.
if EMP_TDEBUG is defined, emp_assert() goes into test mode and records failures, but does not abort. (useful for unit tests of asserts)
Example:
#include "Empirical/include/emp/base/assert.hpp"
int a = 6;
emp_assert(a==5, a);
When compiled in debug mode (i.e. without the -DNDEBUG flag), this will trigger an assertion error and print the value of a.
Empirical also has an emscripten-specific assert, which will only trigger an error when the code was compiled with Emscripten:
#include "Empirical/include/emp/base/emscripten_assert.hpp"
int a = 6;
// If compiled in with emscripten in debug mode,
// this will print a warning and the value of a
emp_emscripten_assert(a==5, a);
If you want your assert to be triggered outside of debug mode, you can use emp_always_assert().
Empirical Warnings
These work very similar to Empirical asserts, except they do not throw assertion errors. When compiled in debug mode, they will print a warning (and any desired additional information) on failure but program execution will continue. When compiled outside of debug mode they do nothing.
#include "Empirical/include/emp/base/assert_warning.hpp"
#include <iostream>
int a = 6;
// If compiled in debug mode, this will print a
// warning and the value of a
emp_assert_warning(a==5, a);
// This will get printed because no assertion
// error will be triggered
std::cout << "Still running!" << std::endl;
If you want your warning to be triggered outside of debug mode, you can use emp_always_assert_warning().
Empirical pointers
Ptr objects behave as normal pointers under most conditions. However, if
a program is compiled with EMP_TRACK_MEM set, then these pointers
perform extra tests to ensure that they point to valid memory and that
memory is freed before pointers are released.
If you trip an assert, you can re-do the run a track a specific pointer
by defining EMP_ABORT_PTR_NEW or EMP_ABORT_PTR_DELETE to the ID of
the pointer in question. This will allow you to track the pointer more
easily in a debugger.
Example:
#include "Empirical/include/emp/base/Ptr.hpp"
emp::Ptr<int> int_ptr;
int_ptr.New(123456); // Store the value 123456 in int_ptr.
std::cout << "*int_ptr = " << *int_ptr << std::endl;
int_ptr.Delete();
API
- MapProxy.hpp
MapProxyMapProxy::MapProxy()MapProxy::emp_GetValue()MapProxy::emp_GetValue()MapProxy::emp_IsInit()MapProxy::operator=()MapProxy::operator+=()MapProxy::operator-=()MapProxy::operator*=()MapProxy::operator/=()MapProxy::operator%=()MapProxy::operator&=()MapProxy::operator|=()MapProxy::operator^=()MapProxy::operator<<=()MapProxy::operator>>=()MapProxy::operator++()MapProxy::operator--()MapProxy::operator++()MapProxy::operator--()MapProxy::operator+()MapProxy::operator-()MapProxy::operator!()MapProxy::operator~()MapProxy::operator+()MapProxy::operator-()MapProxy::operator*()MapProxy::operator/()MapProxy::operator%()MapProxy::operator&()MapProxy::operator|()MapProxy::operator^()MapProxy::operator<<()MapProxy::operator>>()MapProxy::operator&&()MapProxy::operator||()MapProxy::operator==()MapProxy::operator!=()MapProxy::operator<()MapProxy::operator<=()MapProxy::operator>()MapProxy::operator>=()MapProxy::operator[]()MapProxy::operator[]()MapProxy::operator*()MapProxy::operator*()MapProxy::operator&()MapProxy::operator->()MapProxy::operator->*()MapProxy::operator()()MapProxy::operator()()MapProxy::operator,()MapProxy::IsNull()MapProxy::Delete()MapProxy::DeleteArray()MapProxy::operator T&()MapProxy::operator const T&()MapProxy::valueMapProxy::is_init
- Ptr.hpp
PtrStatusFillMemory()FillMemoryFunction()SetPtrDebug()GetPtrDebug()operator<<()operator>>()ToPtr()TrackPtr()NewPtr()CopyPtr()CopyPtrs()ClonePtrs()NewArrayPtr()CopyMemory()PtrPtr::element_typePtr::Ptr()Ptr::Ptr()Ptr::Ptr()Ptr::Ptr()Ptr::Ptr()Ptr::Ptr()Ptr::~Ptr()Ptr::IsNull()Ptr::Raw()Ptr::Raw()Ptr::Cast()Ptr::ConstCast()Ptr::DynamicCast()Ptr::ReinterpretCast()Ptr::New()Ptr::NewArray()Ptr::Delete()Ptr::DeleteArray()Ptr::Hash()Ptr::operator=()Ptr::operator=()Ptr::operator=()Ptr::operator TYPE*()Ptr::operator bool()Ptr::operator bool()Ptr::operator==()Ptr::operator!=()Ptr::operator<()Ptr::operator>()Ptr::operator<=()Ptr::operator>=()Ptr::operator+()Ptr::operator-()Ptr::operator+()Ptr::operator-()Ptr::FillMemoryFunction()Ptr::FillMemory()Ptr::DebugGetCount()Ptr::DebugIsArray()Ptr::DebugGetArrayBytes()Ptr::DebugIsActive()Ptr::OK()Ptr::hash_t
PtrInfoPtrInfo::PtrInfo()PtrInfo::PtrInfo()PtrInfo::PtrInfo()PtrInfo::PtrInfo()PtrInfo::operator=()PtrInfo::operator=()PtrInfo::~PtrInfo()PtrInfo::GetPtr()PtrInfo::GetCount()PtrInfo::GetArrayBytes()PtrInfo::IsActive()PtrInfo::IsArray()PtrInfo::SetArray()PtrInfo::Inc()PtrInfo::Dec()PtrInfo::MarkDeleted()PtrInfo::OK()PtrInfo::ptrPtrInfo::countPtrInfo::statusPtrInfo::array_bytes
PtrTrackerPtrTracker::~PtrTracker()PtrTracker::GetInfo()PtrTracker::GetInfo()PtrTracker::HasPtr()PtrTracker::GetCurID()PtrTracker::GetNumIDs()PtrTracker::GetArrayBytes()PtrTracker::IsDeleted()PtrTracker::IsActive()PtrTracker::IsActiveID()PtrTracker::IsArrayID()PtrTracker::GetIDCount()PtrTracker::New()PtrTracker::NewArray()PtrTracker::IncID()PtrTracker::DecID()PtrTracker::MarkDeleted()PtrTracker::Get()PtrTracker::PtrTracker()PtrTracker::PtrTracker()PtrTracker::PtrTracker()PtrTracker::operator=()PtrTracker::operator=()PtrTracker::ptr_idPtrTracker::id_infoPtrTracker::UNTRACKED_ID
BasePtrBasePtrBasePtr
- always_assert.hpp
- always_assert_warning.hpp
- array.hpp
arrayarray::this_tarray::iteratorarray::const_iteratorarray::reverse_iteratorarray::const_reverse_iteratorarray::value_typearray::size_typearray::referencearray::const_referencearray::operator std::array<T, N>()array::size()array::data()array::data()array::begin()array::begin()array::end()array::end()array::operator[]()array::operator[]()array::back()array::back()array::front()array::front()array::fill()array::resize()array::resize()array::push_back()array::pop_back()array::insert()array::erase()array::emplace()array::emplace_back()array::serialize()array::_dataarray::N
array_iteratorarray_iterator::this_tarray_iterator::array_tarray_iterator::iterator_categoryarray_iterator::value_typearray_iterator::difference_typearray_iterator::pointerarray_iterator::referencearray_iterator::array_iterator()array_iterator::array_iterator()array_iterator::array_iterator()array_iterator::array_iterator()array_iterator::~array_iterator()array_iterator::OK()array_iterator::operator=()array_iterator::operator=()array_iterator::operator ITERATOR_T()array_iterator::operator const ITERATOR_T()array_iterator::operator*()array_iterator::operator*()array_iterator::operator->()array_iterator::operator->()array_iterator::operator++()array_iterator::operator++()array_iterator::operator--()array_iterator::operator--()array_iterator::operator+()array_iterator::operator-()array_iterator::operator-()array_iterator::operator+=()array_iterator::operator-=()array_iterator::operator[]()array_iterator::operator[]()array_iterator::itarray_iterator::arr_ptr
tuple_size
- assert.hpp
- assert_warning.hpp
- emscripten_assert.hpp
- error.hpp
- errors.hpp
- map.hpp
mapmap::key_typemap::mapped_typemap::value_typemap::key_comparemap::value_comparemap::allocator_typemap::referencemap::const_referencemap::pointermap::const_pointermap::iteratormap::const_iteratormap::reverse_iteratormap::const_reverse_iteratormap::difference_typemap::size_typemap::map()map::map()map::map()map::map()map::map()map::map()map::map()map::map()map::operator=()map::operator=()map::operator[]()map::this_tmap::base_tmap::proxy_t
multimapmultimap::key_typemultimap::mapped_typemultimap::value_typemultimap::key_comparemultimap::value_comparemultimap::allocator_typemultimap::referencemultimap::const_referencemultimap::pointermultimap::const_pointermultimap::iteratormultimap::const_iteratormultimap::reverse_iteratormultimap::const_reverse_iteratormultimap::difference_typemultimap::size_typemultimap::multimap()multimap::multimap()multimap::multimap()multimap::multimap()multimap::multimap()multimap::multimap()multimap::multimap()multimap::multimap()multimap::operator=()multimap::operator=()multimap::operator[]()multimap::this_tmultimap::base_tmultimap::proxy_t
- notify.hpp
notifynotify::id_tnotify::message_tnotify::except_data_tnotify::id_arg_tnotify::message_arg_tnotify::response_tnotify::exit_fun_tnotify::Typenotify::TypeID()notify::ColorTypeID()notify::GetData()notify::MessageHandlers()notify::DebugHandlers()notify::WarningHandlers()notify::ErrorHandlers()notify::AddExitHandler()notify::ClearExitHandlers()notify::ReplaceExitHandlers()notify::ReplaceExitHandlers()notify::Exit()notify::Notify()notify::Pause()notify::Unpause()notify::Message()notify::Debug()notify::Warning()notify::Error()notify::TestWarning()notify::TestError()notify::AddHandler()notify::AddHandler()notify::Ignore()notify::SetVerbose()notify::Verbose()notify::Exception()notify::GetExceptions()notify::GetException()notify::CountExceptions()notify::CountExceptions()notify::HasExceptions()notify::HasException()notify::ClearExceptions()notify::ClearException()notify::num_typesnotify::ExceptInfonotify::HandlerSetnotify::HandlerSet::HandlerSet()notify::HandlerSet::HandlerSet()notify::HandlerSet::HandlerSet()notify::HandlerSet::~HandlerSet()notify::HandlerSet::GetExitOnFail()notify::HandlerSet::SetExitOnFail()notify::HandlerSet::Trigger()notify::HandlerSet::Trigger()notify::HandlerSet::Trigger()notify::HandlerSet::Add()notify::HandlerSet::Add()notify::HandlerSet::Add()notify::HandlerSet::Clear()notify::HandlerSet::Replace()notify::HandlerSet::Replace()notify::HandlerSet::fun_tnotify::HandlerSet::fun_no_data_tnotify::HandlerSet::fun_msg_only_tnotify::HandlerSet::handlersnotify::HandlerSet::exit_on_fail
notify::NotifyData
- optional.hpp
- unordered_map.hpp
unordered_mapunordered_map::key_typeunordered_map::mapped_typeunordered_map::value_typeunordered_map::hasherunordered_map::key_equalunordered_map::allocator_typeunordered_map::referenceunordered_map::const_referenceunordered_map::pointerunordered_map::const_pointerunordered_map::iteratorunordered_map::const_iteratorunordered_map::local_iteratorunordered_map::const_local_iteratorunordered_map::difference_typeunordered_map::size_typeunordered_map::unordered_map()unordered_map::unordered_map()unordered_map::unordered_map()unordered_map::unordered_map()unordered_map::unordered_map()unordered_map::unordered_map()unordered_map::unordered_map()unordered_map::unordered_map()unordered_map::unordered_map()unordered_map::unordered_map()unordered_map::unordered_map()unordered_map::unordered_map()unordered_map::unordered_map()unordered_map::unordered_map()unordered_map::unordered_map()unordered_map::unordered_map()unordered_map::unordered_map()unordered_map::operator=()unordered_map::operator=()unordered_map::operator[]()unordered_map::this_tunordered_map::base_tunordered_map::proxy_t
unordered_multimapunordered_multimap::key_typeunordered_multimap::mapped_typeunordered_multimap::value_typeunordered_multimap::hasherunordered_multimap::key_equalunordered_multimap::allocator_typeunordered_multimap::referenceunordered_multimap::const_referenceunordered_multimap::pointerunordered_multimap::const_pointerunordered_multimap::iteratorunordered_multimap::const_iteratorunordered_multimap::local_iteratorunordered_multimap::const_local_iteratorunordered_multimap::difference_typeunordered_multimap::size_typeunordered_multimap::unordered_multimap()unordered_multimap::unordered_multimap()unordered_multimap::unordered_multimap()unordered_multimap::unordered_multimap()unordered_multimap::unordered_multimap()unordered_multimap::unordered_multimap()unordered_multimap::unordered_multimap()unordered_multimap::unordered_multimap()unordered_multimap::unordered_multimap()unordered_multimap::unordered_multimap()unordered_multimap::unordered_multimap()unordered_multimap::unordered_multimap()unordered_multimap::unordered_multimap()unordered_multimap::unordered_multimap()unordered_multimap::unordered_multimap()unordered_multimap::unordered_multimap()unordered_multimap::unordered_multimap()unordered_multimap::operator=()unordered_multimap::operator=()unordered_multimap::operator[]()unordered_multimap::this_tunordered_multimap::base_tunordered_multimap::proxy_t
- vector.hpp
operator<<()operator>>()vectorvector::iteratorvector::const_iteratorvector::reverse_iteratorvector::const_reverse_iteratorvector::value_typevector::size_typevector::referencevector::const_referencevector::vector()vector::vector()vector::vector()vector::vector()vector::vector()vector::vector()vector::vector()vector::~vector()vector::size()vector::begin()vector::begin()vector::end()vector::end()vector::cbegin()vector::cend()vector::rbegin()vector::rbegin()vector::rend()vector::rend()vector::crbegin()vector::crend()vector::resize()vector::resize()vector::operator=()vector::operator[]()vector::operator[]()vector::back()vector::back()vector::front()vector::front()vector::push_back()vector::pop_back()vector::insert()vector::erase()vector::emplace()vector::emplace_back()vector::revisionvector::this_tvector::stdv_tvector::MAX_SIZEvector::iterator_wrappervector::iterator_wrapper::this_tvector::iterator_wrapper::wrapped_tvector::iterator_wrapper::vec_tvector::iterator_wrapper::iterator_wrapper()vector::iterator_wrapper::iterator_wrapper()vector::iterator_wrapper::iterator_wrapper()vector::iterator_wrapper::iterator_wrapper()vector::iterator_wrapper::~iterator_wrapper()vector::iterator_wrapper::OK()vector::iterator_wrapper::operator=()vector::iterator_wrapper::operator=()vector::iterator_wrapper::operator ITERATOR_T()vector::iterator_wrapper::operator const ITERATOR_T()vector::iterator_wrapper::operator*()vector::iterator_wrapper::operator*()vector::iterator_wrapper::operator->()vector::iterator_wrapper::operator->()vector::iterator_wrapper::operator++()vector::iterator_wrapper::operator++()vector::iterator_wrapper::operator--()vector::iterator_wrapper::operator--()vector::iterator_wrapper::operator+()vector::iterator_wrapper::operator-()vector::iterator_wrapper::operator-()vector::iterator_wrapper::operator+=()vector::iterator_wrapper::operator-=()vector::iterator_wrapper::operator[]()vector::iterator_wrapper::v_ptrvector::iterator_wrapper::revisionvector::iterator_wrapper::ErrorCode()vector::iterator_wrapper::ErrorStart()
vectorvector::iteratorvector::const_iteratorvector::value_typevector::size_typevector::referencevector::const_referencevector::vector()vector::vector()vector::vector()vector::vector()vector::vector()vector::vector()vector::vector()vector::resize()vector::resize()vector::operator=()vector::operator[]()vector::operator[]()vector::back()vector::back()vector::front()vector::front()vector::pop_back()vector::this_tvector::stdv_tvector::MAX_SIZE