Implements easier assertions for iterators
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2020-04-22 12:44:50 +02:00
parent 43e612122c
commit 195043d4c5
2 changed files with 8 additions and 3 deletions

View File

@@ -12,12 +12,12 @@
ss << #expr << "\""; \
throw std::logic_error(ss.str()); \
}
#define AssertForEach(iterator, assertion) { for (auto item: iterator) Assert(assertion)}
#else
// Assert is empty if NO_ASSERT is defined.
#define Assert(expr) ;
#define AssertForEach(iterator, assertion) ;
#endif
#define AssertNotNull(value) Assert(value != nullptr)
#define UnpackWeakPtr(weakPtr, sharedPtr) \
Assert(!weakPtr.expired()); \
auto sharedPtr = weakPtr.lock();
#define AssertAllNotNull(iterator) AssertForEach(iterator, item != nullptr)