Skip to content
Merged
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
19 changes: 16 additions & 3 deletions include/binsparse/detail/cpp/array.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,16 @@ inline array_ptr_variant_t get_typed_ptr(bsp_array_t array) {
return {};
}

template <typename T>
constexpr static bool is_c_complex_v =
std::is_same_v<std::remove_cvref_t<T>, _Complex double> ||
std::is_same_v<std::remove_cvref_t<T>, _Complex float>;

template <typename T, typename U>
constexpr static bool mixed_c_complex_v =
(is_c_complex_v<T> && !is_c_complex_v<U>) ||
(!is_c_complex_v<T> && is_c_complex_v<U>);

} // namespace __detail

} // namespace binsparse
Expand All @@ -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<decltype(ptr)>;

if constexpr (std::is_assignable_v<T&, U>) {
if constexpr (std::is_convertible_v<U, T> &&
!binsparse::__detail::mixed_c_complex_v<T, U>) {
value = ptr[index];
}
},
Expand All @@ -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<decltype(ptr)>;

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

if constexpr (std::is_assignable_v<T&, U>) {
if constexpr (std::is_convertible_v<U, T> &&
!binsparse::__detail::mixed_c_complex_v<T, U>) {
ptr_0[index_0] = ptr_1[index_1];
}
},
Expand Down