File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed
libraries/sysiolib/core/sysio Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -44,6 +44,36 @@ namespace sysio {
4444 internal_use_do_not_use::sysio_assert_message (false , msg.data (), msg.size ());
4545 }
4646
47+ /* *
48+ * Assert if the predicate fails and use callable to generate assertion message.
49+ *
50+ * Allows for "lazily" generating an expensive message only when the predicate fails.
51+ *
52+ * @ingroup system
53+ *
54+ * Example:
55+ * @code
56+ * eosio::check(eosio::current_time_point() >= time, [&] {
57+ * std::string err_msg = "Upgrade failed: Account '";
58+ * err_msg += account.to_string();
59+ * err_msg += "' disabled until ";
60+ * err_msg += time.to_string();
61+ * return err_msg;
62+ * });
63+ * @endcode
64+ */
65+ template <
66+ typename F,
67+ typename = std::enable_if_t <
68+ std::is_invocable_v<F> &&
69+ std::is_convertible_v<std::invoke_result_t <F>, std::string_view>
70+ >
71+ >
72+ inline void check (bool pred, F&& msg_generator) {
73+ if (!pred)
74+ check (pred, std::string_view (msg_generator ()));
75+ }
76+
4777 /* *
4878 * Assert if the predicate fails and use the supplied message.
4979 *
You can’t perform that action at this time.
0 commit comments