diff --git a/include/proxy/v5/detail/core.h b/include/proxy/v5/detail/core.h index 59fcd3cd..29ef3ea7 100644 --- a/include/proxy/v5/detail/core.h +++ b/include/proxy/v5/detail/core.h @@ -362,42 +362,48 @@ struct destroying_guard { struct relocate_dispatch; +template +using erased_ptr_t = std::conditional_t; +template +constexpr auto invocation_function = + [](erased_ptr_t ptr, Args... args) noexcept(NE) -> R { + auto* self = std::launder( + static_cast>*>(ptr)); + if constexpr (std::is_same_v) { + [self](void* rhs) { + if constexpr (is_bitwise_trivially_relocatable_v

) { + if constexpr (!std::is_empty_v

) { + std::uninitialized_copy_n(reinterpret_cast(self), + sizeof(P), static_cast(rhs)); + } + } else { + destroying_guard

guard{self}; + std::construct_at(static_cast(rhs), std::move(*self)); + } + }(args...); + } else if constexpr (Q == qualifier_type::rv) { + destroying_guard

guard{self}; + return invoke_dispatch(get_operand(self), + std::forward(args)...); + } else { + return invoke_dispatch(get_operand(self), + std::forward(args)...); + } +}; + template struct signature_traits : inapplicable_traits {}; template struct signature_traits_impl : applicable_traits { using return_type = R; - using pointer_type = std::conditional_t; - using function_type = R(pointer_type, Args...) noexcept(NE); + using function_type = R(erased_ptr_t, Args...) noexcept(NE); template static constexpr auto invoke = - [](pointer_type ptr, Args... args) noexcept(NE) -> R { - auto* self = std::launder( - static_cast>*>(ptr)); - if constexpr (std::is_same_v) { - [self](void* rhs) { - if constexpr (is_bitwise_trivially_relocatable_v

) { - if constexpr (!std::is_empty_v

) { - std::uninitialized_copy_n(reinterpret_cast(self), - sizeof(P), static_cast(rhs)); - } - } else { - destroying_guard

guard{self}; - std::construct_at(static_cast(rhs), std::move(*self)); - } - }(args...); - } else if constexpr (Q == qualifier_type::rv) { - destroying_guard

guard{self}; - return invoke_dispatch(get_operand(self), - std::forward(args)...); - } else { - return invoke_dispatch(get_operand(self), - std::forward(args)...); - } - }; + invocation_function; static constexpr qualifier_type this_qualifier = Q; template