Skip to content

Commit 2ca2c3f

Browse files
committed
Fun with lambdas
Use lambda functions instead of has_positive_value() and toggle_case() No functional change.
1 parent f54c44e commit 2ca2c3f

3 files changed

Lines changed: 4 additions & 11 deletions

File tree

src/movepick.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,6 @@ namespace {
4949
}
5050
}
5151

52-
// Unary predicate used by std::partition to split positive values from remaining
53-
// ones so as to sort the two sets separately, with the second sort delayed.
54-
inline bool has_positive_value(const ExtMove& move) { return move.value > VALUE_ZERO; }
55-
5652
// Picks the best move in the range (begin, end) and moves it to the front.
5753
// It's faster than sorting all the moves in advance when there are few
5854
// moves e.g. possible captures.
@@ -247,7 +243,7 @@ void MovePicker::generate_next_stage() {
247243
case QUIETS_1_S1:
248244
endQuiets = end = generate<QUIETS>(pos, moves);
249245
score<QUIETS>();
250-
end = std::partition(cur, end, has_positive_value);
246+
end = std::partition(cur, end, [](const ExtMove& m) { return m.value > VALUE_ZERO; });
251247
insertion_sort(cur, end);
252248
return;
253249

src/position.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,10 +1147,6 @@ bool Position::is_draw() const {
11471147
/// Position::flip() flips position with the white and black sides reversed. This
11481148
/// is only useful for debugging e.g. for finding evaluation symmetry bugs.
11491149

1150-
static char toggle_case(char c) {
1151-
return char(islower(c) ? toupper(c) : tolower(c));
1152-
}
1153-
11541150
void Position::flip() {
11551151

11561152
string f, token;
@@ -1168,7 +1164,8 @@ void Position::flip() {
11681164
ss >> token; // Castling availability
11691165
f += token + " ";
11701166

1171-
std::transform(f.begin(), f.end(), f.begin(), toggle_case);
1167+
std::transform(f.begin(), f.end(), f.begin(),
1168+
[](char c) { return char(islower(c) ? toupper(c) : tolower(c)); });
11721169

11731170
ss >> token; // En passant square
11741171
f += (token == "-" ? token : token.replace(1, 1, token[1] == '3' ? "6" : "3"));

src/ucioption.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ void init(OptionsMap& o) {
8181
std::ostream& operator<<(std::ostream& os, const OptionsMap& om) {
8282

8383
for (size_t idx = 0; idx < om.size(); ++idx)
84-
for (auto it : om)
84+
for (auto& it : om)
8585
if (it.second.idx == idx)
8686
{
8787
const Option& o = it.second;

0 commit comments

Comments
 (0)