From b77eaa87ee96cf88e156e6ba00f85fde0e800f33 Mon Sep 17 00:00:00 2001 From: Herb Sutter Date: Fri, 18 Dec 2020 11:40:50 -0800 Subject: [PATCH] Make `contract_group` a literal type --- include/gsl/assert | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/include/gsl/assert b/include/gsl/assert index b5d2669..5488122 100644 --- a/include/gsl/assert +++ b/include/gsl/assert @@ -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; };