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 (*)(); using handler = void (*)();
#endif #endif
contract_group (handler h) { set_handler(h); } constexpr contract_group (handler h) { set_handler(h); }
auto set_handler(handler h) -> handler { return std::exchange(chandler, h ? h : []()noexcept{}); } constexpr auto set_handler(handler h) -> handler { return std::exchange(chandler, h ? h : []()noexcept{}); }
auto get_handler() -> handler { return chandler; } constexpr auto get_handler() -> handler { return chandler; }
void expects (bool b) { assertion(b); } constexpr void expects (bool b) { assertion(b); }
void ensures (bool b) { assertion(b); } constexpr void ensures (bool b) { assertion(b); }
private: private:
void assertion(bool b) { if (!b) chandler(); } constexpr void assertion(bool b) { if (!b) chandler(); }
handler chandler; handler chandler;
}; };