From: Marco Costalba Date: Wed, 21 Jan 2015 10:33:53 +0000 (+0100) Subject: Fun with lambdas X-Git-Url: https://git.sesse.net/?p=stockfish;a=commitdiff_plain;h=2ca2c3f35b2e408fd97bdf7092f41e1e508eb7af;ds=sidebyside Fun with lambdas Use lambda functions instead of has_positive_value() and toggle_case() No functional change. --- diff --git a/src/movepick.cpp b/src/movepick.cpp index edee8179..b1fa91d0 100644 --- a/src/movepick.cpp +++ b/src/movepick.cpp @@ -49,10 +49,6 @@ namespace { } } - // Unary predicate used by std::partition to split positive values from remaining - // ones so as to sort the two sets separately, with the second sort delayed. - inline bool has_positive_value(const ExtMove& move) { return move.value > VALUE_ZERO; } - // Picks the best move in the range (begin, end) and moves it to the front. // It's faster than sorting all the moves in advance when there are few // moves e.g. possible captures. @@ -247,7 +243,7 @@ void MovePicker::generate_next_stage() { case QUIETS_1_S1: endQuiets = end = generate(pos, moves); score(); - end = std::partition(cur, end, has_positive_value); + end = std::partition(cur, end, [](const ExtMove& m) { return m.value > VALUE_ZERO; }); insertion_sort(cur, end); return; diff --git a/src/position.cpp b/src/position.cpp index 994e1c76..c0c26f03 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -1147,10 +1147,6 @@ bool Position::is_draw() const { /// Position::flip() flips position with the white and black sides reversed. This /// is only useful for debugging e.g. for finding evaluation symmetry bugs. -static char toggle_case(char c) { - return char(islower(c) ? toupper(c) : tolower(c)); -} - void Position::flip() { string f, token; @@ -1168,7 +1164,8 @@ void Position::flip() { ss >> token; // Castling availability f += token + " "; - std::transform(f.begin(), f.end(), f.begin(), toggle_case); + std::transform(f.begin(), f.end(), f.begin(), + [](char c) { return char(islower(c) ? toupper(c) : tolower(c)); }); ss >> token; // En passant square f += (token == "-" ? token : token.replace(1, 1, token[1] == '3' ? "6" : "3")); diff --git a/src/ucioption.cpp b/src/ucioption.cpp index 28a0ad52..c7823764 100644 --- a/src/ucioption.cpp +++ b/src/ucioption.cpp @@ -81,7 +81,7 @@ void init(OptionsMap& o) { std::ostream& operator<<(std::ostream& os, const OptionsMap& om) { for (size_t idx = 0; idx < om.size(); ++idx) - for (auto it : om) + for (auto& it : om) if (it.second.idx == idx) { const Option& o = it.second;