Make contract_group a literal type

This commit is contained in:
Herb Sutter 2020-12-18 11:40:50 -08:00
parent 9033021831
commit b77eaa87ee

View File

@ -109,14 +109,14 @@ public:
using handler = void (*)();
#endif
contract_group (handler h) { set_handler(h); }
auto set_handler(handler h) -> handler { return std::exchange(chandler, h ? h : []()noexcept{}); }
auto get_handler() -> handler { return chandler; }
constexpr contract_group (handler h) { set_handler(h); }
constexpr auto set_handler(handler h) -> handler { return std::exchange(chandler, h ? h : []()noexcept{}); }
constexpr auto get_handler() -> handler { return chandler; }
void expects (bool b) { assertion(b); }
void ensures (bool b) { assertion(b); }
constexpr void expects (bool b) { assertion(b); }
constexpr void ensures (bool b) { assertion(b); }
private:
void assertion(bool b) { if (!b) chandler(); }
constexpr void assertion(bool b) { if (!b) chandler(); }
handler chandler;
};