From 0c5a66b6661b35040ee9dc0ea443e059dbfcc13a Mon Sep 17 00:00:00 2001 From: Herb Sutter Date: Fri, 18 Dec 2020 12:02:42 -0800 Subject: [PATCH] Added workaround for non-constexpr `std::exchange` --- include/gsl/assert | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/include/gsl/assert b/include/gsl/assert index a57d55d..8f71490 100644 --- a/include/gsl/assert +++ b/include/gsl/assert @@ -114,7 +114,15 @@ public: #else constexpr contract_group (handler h) : chandler(h ? h : []()noexcept{}) { } #endif + +#if __cplusplus >= 202002L 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 void expects (bool b) { assertion(b); }