Skip to content

Commit 910e5d1

Browse files
committed
had to write my own constexpr std::abs function only for msvc that does not support c++ 23 features...
1 parent 262ad36 commit 910e5d1

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

include/bitbishop/moves/pawn_move_gen.hpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,12 @@ constexpr bool is_promotion_rank(Square sq, Color c) { return c == Color::WHITE
102102
* @return true if the capture geometry is valid for en passant, false otherwise
103103
*/
104104
constexpr bool can_capture_en_passant(Square from, Square epsq, Color side) noexcept {
105-
int df = std::abs(int(from.file()) - int(epsq.file()));
105+
// MSVC have not yet made std::abs() constexpr for C++ 23, forcing us to define a generic constexpr one...
106+
// For this, lets apply the abs() function manually. This is sad, but you know, MSVC...
107+
// The code should not adapt to the compiler for the same language, the compiler should...
108+
int df = int(from.file()) - int(epsq.file());
109+
df = (df < 0) ? -df : df;
110+
106111
if (df != 1) return false;
107112
if (side == Color::WHITE && from.rank() == 4 && epsq.rank() == 5) return true;
108113
if (side == Color::BLACK && from.rank() == 3 && epsq.rank() == 2) return true;

0 commit comments

Comments
 (0)