4#include <Rose/Exception.h>
19template<
class F,
class... Args>
22 static auto test(U *p) ->
decltype((*p)(std::declval<Args>()...), void(), std::true_type());
25 static auto test(...) ->
decltype(std::false_type());
27 static constexpr bool value =
decltype(test<F>(0))::value;
78template<
class Value,
class Predicate>
79typename std::enable_if<is_invocable<Predicate, Value>::value, Value&>::type
80affirm(Value&& value, Predicate predicate) {
86template<
class Value,
class Predicate>
87typename std::enable_if<is_invocable<Predicate, Value>::value, Value&>::type
88affirm(Value& value, Predicate predicate) {
94template<
class Value,
class Predicate>
95typename std::enable_if<is_invocable<Predicate, Value>::value, Value&>::type
96affirm(Value&& value, Predicate predicate, std::string
const& message) {
102template<
class Value,
class Predicate>
103typename std::enable_if<is_invocable<Predicate, Value>::value, Value&>::type
104affirm(Value& value, Predicate predicate, std::string
const& message) {
105 if (predicate(value))
142 throw AffirmationError(
"value does not evaluate to true in Boolean context");
150 throw AffirmationError(
"value does not evaluate to true in Boolean context");
155affirm(Value&& value, std::string
const& message) {
163affirm(Value& value, std::string
const& message) {
193template<
class Po
inter>
201template<
class Po
inter>
216#define ROSE_AFFIRM(VALUE, PREDICATE) ::Rose::affirm((VALUE), [](auto x) -> bool { return PREDICATE; })
Exceptions for value assertions.
AffirmationError(const std::string &mesg)
Construct error with message.
Base class for all ROSE exceptions.
std::enable_if< is_invocable< Predicate, Value >::value, Value & >::type affirm(Value &&value, Predicate predicate)
Test something about a value and then return it.
Pointer & notnull(Pointer &&pointer)
Check for non-null pointer.