Skip to content

Commit

Permalink
Alternate definition of Impl::is_nothrow_swappable_v for NVCC version…
Browse files Browse the repository at this point in the history
… less than 11.4
  • Loading branch information
dalg24 committed Apr 25, 2024
1 parent ebb1cb3 commit 031f6d9
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions core/src/Kokkos_Swap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,26 @@ kokkos_swap(T& a, T& b) noexcept(std::is_nothrow_move_constructible_v<T>&&

namespace Impl {

// Workaround for the definition of is_nothrow_swappable_v
#if defined(KOKKOS_COMPILER_NVCC) && (KOKKOS_COMPILER_NVCC < 1140)
template <class T>
struct is_swappable {
template <class U>
static decltype(kokkos_swap(std::declval<T&>(), std::declval<T&>()))
test_swap(int) noexcept(noexcept(kokkos_swap(std::declval<T&>(),
std::declval<T&>())));
struct Nope {}; // test_swap must return a complete type for the definition
// of nothrow below
template <class U>
static Nope test_swap(long);
static constexpr bool value =
!std::is_same_v<decltype(test_swap<T>(0)), Nope>;
static constexpr bool nothrow = noexcept(test_swap<T>(0));
};

template <class T>
inline constexpr bool is_nothrow_swappable_v = is_swappable<T>::nothrow;
#else
template <class T>
struct is_swappable {
template <class U>
Expand All @@ -52,6 +72,7 @@ struct is_swappable {
template <class T>
inline constexpr bool is_nothrow_swappable_v =
noexcept(kokkos_swap(std::declval<T&>(), std::declval<T&>()));
#endif

} // namespace Impl

Expand Down

0 comments on commit 031f6d9

Please sign in to comment.