mirror of
https://github.com/microsoft/GSL.git
synced 2024-11-03 17:56:43 -05:00
Removed double .load
Require `chandler` to be never null by installing `[]()noexcept{}` as the handler if given a null pointer. This lets us remove the double test in `assertion`.
This commit is contained in:
parent
b7548fd1cd
commit
0cbb9e221d
@ -104,15 +104,16 @@ class contract_group {
|
||||
public:
|
||||
using handler = void (*)() noexcept;
|
||||
|
||||
contract_group(handler h) : chandler{h} { }
|
||||
auto set_handler(handler h) -> handler { return chandler.exchange(h); }
|
||||
contract_group(handler h) { set_handler(h); }
|
||||
auto set_handler(handler h) -> handler { if (!h) h = []()noexcept{};
|
||||
return chandler.exchange(h); }
|
||||
auto get_handler() -> handler { return chandler; }
|
||||
|
||||
auto expects(bool b) { assertion(b); }
|
||||
auto ensures(bool b) { assertion(b); }
|
||||
|
||||
private:
|
||||
auto assertion(bool b) { if (!b && chandler.load()) chandler.load()(); }
|
||||
auto assertion(bool b) { if (!b) chandler.load()(); }
|
||||
std::atomic<handler> chandler;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user