Added workaround for non-constexpr std::exchange

This commit is contained in:
Herb Sutter 2020-12-18 12:02:42 -08:00
parent 248a7cbdce
commit 0c5a66b666

View File

@ -114,7 +114,15 @@ public:
#else #else
constexpr contract_group (handler h) : chandler(h ? h : []()noexcept{}) { } constexpr contract_group (handler h) : chandler(h ? h : []()noexcept{}) { }
#endif #endif
#if __cplusplus >= 202002L
constexpr 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{}); }
#else
constexpr auto set_handler(handler h) -> handler { auto old = chandler;
chandler = h ? h : []()noexcept{};
return old;
}
#endif
constexpr auto get_handler() -> handler { return chandler; } constexpr auto get_handler() -> handler { return chandler; }
constexpr void expects (bool b) { assertion(b); } constexpr void expects (bool b) { assertion(b); }