Skip to content

Commit fbf3902

Browse files
authored
Workaround for Clang, which has difficulty with mixed C complex numbers. (#17)
1 parent cb95ba4 commit fbf3902

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

include/binsparse/detail/cpp/array.hpp

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,16 @@ inline array_ptr_variant_t get_typed_ptr(bsp_array_t array) {
6363
return {};
6464
}
6565

66+
template <typename T>
67+
constexpr static bool is_c_complex_v =
68+
std::is_same_v<std::remove_cvref_t<T>, _Complex double> ||
69+
std::is_same_v<std::remove_cvref_t<T>, _Complex float>;
70+
71+
template <typename T, typename U>
72+
constexpr static bool mixed_c_complex_v =
73+
(is_c_complex_v<T> && !is_c_complex_v<U>) ||
74+
(!is_c_complex_v<T> && is_c_complex_v<U>);
75+
6676
} // namespace __detail
6777

6878
} // namespace binsparse
@@ -76,7 +86,8 @@ inline void bsp_array_read(bsp_array_t array, size_t index, T& value) {
7686
[&](auto* ptr) {
7787
using U = std::remove_pointer_t<decltype(ptr)>;
7888

79-
if constexpr (std::is_assignable_v<T&, U>) {
89+
if constexpr (std::is_convertible_v<U, T> &&
90+
!binsparse::__detail::mixed_c_complex_v<T, U>) {
8091
value = ptr[index];
8192
}
8293
},
@@ -92,7 +103,8 @@ inline void bsp_array_write(bsp_array_t array, size_t index, U value) {
92103
[&](auto* ptr) {
93104
using T = std::remove_pointer_t<decltype(ptr)>;
94105

95-
if constexpr (std::is_assignable_v<T&, U>) {
106+
if constexpr (std::is_convertible_v<U, T> &&
107+
!binsparse::__detail::mixed_c_complex_v<T, U>) {
96108
ptr[index] = value;
97109
}
98110
},
@@ -110,7 +122,8 @@ inline void bsp_array_awrite(bsp_array_t array_0, size_t index_0,
110122
using T = std::remove_pointer_t<decltype(ptr_0)>;
111123
using U = std::remove_pointer_t<decltype(ptr_1)>;
112124

113-
if constexpr (std::is_assignable_v<T&, U>) {
125+
if constexpr (std::is_convertible_v<U, T> &&
126+
!binsparse::__detail::mixed_c_complex_v<T, U>) {
114127
ptr_0[index_0] = ptr_1[index_1];
115128
}
116129
},

0 commit comments

Comments
 (0)