@@ -26,6 +26,7 @@ import stdexec;
2626# include " __concepts.hpp"
2727# include " __config.hpp"
2828# include " __memory.hpp"
29+ # include " __scope.hpp"
2930# include " __type_traits.hpp"
3031# include " __typeinfo.hpp"
3132# include " __utility.hpp"
@@ -37,6 +38,7 @@ import stdexec;
3738
3839# include < bit>
3940# include < exception>
41+ # include < functional>
4042# include < memory>
4143# include < span>
4244# include < type_traits>
@@ -614,27 +616,6 @@ namespace STDEXEC::__any
614616
615617 // ////////////////////////////////////////////////////////////////////////////////////////
616618 // __emplace_into
617- template <class _Alloc2 >
618- struct __dealloc_guard
619- {
620- _Alloc2 &__alloc;
621- typename std::allocator_traits<_Alloc2>::pointer __ptr;
622- bool __dismissed = false ;
623-
624- constexpr void __dismiss () noexcept
625- {
626- __dismissed = true ;
627- }
628-
629- constexpr ~__dealloc_guard () noexcept
630- {
631- if (!__dismissed)
632- {
633- std::allocator_traits<_Alloc2>::deallocate (__alloc, __ptr, 1 );
634- }
635- }
636- };
637-
638619 template <class _Model , class _Allocator , class ... _Args>
639620 constexpr _Model &__emplace_into ([[maybe_unused]] _Allocator const &__alloc,
640621 [[maybe_unused]] __iroot *&__root_ptr,
@@ -656,12 +637,14 @@ namespace STDEXEC::__any
656637 }
657638 else
658639 {
659- auto __alloc2 = STDEXEC ::__rebind_allocator<_Model>(__alloc);
660- using __traits_t = std::allocator_traits<decltype (__alloc2)>;
661- auto *const __model = __traits_t::allocate (__alloc2, 1 );
662- __dealloc_guard<decltype (__alloc2)> __guard{__alloc2, __model};
640+ auto __alloc2 = STDEXEC ::__rebind_allocator<_Model>(__alloc);
641+ using __traits_t = std::allocator_traits<decltype (__alloc2)>;
642+ auto *const __model = __traits_t::allocate (__alloc2, 1 );
643+
644+ auto __guard = __scope_guard{&__traits_t ::deallocate, std::ref (__alloc2), __model, 1 };
663645 __traits_t::construct (__alloc2, __model, static_cast <_Args &&>(__args)...);
664646 __guard.__dismiss ();
647+
665648 *__std::start_lifetime_as<__tagged_ptr>(__buff.data ()) = __tagged_ptr (__model);
666649 return *__model;
667650 }
0 commit comments