Skip to content

Commit

Permalink
Merge pull request #1374 from NVIDIA/destroy-at
Browse files Browse the repository at this point in the history
replace explicit dtor calls with `std::destroy_at`
  • Loading branch information
ericniebler authored Jul 16, 2024
2 parents 6d16bd1 + d260754 commit 9428f35
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
5 changes: 3 additions & 2 deletions include/stdexec/__detail/__optional.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

#include <new>
#include <exception>
#include <memory>
#include <utility>

namespace stdexec {
Expand Down Expand Up @@ -70,7 +71,7 @@ namespace stdexec {

~__optional() {
if (__has_value) {
__value.~_Tp();
std::destroy_at(std::addressof(__value));
}
}

Expand Down Expand Up @@ -135,7 +136,7 @@ namespace stdexec {

void reset() noexcept {
if (__has_value) {
__value.~_Tp();
std::destroy_at(std::addressof(__value));
__has_value = false;
}
}
Expand Down
10 changes: 2 additions & 8 deletions include/stdexec/__detail/__variant.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "__utility.hpp"

#include <cstddef>
#include <memory>
#include <new>
#include <type_traits>

Expand Down Expand Up @@ -77,14 +78,7 @@ namespace stdexec {
__destroy() noexcept {
auto __index = std::exchange(__index_, __variant_npos);
if (__variant_npos != __index) {
#if STDEXEC_NVHPC()
// Unknown nvc++ name lookup bug
((_Is == __index ? static_cast<_Ts *>(__get_ptr())->_Ts::~_Ts() : void(0)), ...);
#else
// casting the destructor expression to void is necessary for MSVC in
// /permissive- mode.
((_Is == __index ? void((*static_cast<_Ts *>(__get_ptr())).~_Ts()) : void(0)), ...);
#endif
((_Is == __index ? std::destroy_at(static_cast<_Ts *>(__get_ptr())) : void(0)), ...);
}
}

Expand Down

0 comments on commit 9428f35

Please sign in to comment.