diff --git a/src/Assert.hpp b/src/Assert.hpp index 503b353..c8a3c76 100644 --- a/src/Assert.hpp +++ b/src/Assert.hpp @@ -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) diff --git a/tests/AssertTests.cpp b/tests/AssertTests.cpp index dc79505..7d627ab 100644 --- a/tests/AssertTests.cpp +++ b/tests/AssertTests.cpp @@ -19,3 +19,8 @@ TEST_CASE("Multiple asserts", "[Utilities]") { } TEST_CASE("AssertNotNull throws if nullptr", "[Utilities]") { REQUIRE_THROWS(TestWrapperNotNull(nullptr)); } + +TEST_CASE("Assert for each", "[Utilities]") { + auto i = {10, 500, 2300, 454}; + AssertForEach(i, item > 0) +}