From 11d4e746209bbebc4970ed6ed8f7c7b408532c6c Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Fri, 17 Jan 2020 14:17:18 -0800 Subject: [PATCH] scope guard: ensure implicit lambdas are always inline --- libraries/libvapours/include/vapours/defines.hpp | 4 +++- .../libvapours/include/vapours/util/util_scope_guard.hpp | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/libraries/libvapours/include/vapours/defines.hpp b/libraries/libvapours/include/vapours/defines.hpp index c2ead65f2..ac3668397 100644 --- a/libraries/libvapours/include/vapours/defines.hpp +++ b/libraries/libvapours/include/vapours/defines.hpp @@ -13,7 +13,6 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - #pragma once #include "includes.hpp" @@ -40,6 +39,9 @@ #define CONST_FOLD(x) (__builtin_constant_p(x) ? (x) : (x)) +#define WRAP_TEMPLATE_CONSTANT(...) ([] { using U = union { static constexpr auto GetValue() { return __VA_ARGS__; } }; return U{}; }()) +#define UNWRAP_TEMPLATE_CONSTANT(tpnm) (tpnm::GetValue()) + #define CONCATENATE_IMPL(S1, s2) s1##s2 #define CONCATENATE(s1, s2) CONCATENATE_IMPL(s1, s2) diff --git a/libraries/libvapours/include/vapours/util/util_scope_guard.hpp b/libraries/libvapours/include/vapours/util/util_scope_guard.hpp index fc6ad842c..170e59821 100644 --- a/libraries/libvapours/include/vapours/util/util_scope_guard.hpp +++ b/libraries/libvapours/include/vapours/util/util_scope_guard.hpp @@ -54,5 +54,5 @@ namespace ams::util { } -#define SCOPE_GUARD ::ams::util::impl::ScopeGuardOnExit() + [&]() +#define SCOPE_GUARD ::ams::util::impl::ScopeGuardOnExit() + [&]() ALWAYS_INLINE_LAMBDA #define ON_SCOPE_EXIT auto ANONYMOUS_VARIABLE(SCOPE_EXIT_STATE_) = SCOPE_GUARD