Skip to content

Commit a2038c1

Browse files
Jonathanvondele
authored andcommitted
apply if constexpr to additional instances
as a form of documentation, and a hint to the compiler. closes #4345 No functional change
1 parent 734315f commit a2038c1

File tree

4 files changed

+15
-14
lines changed

4 files changed

+15
-14
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ Jerry Donald Watson (jerrydonaldwatson)
101101
jjoshua2
102102
Jonathan Calovski (Mysseno)
103103
Jonathan Buladas Dumale (SFisGOD)
104+
Jonathan McDermid (jonathanmcdermid)
104105
Joost VandeVondele (vondele)
105106
Jörg Oster (joergoster)
106107
Joseph Ellis (jhellis3)

src/evaluate.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -388,10 +388,10 @@ namespace {
388388
template<Tracing T> template<Color Us, PieceType Pt>
389389
Score Evaluation<T>::pieces() {
390390

391-
constexpr Color Them = ~Us;
392-
constexpr Direction Down = -pawn_push(Us);
393-
constexpr Bitboard OutpostRanks = (Us == WHITE ? Rank4BB | Rank5BB | Rank6BB
394-
: Rank5BB | Rank4BB | Rank3BB);
391+
constexpr Color Them = ~Us;
392+
[[maybe_unused]] constexpr Direction Down = -pawn_push(Us);
393+
[[maybe_unused]] constexpr Bitboard OutpostRanks = (Us == WHITE ? Rank4BB | Rank5BB | Rank6BB
394+
: Rank5BB | Rank4BB | Rank3BB);
395395
Bitboard b1 = pos.pieces(Us, Pt);
396396
Bitboard b, bb;
397397
Score score = SCORE_ZERO;
@@ -430,7 +430,7 @@ namespace {
430430
int mob = popcount(b & mobilityArea[Us]);
431431
mobility[Us] += MobilityBonus[Pt - 2][mob];
432432

433-
if (Pt == BISHOP || Pt == KNIGHT)
433+
if constexpr (Pt == BISHOP || Pt == KNIGHT)
434434
{
435435
// Bonus if the piece is on an outpost square or can reach one
436436
// Bonus for knights (UncontestedOutpost) if few relevant targets

src/movegen.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ namespace Stockfish {
2626
namespace {
2727

2828
template<GenType Type, Direction D>
29-
ExtMove* make_promotions(ExtMove* moveList, Square to) {
29+
ExtMove* make_promotions(ExtMove* moveList, [[maybe_unused]] Square to) {
3030

31-
if (Type == CAPTURES || Type == EVASIONS || Type == NON_EVASIONS)
31+
if constexpr (Type == CAPTURES || Type == EVASIONS || Type == NON_EVASIONS)
3232
*moveList++ = make<PROMOTION>(to - D, to, QUEEN);
3333

34-
if (Type == QUIETS || Type == EVASIONS || Type == NON_EVASIONS)
34+
if constexpr (Type == QUIETS || Type == EVASIONS || Type == NON_EVASIONS)
3535
{
3636
*moveList++ = make<PROMOTION>(to - D, to, ROOK);
3737
*moveList++ = make<PROMOTION>(to - D, to, BISHOP);
@@ -60,18 +60,18 @@ namespace {
6060
Bitboard pawnsNotOn7 = pos.pieces(Us, PAWN) & ~TRank7BB;
6161

6262
// Single and double pawn pushes, no promotions
63-
if (Type != CAPTURES)
63+
if constexpr (Type != CAPTURES)
6464
{
6565
Bitboard b1 = shift<Up>(pawnsNotOn7) & emptySquares;
6666
Bitboard b2 = shift<Up>(b1 & TRank3BB) & emptySquares;
6767

68-
if (Type == EVASIONS) // Consider only blocking squares
68+
if constexpr (Type == EVASIONS) // Consider only blocking squares
6969
{
7070
b1 &= target;
7171
b2 &= target;
7272
}
7373

74-
if (Type == QUIET_CHECKS)
74+
if constexpr (Type == QUIET_CHECKS)
7575
{
7676
// To make a quiet check, you either make a direct check by pushing a pawn
7777
// or push a blocker pawn that is not on the same file as the enemy king.
@@ -102,7 +102,7 @@ namespace {
102102
Bitboard b2 = shift<UpLeft >(pawnsOn7) & enemies;
103103
Bitboard b3 = shift<Up >(pawnsOn7) & emptySquares;
104104

105-
if (Type == EVASIONS)
105+
if constexpr (Type == EVASIONS)
106106
b3 &= target;
107107

108108
while (b1)
@@ -116,7 +116,7 @@ namespace {
116116
}
117117

118118
// Standard and en passant captures
119-
if (Type == CAPTURES || Type == EVASIONS || Type == NON_EVASIONS)
119+
if constexpr (Type == CAPTURES || Type == EVASIONS || Type == NON_EVASIONS)
120120
{
121121
Bitboard b1 = shift<UpRight>(pawnsNotOn7) & enemies;
122122
Bitboard b2 = shift<UpLeft >(pawnsNotOn7) & enemies;

src/movepick.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ Move MovePicker::select(Pred filter) {
158158

159159
while (cur < endMoves)
160160
{
161-
if (T == Best)
161+
if constexpr (T == Best)
162162
std::swap(*cur, *std::max_element(cur, endMoves));
163163

164164
if (*cur != ttMove && filter())

0 commit comments

Comments
 (0)