Skip to content

Commit

Permalink
Clang-Tidy 17: modernize-type-traits (AMReX-Codes#3844)
Browse files Browse the repository at this point in the history
  • Loading branch information
WeiqunZhang authored Mar 25, 2024
1 parent 9e71c2c commit 9e8f8d6
Show file tree
Hide file tree
Showing 60 changed files with 644 additions and 644 deletions.
88 changes: 44 additions & 44 deletions Src/AmrCore/AMReX_FillPatchUtil_I.H
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ void FillPatchInterp (MultiFab& mf_fine_patch, int fcomp, MultiFab const& mf_crs
MFInterpolater* mapper, const Vector<BCRec>& bcs, int bcscomp);

template <typename MF, typename Interp>
std::enable_if_t<IsFabArray<MF>::value && !std::is_same<Interp,MFInterpolater>::value>
std::enable_if_t<IsFabArray<MF>::value && !std::is_same_v<Interp,MFInterpolater>>
FillPatchInterp (MF& mf_fine_patch, int fcomp, MF const& mf_crse_patch, int ccomp,
int ncomp, IntVect const& ng, const Geometry& cgeom, const Geometry& fgeom,
Box const& dest_domain, const IntVect& ratio,
Expand Down Expand Up @@ -240,7 +240,7 @@ FillPatchInterp (MF& mf_fine_patch, int fcomp, MF const& mf_crse_patch, int ccom
}

template <typename MF, typename iMF, typename Interp>
std::enable_if_t<IsFabArray<MF>::value && !std::is_same<Interp,MFInterpolater>::value>
std::enable_if_t<IsFabArray<MF>::value && !std::is_same_v<Interp,MFInterpolater>>
InterpFace (Interp *interp,
MF const& mf_crse_patch, int crse_comp,
MF& mf_refined_patch, int fine_comp,
Expand Down Expand Up @@ -298,9 +298,9 @@ namespace {
// ======== FArrayBox

template <typename MF,
typename std::enable_if<std::is_same<typename MF::FABType::value_type,
FArrayBox>::value,
int>::type = 0>
std::enable_if_t<std::is_same_v<typename MF::FABType::value_type,
FArrayBox>,
int> = 0>
MF make_mf_crse_patch (FabArrayBase::FPinfo const& fpc, int ncomp)
{
MF mf_crse_patch(fpc.ba_crse_patch, fpc.dm_patch, ncomp, 0, MFInfo(),
Expand All @@ -309,9 +309,9 @@ namespace {
}

template <typename MF,
typename std::enable_if<std::is_same<typename MF::FABType::value_type,
FArrayBox>::value,
int>::type = 0>
std::enable_if_t<std::is_same_v<typename MF::FABType::value_type,
FArrayBox>,
int> = 0>
MF make_mf_crse_patch (FabArrayBase::FPinfo const& fpc, int ncomp, IndexType idx_type)
{
MF mf_crse_patch(amrex::convert(fpc.ba_crse_patch, idx_type), fpc.dm_patch,
Expand All @@ -320,9 +320,9 @@ namespace {
}

template <typename MF,
typename std::enable_if<std::is_same<typename MF::FABType::value_type,
FArrayBox>::value,
int>::type = 0>
std::enable_if_t<std::is_same_v<typename MF::FABType::value_type,
FArrayBox>,
int> = 0>
MF make_mf_fine_patch (FabArrayBase::FPinfo const& fpc, int ncomp)
{
MF mf_fine_patch(fpc.ba_fine_patch, fpc.dm_patch, ncomp, 0, MFInfo(),
Expand All @@ -331,9 +331,9 @@ namespace {
}

template <typename MF,
typename std::enable_if<std::is_same<typename MF::FABType::value_type,
FArrayBox>::value,
int>::type = 0>
std::enable_if_t<std::is_same_v<typename MF::FABType::value_type,
FArrayBox>,
int> = 0>
MF make_mf_fine_patch (FabArrayBase::FPinfo const& fpc, int ncomp, IndexType idx_type)
{
MF mf_fine_patch(amrex::convert(fpc.ba_fine_patch, idx_type), fpc.dm_patch,
Expand All @@ -342,9 +342,9 @@ namespace {
}

template <typename MF,
typename std::enable_if<std::is_same<typename MF::FABType::value_type,
FArrayBox>::value,
int>::type = 0>
std::enable_if_t<std::is_same_v<typename MF::FABType::value_type,
FArrayBox>,
int> = 0>
MF make_mf_refined_patch (FabArrayBase::FPinfo const& fpc, int ncomp, IndexType idx_type, IntVect ratio)
{
MF mf_refined_patch(amrex::convert( amrex::refine( amrex::coarsen(fpc.ba_fine_patch, ratio), ratio), idx_type),
Expand All @@ -353,9 +353,9 @@ namespace {
}

template <typename MF,
typename std::enable_if<std::is_same<typename MF::FABType::value_type,
FArrayBox>::value,
int>::type = 0>
std::enable_if_t<std::is_same_v<typename MF::FABType::value_type,
FArrayBox>,
int> = 0>
MF make_mf_crse_mask (FabArrayBase::FPinfo const& fpc, int ncomp, IndexType idx_type, IntVect ratio)
{
MF mf_crse_mask(amrex::convert(amrex::coarsen(fpc.ba_fine_patch, ratio), idx_type),
Expand All @@ -364,9 +364,9 @@ namespace {
}

template <typename MF,
typename std::enable_if<std::is_same<typename MF::FABType::value_type,
FArrayBox>::value,
int>::type = 0>
std::enable_if_t<std::is_same_v<typename MF::FABType::value_type,
FArrayBox>,
int> = 0>
void mf_set_domain_bndry (MF &mf, Geometry const & geom)
{
mf.setDomainBndry(std::numeric_limits<Real>::quiet_NaN(), geom);
Expand All @@ -376,63 +376,63 @@ namespace {
// ======== Not FArrayBox

template <typename MF,
typename std::enable_if<!std::is_same<typename MF::FABType::value_type,
FArrayBox>::value,
int>::type = 0>
std::enable_if_t<!std::is_same_v<typename MF::FABType::value_type,
FArrayBox>,
int> = 0>
MF make_mf_crse_patch (FabArrayBase::FPinfo const& fpc, int ncomp)
{
return MF(fpc.ba_crse_patch, fpc.dm_patch, ncomp, 0);
}

template <typename MF,
typename std::enable_if<!std::is_same<typename MF::FABType::value_type,
FArrayBox>::value,
int>::type = 0>
std::enable_if_t<!std::is_same_v<typename MF::FABType::value_type,
FArrayBox>,
int> = 0>
MF make_mf_crse_patch (FabArrayBase::FPinfo const& fpc, int ncomp, IndexType idx_type)
{
return MF(amrex::convert(fpc.ba_crse_patch, idx_type), fpc.dm_patch, ncomp, 0);
}

template <typename MF,
typename std::enable_if<!std::is_same<typename MF::FABType::value_type,
FArrayBox>::value,
int>::type = 0>
std::enable_if_t<!std::is_same_v<typename MF::FABType::value_type,
FArrayBox>,
int> = 0>
MF make_mf_fine_patch (FabArrayBase::FPinfo const& fpc, int ncomp)
{
return MF(fpc.ba_fine_patch, fpc.dm_patch, ncomp, 0);
}

template <typename MF,
typename std::enable_if<!std::is_same<typename MF::FABType::value_type,
FArrayBox>::value,
int>::type = 0>
std::enable_if_t<!std::is_same_v<typename MF::FABType::value_type,
FArrayBox>,
int> = 0>
MF make_mf_fine_patch (FabArrayBase::FPinfo const& fpc, int ncomp, IndexType idx_type)
{
return MF(amrex::convert(fpc.ba_fine_patch, idx_type), fpc.dm_patch, ncomp, 0);
}

template <typename MF,
typename std::enable_if<!std::is_same<typename MF::FABType::value_type,
FArrayBox>::value,
int>::type = 0>
std::enable_if_t<!std::is_same_v<typename MF::FABType::value_type,
FArrayBox>,
int> = 0>
MF make_mf_refined_patch (FabArrayBase::FPinfo const& fpc, int ncomp, IndexType idx_type, IntVect ratio)
{
return MF(amrex::convert( amrex::refine( amrex::coarsen(fpc.ba_fine_patch, ratio), ratio), idx_type), fpc.dm_patch, ncomp, 0);
}

template <typename MF,
typename std::enable_if<!std::is_same<typename MF::FABType::value_type,
FArrayBox>::value,
int>::type = 0>
std::enable_if_t<!std::is_same_v<typename MF::FABType::value_type,
FArrayBox>,
int> = 0>
MF make_mf_crse_mask (FabArrayBase::FPinfo const& fpc, int ncomp, IndexType idx_type, IntVect ratio)
{
return MF(amrex::convert(amrex::coarsen(fpc.ba_fine_patch, ratio), idx_type), fpc.dm_patch, ncomp, 0);
}

template <typename MF,
typename std::enable_if<!std::is_same<typename MF::FABType::value_type,
FArrayBox>::value,
int>::type = 0>
std::enable_if_t<!std::is_same_v<typename MF::FABType::value_type,
FArrayBox>,
int> = 0>
void mf_set_domain_bndry (MF &/*mf*/, Geometry const & /*geom*/)
{
// nothing
Expand Down
56 changes: 28 additions & 28 deletions Src/Base/AMReX_Algorithm.H
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ namespace amrex
// Reference: https://en.cppreference.com/w/cpp/types/numeric_limits/epsilon
template <typename T>
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
typename std::enable_if<std::is_floating_point<T>::value,bool>::type
std::enable_if_t<std::is_floating_point_v<T>,bool>
almostEqual (T x, T y, int ulp = 2)
{
// the machine epsilon has to be scaled to the magnitude of the values used
Expand All @@ -100,7 +100,7 @@ namespace amrex
}

template <class T, class F,
typename std::enable_if<std::is_floating_point<T>::value,int>::type FOO = 0>
std::enable_if_t<std::is_floating_point_v<T>,int>FOO = 0>
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
T bisect (T lo, T hi, F f, T tol=1e-12, int max_iter=100)
{
Expand Down Expand Up @@ -141,7 +141,7 @@ namespace amrex
// It is assumed that the input data are sorted and T[lo] <= v < T[hi].
// Note that this is different from std::lower_bound.
template <typename T, typename I,
typename std::enable_if<std::is_integral<I>::value,int>::type = 0>
std::enable_if_t<std::is_integral_v<I>,int> = 0>
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
I bisect (T const* d, I lo, I hi, T const& v) {
while (lo <= hi) {
Expand Down Expand Up @@ -210,10 +210,10 @@ namespace amrex
}

template<typename ItType, typename ValType,
typename std::enable_if<
std::is_floating_point<typename std::iterator_traits<ItType>::value_type>::value &&
std::is_floating_point<ValType>::value,
int>::type = 0>
std::enable_if_t<
std::is_floating_point_v<typename std::iterator_traits<ItType>::value_type> &&
std::is_floating_point_v<ValType>,
int> = 0>
AMREX_GPU_HOST_DEVICE
void linspace (ItType first, const ItType& last, const ValType& start, const ValType& stop)
{
Expand All @@ -228,10 +228,10 @@ namespace amrex
}

template<typename ItType, typename ValType,
typename std::enable_if<
std::is_floating_point<typename std::iterator_traits<ItType>::value_type>::value &&
std::is_floating_point<ValType>::value,
int>::type = 0>
std::enable_if_t<
std::is_floating_point_v<typename std::iterator_traits<ItType>::value_type> &&
std::is_floating_point_v<ValType>,
int> = 0>
AMREX_GPU_HOST_DEVICE
void logspace (ItType first, const ItType& last,
const ValType& start, const ValType& stop, const ValType& base)
Expand All @@ -256,21 +256,21 @@ struct clz_tag : clzl_tag {};
// unsigned long, and unsigned long long inputs. Because the sizes of these data types
// vary on different platforms, we work with fixed-width integer types.
// these tags and overloads select the smallest version of __builtin_clz that will hold the input type
template <typename T, typename = typename std::enable_if<sizeof(T) <= sizeof(unsigned int)>::type>
template <typename T, typename = std::enable_if_t<sizeof(T) <= sizeof(unsigned int)>>
AMREX_FORCE_INLINE
int builtin_clz_wrapper (clz_tag, T x) noexcept
{
return static_cast<int>(__builtin_clz(x) - (sizeof(unsigned int) * CHAR_BIT - sizeof(T) * CHAR_BIT));
}

template <typename T, typename = typename std::enable_if<sizeof(T) <= sizeof(unsigned long)>::type>
template <typename T, typename = std::enable_if_t<sizeof(T) <= sizeof(unsigned long)>>
AMREX_FORCE_INLINE
int builtin_clz_wrapper (clzl_tag, T x) noexcept
{
return static_cast<int>(__builtin_clzl(x) - (sizeof(unsigned long) * CHAR_BIT - sizeof(T) * CHAR_BIT));
}

template <typename T, typename = typename std::enable_if<sizeof(T) <= sizeof(unsigned long long)>::type>
template <typename T, typename = std::enable_if_t<sizeof(T) <= sizeof(unsigned long long)>>
AMREX_FORCE_INLINE
int builtin_clz_wrapper (clzll_tag, T x) noexcept
{
Expand All @@ -279,10 +279,10 @@ int builtin_clz_wrapper (clzll_tag, T x) noexcept

}

template <class T, typename std::enable_if_t<std::is_same_v<std::decay_t<T>,std::uint8_t> ||
std::is_same_v<std::decay_t<T>,std::uint16_t> ||
std::is_same_v<std::decay_t<T>,std::uint32_t> ||
std::is_same_v<std::decay_t<T>,std::uint64_t>, int> = 0>
template <class T, std::enable_if_t<std::is_same_v<std::decay_t<T>,std::uint8_t> ||
std::is_same_v<std::decay_t<T>,std::uint16_t> ||
std::is_same_v<std::decay_t<T>,std::uint32_t> ||
std::is_same_v<std::decay_t<T>,std::uint64_t>, int> = 0>
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
int clz (T x) noexcept;

Expand Down Expand Up @@ -327,25 +327,25 @@ int clz_generic (std::uint64_t x) noexcept

namespace detail {
// likewise with CUDA, there are __clz functions that take (signed) int and long long int
template <typename T, typename = typename std::enable_if<sizeof(T) <= sizeof(int)>::type>
template <typename T, typename = std::enable_if_t<sizeof(T) <= sizeof(int)> >
AMREX_GPU_DEVICE AMREX_FORCE_INLINE
int clz_wrapper (clz_tag, T x) noexcept
{
return __clz((int) x) - (sizeof(int) * CHAR_BIT - sizeof(T) * CHAR_BIT);
}

template <typename T, typename = typename std::enable_if<sizeof(T) <= sizeof(long long int)>::type>
template <typename T, typename = std::enable_if_t<sizeof(T) <= sizeof(long long int)> >
AMREX_GPU_DEVICE AMREX_FORCE_INLINE
int clz_wrapper (clzll_tag, T x) noexcept
{
return __clzll((long long int) x) - (sizeof(long long int) * CHAR_BIT - sizeof(T) * CHAR_BIT);
}
}

template <class T, typename std::enable_if_t<std::is_same_v<std::decay_t<T>,std::uint8_t> ||
std::is_same_v<std::decay_t<T>,std::uint16_t> ||
std::is_same_v<std::decay_t<T>,std::uint32_t> ||
std::is_same_v<std::decay_t<T>,std::uint64_t>, int> >
template <class T, std::enable_if_t<std::is_same_v<std::decay_t<T>,std::uint8_t> ||
std::is_same_v<std::decay_t<T>,std::uint16_t> ||
std::is_same_v<std::decay_t<T>,std::uint32_t> ||
std::is_same_v<std::decay_t<T>,std::uint64_t>, int> >
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
int clz (T x) noexcept
{
Expand All @@ -359,10 +359,10 @@ int clz (T x) noexcept

#else // !defined AMREX_USE_CUDA

template <class T, typename std::enable_if_t<std::is_same_v<std::decay_t<T>,std::uint8_t> ||
std::is_same_v<std::decay_t<T>,std::uint16_t> ||
std::is_same_v<std::decay_t<T>,std::uint32_t> ||
std::is_same_v<std::decay_t<T>,std::uint64_t>, int> >
template <class T, std::enable_if_t<std::is_same_v<std::decay_t<T>,std::uint8_t> ||
std::is_same_v<std::decay_t<T>,std::uint16_t> ||
std::is_same_v<std::decay_t<T>,std::uint32_t> ||
std::is_same_v<std::decay_t<T>,std::uint64_t>, int> >
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
int clz (T x) noexcept
{
Expand Down
Loading

0 comments on commit 9e8f8d6

Please sign in to comment.