Skip to content

Commit

Permalink
Added static_asserts for out of range tuple_element and get
Browse files Browse the repository at this point in the history
(to match checks in complex structured bindings)
  • Loading branch information
nliber committed May 30, 2024
1 parent d65b67b commit 2a7ca1a
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions core/src/Kokkos_Array.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -391,28 +391,33 @@ struct std::tuple_size<Kokkos::Array<T, N>>

template <std::size_t I, class T, std::size_t N>
struct std::tuple_element<I, Kokkos::Array<T, N>> {
static_assert(I < N);
using type = T;
};

namespace Kokkos {

template <std::size_t I, class T, std::size_t N>
KOKKOS_FUNCTION constexpr T& get(Array<T, N>& a) noexcept {
static_assert(I < N);
return a[I];
}

template <std::size_t I, class T, std::size_t N>
KOKKOS_FUNCTION constexpr T const& get(Array<T, N> const& a) noexcept {
static_assert(I < N);
return a[I];
}

template <std::size_t I, class T, std::size_t N>
KOKKOS_FUNCTION constexpr T&& get(Array<T, N>&& a) noexcept {
static_assert(I < N);
return std::move(a[I]);
}

template <std::size_t I, class T, std::size_t N>
KOKKOS_FUNCTION constexpr T const&& get(Array<T, N> const&& a) noexcept {
static_assert(I < N);
return std::move(a[I]);
}

Expand Down

0 comments on commit 2a7ca1a

Please sign in to comment.