Skip to content

Commit 3a5fc3e

Browse files
Use compile-time if in survive()
1 parent 71683da commit 3a5fc3e

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

examples/Example19/electrons.cu

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ static __device__ __forceinline__ void TransportElectrons(Track *electrons, cons
5353
const int lvolID = volume->GetLogicalVolume()->id();
5454
const int theMCIndex = MCIndex[lvolID];
5555

56-
auto survive = [&](bool push = true) {
57-
if (push) activeQueue->push_back(globalSlot);
56+
auto survive = [&](auto push = std::true_type{}) {
57+
if constexpr (decltype(push)::value) activeQueue->push_back(slot);
5858
};
5959

6060
// Signal that this globalSlot doesn't undergo an interaction (yet)
@@ -287,7 +287,7 @@ static __device__ __forceinline__ void TransportElectrons(Track *electrons, cons
287287

288288
soaData.nextInteraction[i] = winnerProcessIndex;
289289

290-
survive(false);
290+
survive(std::false_type{});
291291
}
292292
}
293293

examples/Example19/gammas.cu

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ __global__ void TransportGammas(Track *gammas, const adept::MParray *active, Sec
3838
const int lvolID = volume->GetLogicalVolume()->id();
3939
const int theMCIndex = MCIndex[lvolID];
4040

41-
auto survive = [&](bool push = true) {
42-
if (push) activeQueue->push_back(slot);
41+
auto survive = [&](auto push = std::true_type{}) {
42+
if constexpr (decltype(push)::value) activeQueue->push_back(slot);
4343
};
4444

4545
// Signal that this slot doesn't undergo an interaction (yet)
@@ -117,8 +117,8 @@ __global__ void TransportGammas(Track *gammas, const adept::MParray *active, Sec
117117
currentTrack.numIALeft[winnerProcessIndex] = -1.0;
118118

119119
soaData.nextInteraction[i] = winnerProcessIndex;
120-
soaData.gamma_PEmxSec[i] = gammaTrack.GetPEmxSec();
121-
survive(false);
120+
soaData.gamma_PEmxSec[i] = gammaTrack.GetPEmxSec();
121+
survive(std::false_type{});
122122
}
123123
}
124124

0 commit comments

Comments
 (0)