From 0a3e8d624203fc27e3b961c55393dbfd8449d45d Mon Sep 17 00:00:00 2001 From: Benjamin Brock Date: Thu, 13 Mar 2025 16:19:04 -0700 Subject: [PATCH] Fix for Clang, which has difficulty with mixed C complex numbers. --- include/binsparse/detail/cpp/array.hpp | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/include/binsparse/detail/cpp/array.hpp b/include/binsparse/detail/cpp/array.hpp index dfcac33..9842cef 100644 --- a/include/binsparse/detail/cpp/array.hpp +++ b/include/binsparse/detail/cpp/array.hpp @@ -63,6 +63,16 @@ inline array_ptr_variant_t get_typed_ptr(bsp_array_t array) { return {}; } +template +constexpr static bool is_c_complex_v = + std::is_same_v, _Complex double> || + std::is_same_v, _Complex float>; + +template +constexpr static bool mixed_c_complex_v = + (is_c_complex_v && !is_c_complex_v) || + (!is_c_complex_v && is_c_complex_v); + } // namespace __detail } // namespace binsparse @@ -76,7 +86,8 @@ inline void bsp_array_read(bsp_array_t array, size_t index, T& value) { [&](auto* ptr) { using U = std::remove_pointer_t; - if constexpr (std::is_assignable_v) { + if constexpr (std::is_convertible_v && + !binsparse::__detail::mixed_c_complex_v) { value = ptr[index]; } }, @@ -92,7 +103,8 @@ inline void bsp_array_write(bsp_array_t array, size_t index, U value) { [&](auto* ptr) { using T = std::remove_pointer_t; - if constexpr (std::is_assignable_v) { + if constexpr (std::is_convertible_v && + !binsparse::__detail::mixed_c_complex_v) { ptr[index] = value; } }, @@ -110,7 +122,8 @@ inline void bsp_array_awrite(bsp_array_t array_0, size_t index_0, using T = std::remove_pointer_t; using U = std::remove_pointer_t; - if constexpr (std::is_assignable_v) { + if constexpr (std::is_convertible_v && + !binsparse::__detail::mixed_c_complex_v) { ptr_0[index_0] = ptr_1[index_1]; } },