Skip to content

Commit

Permalink
Clang-Tidy 17: cppcoreguidelines-missing-std-forward (AMReX-Codes#3818)
Browse files Browse the repository at this point in the history
  • Loading branch information
WeiqunZhang authored Mar 19, 2024
1 parent 6cdf256 commit 34a5327
Show file tree
Hide file tree
Showing 38 changed files with 195 additions and 192 deletions.
4 changes: 2 additions & 2 deletions Src/Base/AMReX_BaseFabUtility.H
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ template <typename STRUCT, typename F,
AMREX_IS_TRIVIALLY_COPYABLE(STRUCT) &&
std::is_trivially_destructible<STRUCT>::value,
int>::type FOO = 0>
void fill (BaseFab<STRUCT>& aos_fab, F && f)
void fill (BaseFab<STRUCT>& aos_fab, F const& f)
{
Box const& box = aos_fab.box();
auto const& aos = aos_fab.array();
Expand Down Expand Up @@ -88,7 +88,7 @@ void fill (BaseFab<STRUCT>& aos_fab, F && f)
} else
#endif
{
amrex::LoopOnCpu(box, [=] (int i, int j, int k) noexcept
amrex::LoopOnCpu(box, [&] (int i, int j, int k) noexcept
{
f(aos(i,j,k), i, j, k);
});
Expand Down
12 changes: 6 additions & 6 deletions Src/Base/AMReX_CTOParallelForImpl.H
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace detail
{
template <int MT, typename T, class F, typename... As>
std::enable_if_t<std::is_integral<T>::value || std::is_same<T,Box>::value, bool>
ParallelFor_helper2 (T const& N, F&& f, TypeList<As...>,
ParallelFor_helper2 (T const& N, F const& f, TypeList<As...>,
std::array<int,sizeof...(As)> const& runtime_options)
{
if (runtime_options == std::array<int,sizeof...(As)>{As::value...}) {
Expand All @@ -51,7 +51,7 @@ namespace detail

template <int MT, typename T, class F, typename... As>
std::enable_if_t<std::is_integral<T>::value, bool>
ParallelFor_helper2 (Box const& box, T ncomp, F&& f, TypeList<As...>,
ParallelFor_helper2 (Box const& box, T ncomp, F const& f, TypeList<As...>,
std::array<int,sizeof...(As)> const& runtime_options)
{
if (runtime_options == std::array<int,sizeof...(As)>{As::value...}) {
Expand All @@ -67,23 +67,23 @@ namespace detail

template <int MT, typename T, class F, typename... PPs, typename RO>
std::enable_if_t<std::is_integral<T>::value || std::is_same<T,Box>::value>
ParallelFor_helper1 (T const& N, F&& f, TypeList<PPs...>,
ParallelFor_helper1 (T const& N, F const& f, TypeList<PPs...>,
RO const& runtime_options)
{
bool found_option = (false || ... ||
ParallelFor_helper2<MT>(N, std::forward<F>(f),
ParallelFor_helper2<MT>(N, f,
PPs{}, runtime_options));
amrex::ignore_unused(found_option);
AMREX_ASSERT(found_option);
}

template <int MT, typename T, class F, typename... PPs, typename RO>
std::enable_if_t<std::is_integral<T>::value>
ParallelFor_helper1 (Box const& box, T ncomp, F&& f, TypeList<PPs...>,
ParallelFor_helper1 (Box const& box, T ncomp, F const& f, TypeList<PPs...>,
RO const& runtime_options)
{
bool found_option = (false || ... ||
ParallelFor_helper2<MT>(box, ncomp, std::forward<F>(f),
ParallelFor_helper2<MT>(box, ncomp, f,
PPs{}, runtime_options));
amrex::ignore_unused(found_option);
AMREX_ASSERT(found_option);
Expand Down
36 changes: 18 additions & 18 deletions Src/Base/AMReX_FabArrayUtility.H
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace fudetail {
template <class FAB, class F,
class bar = std::enable_if_t<IsBaseFab<FAB>::value> >
typename FAB::value_type
ReduceSum_host (FabArray<FAB> const& fa, IntVect const& nghost, F&& f)
ReduceSum_host (FabArray<FAB> const& fa, IntVect const& nghost, F const& f)
{
using value_type = typename FAB::value_type;
value_type sm = 0;
Expand All @@ -47,7 +47,7 @@ std::enable_if_t<IsBaseFab<FAB>::value,
std::conditional_t<std::is_same<OP,ReduceOpLogicalAnd>::value ||
std::is_same<OP,ReduceOpLogicalOr>::value,
int, typename FAB::value_type> >
ReduceMF (FabArray<FAB> const& fa, IntVect const& nghost, F&& f)
ReduceMF (FabArray<FAB> const& fa, IntVect const& nghost, F const& f)
{
using T = std::conditional_t<std::is_same<OP,ReduceOpLogicalAnd>::value ||
std::is_same<OP,ReduceOpLogicalOr>::value,
Expand All @@ -66,7 +66,7 @@ std::enable_if_t<IsBaseFab<FAB1>::value && IsBaseFab<FAB2>::value,
std::conditional_t<std::is_same<OP,ReduceOpLogicalAnd>::value ||
std::is_same<OP,ReduceOpLogicalOr>::value,
int, typename FAB1::value_type> >
ReduceMF (FabArray<FAB1> const& fa1, FabArray<FAB2> const& fa2, IntVect const& nghost, F&& f)
ReduceMF (FabArray<FAB1> const& fa1, FabArray<FAB2> const& fa2, IntVect const& nghost, F const& f)
{
using T = std::conditional_t<std::is_same<OP,ReduceOpLogicalAnd>::value ||
std::is_same<OP,ReduceOpLogicalOr>::value,
Expand All @@ -88,7 +88,7 @@ std::enable_if_t<IsBaseFab<FAB1>::value && IsBaseFab<FAB2>::value && IsBaseFab<F
std::is_same<OP,ReduceOpLogicalOr>::value,
int, typename FAB1::value_type> >
ReduceMF (FabArray<FAB1> const& fa1, FabArray<FAB2> const& fa2,
FabArray<FAB3> const& fa3, IntVect const& nghost, F&& f)
FabArray<FAB3> const& fa3, IntVect const& nghost, F const& f)
{
using T = std::conditional_t<std::is_same<OP,ReduceOpLogicalAnd>::value ||
std::is_same<OP,ReduceOpLogicalOr>::value,
Expand Down Expand Up @@ -156,7 +156,7 @@ template <class FAB1, class FAB2, class F,
class bar = std::enable_if_t<IsBaseFab<FAB1>::value> >
typename FAB1::value_type
ReduceSum_host (FabArray<FAB1> const& fa1, FabArray<FAB2> const& fa2,
IntVect const& nghost, F&& f)
IntVect const& nghost, F const& f)
{
using value_type = typename FAB1::value_type;
value_type sm = 0;
Expand Down Expand Up @@ -234,7 +234,7 @@ template <class FAB1, class FAB2, class FAB3, class F,
class bar = std::enable_if_t<IsBaseFab<FAB1>::value> >
typename FAB1::value_type
ReduceSum_host (FabArray<FAB1> const& fa1, FabArray<FAB2> const& fa2,
FabArray<FAB3> const& fa3, IntVect const& nghost, F&& f)
FabArray<FAB3> const& fa3, IntVect const& nghost, F const& f)
{
using value_type = typename FAB1::value_type;
value_type sm = 0;
Expand Down Expand Up @@ -311,7 +311,7 @@ namespace fudetail {
template <class FAB, class F,
class bar = std::enable_if_t<IsBaseFab<FAB>::value> >
typename FAB::value_type
ReduceMin_host (FabArray<FAB> const& fa, IntVect const& nghost, F&& f)
ReduceMin_host (FabArray<FAB> const& fa, IntVect const& nghost, F const& f)
{
using value_type = typename FAB::value_type;
value_type r = std::numeric_limits<value_type>::max();
Expand Down Expand Up @@ -382,7 +382,7 @@ template <class FAB1, class FAB2, class F,
class bar = std::enable_if_t<IsBaseFab<FAB1>::value> >
typename FAB1::value_type
ReduceMin_host (FabArray<FAB1> const& fa1, FabArray<FAB2> const& fa2,
IntVect const& nghost, F&& f)
IntVect const& nghost, F const& f)
{
using value_type = typename FAB1::value_type;
value_type r = std::numeric_limits<value_type>::max();
Expand Down Expand Up @@ -460,7 +460,7 @@ template <class FAB1, class FAB2, class FAB3, class F,
class bar = std::enable_if_t<IsBaseFab<FAB1>::value> >
typename FAB1::value_type
ReduceMin_host (FabArray<FAB1> const& fa1, FabArray<FAB2> const& fa2,
FabArray<FAB3> const& fa3, IntVect const& nghost, F&& f)
FabArray<FAB3> const& fa3, IntVect const& nghost, F const& f)
{
using value_type = typename FAB1::value_type;
value_type r = std::numeric_limits<value_type>::max();
Expand Down Expand Up @@ -537,7 +537,7 @@ namespace fudetail {
template <class FAB, class F,
class bar = std::enable_if_t<IsBaseFab<FAB>::value> >
typename FAB::value_type
ReduceMax_host (FabArray<FAB> const& fa, IntVect const& nghost, F&& f)
ReduceMax_host (FabArray<FAB> const& fa, IntVect const& nghost, F const& f)
{
using value_type = typename FAB::value_type;
value_type r = std::numeric_limits<value_type>::lowest();
Expand Down Expand Up @@ -609,7 +609,7 @@ template <class FAB1, class FAB2, class F,
class bar = std::enable_if_t<IsBaseFab<FAB1>::value> >
typename FAB1::value_type
ReduceMax_host (FabArray<FAB1> const& fa1, FabArray<FAB2> const& fa2,
IntVect const& nghost, F&& f)
IntVect const& nghost, F const& f)
{
using value_type = typename FAB1::value_type;
value_type r = std::numeric_limits<value_type>::lowest();
Expand Down Expand Up @@ -687,7 +687,7 @@ template <class FAB1, class FAB2, class FAB3, class F,
class bar = std::enable_if_t<IsBaseFab<FAB1>::value> >
typename FAB1::value_type
ReduceMax_host (FabArray<FAB1> const& fa1, FabArray<FAB2> const& fa2,
FabArray<FAB3> const& fa3, IntVect const& nghost, F&& f)
FabArray<FAB3> const& fa3, IntVect const& nghost, F const& f)
{
using value_type = typename FAB1::value_type;
value_type r = std::numeric_limits<value_type>::lowest();
Expand Down Expand Up @@ -764,7 +764,7 @@ namespace fudetail {
template <class FAB, class F,
class bar = std::enable_if_t<IsBaseFab<FAB>::value> >
bool
ReduceLogicalAnd_host (FabArray<FAB> const& fa, IntVect const& nghost, F&& f)
ReduceLogicalAnd_host (FabArray<FAB> const& fa, IntVect const& nghost, F const& f)
{
int r = true;

Expand Down Expand Up @@ -836,7 +836,7 @@ template <class FAB1, class FAB2, class F,
class bar = std::enable_if_t<IsBaseFab<FAB1>::value> >
bool
ReduceLogicalAnd_host (FabArray<FAB1> const& fa1, FabArray<FAB2> const& fa2,
IntVect const& nghost, F&& f)
IntVect const& nghost, F const& f)
{
int r = true;

Expand Down Expand Up @@ -911,7 +911,7 @@ namespace fudetail {
template <class FAB, class F,
class bar = std::enable_if_t<IsBaseFab<FAB>::value> >
bool
ReduceLogicalOr_host (FabArray<FAB> const& fa, IntVect const& nghost, F&& f)
ReduceLogicalOr_host (FabArray<FAB> const& fa, IntVect const& nghost, F const& f)
{
int r = false;

Expand Down Expand Up @@ -940,9 +940,9 @@ ReduceLogicalOr_host_wrapper (FabArray<FAB> const& fa, IntVect const& nghost, F&

template <class FAB, class F>
std::enable_if_t<amrex::DefinitelyNotHostRunnable<F>::value, bool>
ReduceLogicalOr_host (FabArray<FAB> const& fa, IntVect const& nghost, F&& f)
ReduceLogicalOr_host (FabArray<FAB> const& fa, IntVect const& nghost, F&& /*f*/)
{
amrex::ignore_unused(fa,nghost,f);
amrex::ignore_unused(fa,nghost);
amrex::Abort("ReduceLogicalOr: Launch Region is off. Device lambda cannot be called by host.");
return 0;
}
Expand Down Expand Up @@ -983,7 +983,7 @@ template <class FAB1, class FAB2, class F,
class bar = std::enable_if_t<IsBaseFab<FAB1>::value> >
bool
ReduceLogicalOr_host (FabArray<FAB1> const& fa1, FabArray<FAB2> const& fa2,
IntVect const& nghost, F&& f)
IntVect const& nghost, F const& f)
{
int r = false;

Expand Down
4 changes: 2 additions & 2 deletions Src/Base/AMReX_GpuAtomic.H
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,8 @@ namespace detail {
))
AMREX_IF_ON_HOST((
T old = *add;
T const tmp = op(old, value);
if (cond(tmp)) {
T const tmp = std::forward<Op>(op)(old, value);
if (std::forward<Cond>(cond)(tmp)) {
*add = tmp;
return true;
} else {
Expand Down
2 changes: 1 addition & 1 deletion Src/Base/AMReX_GpuContainers.H
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ namespace amrex::Gpu {
std::is_trivially_copyable_v<T> &&
amrex::IsCallable<F, T&, Long>::value,
int> FOO = 0>
void fillAsync (IT first, IT last, F&& f) noexcept
void fillAsync (IT first, IT last, F const& f) noexcept
{
auto N = static_cast<Long>(std::distance(first, last));
if (N <= 0) { return; }
Expand Down
4 changes: 2 additions & 2 deletions Src/Base/AMReX_GpuLaunch.H
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ namespace amrex {
// CPU variation

template<class L>
void launch_host (L&& f0) noexcept { f0(); }
void launch_host (L&& f0) noexcept { std::forward<L>(f0)(); }

template<class L, class... Lambdas>
void launch_host (L&& f0, Lambdas&&... fs) noexcept {
f0();
std::forward<L>(f0)();
launch_host(std::forward<Lambdas>(fs)...);
}

Expand Down
28 changes: 14 additions & 14 deletions Src/Base/AMReX_GpuLaunchFunctsC.H
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,18 @@ namespace detail {
template<typename T, typename L>
void launch (T const& n, L&& f) noexcept
{
f(n);
std::forward<L>(f)(n);
}

template<int MT, typename T, typename L>
void launch (T const& n, L&& f) noexcept
{
amrex::ignore_unused(MT);
f(n);
std::forward<L>(f)(n);
}

template <typename T, typename L, typename M=std::enable_if_t<std::is_integral<T>::value> >
void For (T n, L&& f) noexcept
void For (T n, L const& f) noexcept
{
for (T i = 0; i < n; ++i) {
detail::call_f(f,i);
Expand Down Expand Up @@ -96,7 +96,7 @@ void For (Gpu::KernelInfo const&, T n, L&& f) noexcept
}

template <typename T, typename L, typename M=std::enable_if_t<std::is_integral<T>::value> >
void ParallelFor (T n, L&& f) noexcept
void ParallelFor (T n, L const& f) noexcept
{
AMREX_PRAGMA_SIMD
for (T i = 0; i < n; ++i) {
Expand Down Expand Up @@ -125,7 +125,7 @@ void ParallelFor (Gpu::KernelInfo const&, T n, L&& f) noexcept
}

template <typename L>
void For (Box const& box, L&& f) noexcept
void For (Box const& box, L const& f) noexcept
{
const auto lo = amrex::lbound(box);
const auto hi = amrex::ubound(box);
Expand Down Expand Up @@ -157,7 +157,7 @@ void For (Gpu::KernelInfo const&, Box const& box, L&& f) noexcept
}

template <typename L>
void ParallelFor (Box const& box, L&& f) noexcept
void ParallelFor (Box const& box, L const& f) noexcept
{
const auto lo = amrex::lbound(box);
const auto hi = amrex::ubound(box);
Expand Down Expand Up @@ -190,7 +190,7 @@ void ParallelFor (Gpu::KernelInfo const&, Box const& box, L&& f) noexcept
}

template <typename T, typename L, typename M=std::enable_if_t<std::is_integral<T>::value> >
void For (Box const& box, T ncomp, L&& f) noexcept
void For (Box const& box, T ncomp, L const& f) noexcept
{
const auto lo = amrex::lbound(box);
const auto hi = amrex::ubound(box);
Expand Down Expand Up @@ -224,7 +224,7 @@ void For (Gpu::KernelInfo const&, Box const& box, T ncomp, L&& f) noexcept
}

template <typename T, typename L, typename M=std::enable_if_t<std::is_integral<T>::value> >
void ParallelFor (Box const& box, T ncomp, L&& f) noexcept
void ParallelFor (Box const& box, T ncomp, L const& f) noexcept
{
const auto lo = amrex::lbound(box);
const auto hi = amrex::ubound(box);
Expand Down Expand Up @@ -432,14 +432,14 @@ void ParallelFor (Box const& box1, Box const& box2, L1&& f1, L2&& f2) noexcept
template <typename L1, typename L2>
void ParallelFor (Gpu::KernelInfo const&, Box const& box1, Box const& box2, L1&& f1, L2&& f2) noexcept
{
ParallelFor(box1,box2,f1,f2);
ParallelFor(box1,box2,std::forward<L1>(f1),std::forward<L2>(f2));
}

template <int MT, typename L1, typename L2>
void ParallelFor (Gpu::KernelInfo const&, Box const& box1, Box const& box2, L1&& f1, L2&& f2) noexcept
{
amrex::ignore_unused(MT);
ParallelFor(box1,box2,f1,f2);
ParallelFor(box1,box2,std::forward<L1>(f1),std::forward<L2>(f2));
}

template <typename L1, typename L2, typename L3>
Expand Down Expand Up @@ -1037,15 +1037,15 @@ void HostDeviceFor (Gpu::KernelInfo const&,
}

template <typename T, typename L, typename M=std::enable_if_t<std::is_integral<T>::value> >
void ParallelForRNG (T n, L&& f) noexcept
void ParallelForRNG (T n, L const& f) noexcept
{
for (T i = 0; i < n; ++i) {
f(i,RandomEngine{});
}
}

template <typename L>
void ParallelForRNG (Box const& box, L&& f) noexcept
void ParallelForRNG (Box const& box, L const& f) noexcept
{
const auto lo = amrex::lbound(box);
const auto hi = amrex::ubound(box);
Expand All @@ -1057,7 +1057,7 @@ void ParallelForRNG (Box const& box, L&& f) noexcept
}

template <typename T, typename L, typename M=std::enable_if_t<std::is_integral<T>::value> >
void ParallelForRNG (Box const& box, T ncomp, L&& f) noexcept
void ParallelForRNG (Box const& box, T ncomp, L const& f) noexcept
{
const auto lo = amrex::lbound(box);
const auto hi = amrex::ubound(box);
Expand All @@ -1073,7 +1073,7 @@ void ParallelForRNG (Box const& box, T ncomp, L&& f) noexcept
template <typename L>
void single_task (L&& f) noexcept
{
f();
std::forward<L>(f)();
}

}
Expand Down
Loading

0 comments on commit 34a5327

Please sign in to comment.