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:
parent
d099894ec1
commit
fa4cebadcf
2 changed files with 4 additions and 1 deletions
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue