0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-02-03 09:56:38 -05:00

util: Make Assume() usable as unary expression

This commit is contained in:
MarcoFalke 2021-02-28 16:38:19 +01:00
parent d099894ec1
commit fa4cebadcf
No known key found for this signature in database
GPG key ID: CE2B75697E69A548
2 changed files with 4 additions and 1 deletions

View file

@ -76,6 +76,9 @@ BOOST_AUTO_TEST_CASE(util_check)
const int two = *Assert(p_two);
Assert(two == 2);
Assert(true);
// Check that Assume can be used as unary expression
const bool result{Assume(two == 2)};
Assert(result);
}
BOOST_AUTO_TEST_CASE(util_criticalsection)

View file

@ -69,7 +69,7 @@ T get_pure_r_value(T&& val)
#ifdef ABORT_ON_FAILED_ASSUME
#define Assume(val) Assert(val)
#else
#define Assume(val) ((void)(val))
#define Assume(val) ([&]() -> decltype(get_pure_r_value(val)) { auto&& check = (val); return std::forward<decltype(get_pure_r_value(val))>(check); }())
#endif
#endif // BITCOIN_UTIL_CHECK_H