Skip to content

Commit

Permalink
use reinterpret
Browse files Browse the repository at this point in the history
  • Loading branch information
alfC committed Jul 14, 2024
1 parent 0853cf3 commit a019951
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions include/boost/multi/array_ref.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2009,10 +2009,17 @@ class subarray : public const_subarray<T, D, ElementPtr, Layout> {
"error: reinterpret_array_cast is limited to integral stride values");

assert( sizeof(T) == sizeof(T2)*static_cast<std::size_t>(count) ); // NOLINT(cppcoreguidelines-pro-bounds-array-to-pointer-decay,hicpp-no-array-decay) : checck implicit size compatibility
return subarray<T2, D + 1, P2>(
layout_t<D+1>(this->layout().scale(sizeof(T), sizeof(T2)), 1, 0, count).rotate(),
static_cast<P2>(static_cast<void*>(this->base_)) // NOLINT(bugprone-casting-through-void) direct reinterepret_cast doesn't work here
);
if constexpr(std::is_pointer_v<ElementPtr>) {
return subarray<T2, D + 1, P2>(
layout_t<D+1>(this->layout().scale(sizeof(T), sizeof(T2)), 1, 0, count).rotate(),
static_cast<P2>(static_cast<void*>(this->base_)) // NOLINT(bugprone-casting-through-void) direct reinterepret_cast doesn't work here
);
} else {
return subarray<T2, D + 1, P2>(
layout_t<D+1>(this->layout().scale(sizeof(T), sizeof(T2)), 1, 0, count).rotate(),
reinterpret_cast<P2 const&>(this->base_) // NOLINT(bugprone-casting-through-void) direct reinterepret_cast doesn't work here
);
}
}

template<class T2, class P2 = typename std::pointer_traits<ElementPtr>::template rebind<T2> >
Expand All @@ -2021,10 +2028,17 @@ class subarray : public const_subarray<T, D, ElementPtr, Layout> {
"error: reinterpret_array_cast is limited to integral stride values");

assert( sizeof(T) == sizeof(T2)*static_cast<std::size_t>(count) ); // NOLINT(cppcoreguidelines-pro-bounds-array-to-pointer-decay,hicpp-no-array-decay) : checck implicit size compatibility
return subarray<T2, D + 1, P2>(
layout_t<D+1>(this->layout().scale(sizeof(T), sizeof(T2)), 1, 0, count).rotate(),
static_cast<P2>(static_cast<void*>(this->base_)) // NOLINT(bugprone-casting-through-void) direct reinterepret_cast doesn't work here
);
if constexpr(std::is_pointer_v<ElementPtr>) {
return subarray<T2, D + 1, P2>(
layout_t<D+1>(this->layout().scale(sizeof(T), sizeof(T2)), 1, 0, count).rotate(),
static_cast<P2>(static_cast<void*>(this->base_)) // NOLINT(bugprone-casting-through-void) direct reinterepret_cast doesn't work here
);
} else {
return subarray<T2, D + 1, P2>(
layout_t<D+1>(this->layout().scale(sizeof(T), sizeof(T2)), 1, 0, count).rotate(),
reinterpret_cast<P2 const&>(this->base_) // NOLINT(bugprone-casting-through-void) direct reinterepret_cast doesn't work here
);
}
}

using element_move_ptr = multi::move_ptr<typename subarray::element, typename subarray::element_ptr>;
Expand Down

0 comments on commit a019951

Please sign in to comment.