Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 8 additions & 25 deletions include/stdexec/__detail/__any.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -37,6 +38,7 @@ import stdexec;

# include <bit>
# include <exception>
# include <functional>
# include <memory>
# include <span>
# include <type_traits>
Expand Down Expand Up @@ -614,27 +616,6 @@ namespace STDEXEC::__any

//////////////////////////////////////////////////////////////////////////////////////////
// __emplace_into
template <class _Alloc2>
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 <class _Model, class _Allocator, class... _Args>
constexpr _Model &__emplace_into([[maybe_unused]] _Allocator const &__alloc,
[[maybe_unused]] __iroot *&__root_ptr,
Expand All @@ -656,12 +637,14 @@ namespace STDEXEC::__any
}
else
{
auto __alloc2 = STDEXEC::__rebind_allocator<_Model>(__alloc);
using __traits_t = std::allocator_traits<decltype(__alloc2)>;
auto *const __model = __traits_t::allocate(__alloc2, 1);
__dealloc_guard<decltype(__alloc2)> __guard{__alloc2, __model};
auto __alloc2 = STDEXEC::__rebind_allocator<_Model>(__alloc);
using __traits_t = std::allocator_traits<decltype(__alloc2)>;
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;
}
Expand Down
Loading