From f28a4c680ce5e047ff55d8442d194bfd90f977f2 Mon Sep 17 00:00:00 2001 From: Eric Niebler Date: Tue, 18 Aug 2026 15:31:50 -0700 Subject: [PATCH] replace custom scope guard with generic one in `__any` --- include/stdexec/__detail/__any.hpp | 33 ++++++++---------------------- 1 file changed, 8 insertions(+), 25 deletions(-) diff --git a/include/stdexec/__detail/__any.hpp b/include/stdexec/__detail/__any.hpp index 7325c8288..05f886497 100644 --- a/include/stdexec/__detail/__any.hpp +++ b/include/stdexec/__detail/__any.hpp @@ -26,6 +26,7 @@ import stdexec; # include "__concepts.hpp" # include "__config.hpp" # include "__memory.hpp" +# include "__scope.hpp" # include "__type_traits.hpp" # include "__typeinfo.hpp" # include "__utility.hpp" @@ -37,6 +38,7 @@ import stdexec; # include # include +# include # include # include # include @@ -614,27 +616,6 @@ namespace STDEXEC::__any ////////////////////////////////////////////////////////////////////////////////////////// // __emplace_into - template - struct __dealloc_guard - { - _Alloc2 &__alloc; - typename std::allocator_traits<_Alloc2>::pointer __ptr; - bool __dismissed = false; - - constexpr void __dismiss() noexcept - { - __dismissed = true; - } - - constexpr ~__dealloc_guard() noexcept - { - if (!__dismissed) - { - std::allocator_traits<_Alloc2>::deallocate(__alloc, __ptr, 1); - } - } - }; - template constexpr _Model &__emplace_into([[maybe_unused]] _Allocator const &__alloc, [[maybe_unused]] __iroot *&__root_ptr, @@ -656,12 +637,14 @@ namespace STDEXEC::__any } else { - auto __alloc2 = STDEXEC::__rebind_allocator<_Model>(__alloc); - using __traits_t = std::allocator_traits; - auto *const __model = __traits_t::allocate(__alloc2, 1); - __dealloc_guard __guard{__alloc2, __model}; + auto __alloc2 = STDEXEC::__rebind_allocator<_Model>(__alloc); + using __traits_t = std::allocator_traits; + auto *const __model = __traits_t::allocate(__alloc2, 1); + + auto __guard = __scope_guard{&__traits_t::deallocate, std::ref(__alloc2), __model, 1}; __traits_t::construct(__alloc2, __model, static_cast<_Args &&>(__args)...); __guard.__dismiss(); + *__std::start_lifetime_as<__tagged_ptr>(__buff.data()) = __tagged_ptr(__model); return *__model; }