Skip to content

Commit caef319

Browse files
committed
Fix compilation with Android NDK
It seems ADL lookup is broken with the STLPort library. Peter says: The compiler is gcc 4.4.3, but I don't know how many patches they have applied to it. I think gcc has had support for Koenig lookup a long time. I think the problem is the type of the vector iterator. For example, line 272 in search.cpp: if (bookMove && count(RootMoves.begin(), RootMoves.end(), bookMove)) gives the error: jni/stockfish/search.cpp:272: error: 'count' was not declared in this scope Here RootMoves is: std::vector<RootMove> RootMoves; If std::vector<T>::iterator is implemented as T*, then Koenig lookup would fail because RootMove* is not in namespace std. I compile with the stlport implementation of STL, which in its vector class has: typedef value_type* iterator; I'm not sure if this is allowed by the C++ standard. I did not find anything that says the iterator type must belong to namespace std. The consensus in this thread http://compgroups.net/comp.lang.c++.moderated/argument-dependent-lookup/433395 is that the stlport iterator type is allowed. Report and patch by Peter Osterlund. No functional change. Signed-off-by: Marco Costalba <mcostalba@gmail.com>
1 parent 2f47844 commit caef319

4 files changed

Lines changed: 8 additions & 2 deletions

File tree

src/endgame.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ namespace {
7272
string sides[] = { code.substr(code.find('K', 1)), // Weaker
7373
code.substr(0, code.find('K', 1)) }; // Stronger
7474

75-
transform(sides[c].begin(), sides[c].end(), sides[c].begin(), tolower);
75+
std::transform(sides[c].begin(), sides[c].end(), sides[c].begin(), tolower);
7676

7777
string fen = sides[0] + char('0' + int(8 - code.length()))
7878
+ sides[1] + "/8/8/8/8/8/8/8 w - - 0 10";

src/search.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ using std::endl;
5151
using Eval::evaluate;
5252
using namespace Search;
5353

54+
// For some reason argument-dependent lookup (ADL) doesn't work for Android's
55+
// STLPort, so explicitly qualify following functions.
56+
using std::count;
57+
using std::find;
58+
5459
namespace {
5560

5661
// Set to true to force running with one thread. Used for debugging

src/types.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
/// | only in 64-bit mode. For compiling requires hardware with
3636
/// | popcnt support.
3737

38+
#include <cctype>
3839
#include <climits>
3940
#include <cstdlib>
4041

src/ucioption.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ bool ci_less(char c1, char c2) { return tolower(c1) < tolower(c2); }
4545
}
4646

4747
bool CaseInsensitiveLess::operator() (const string& s1, const string& s2) const {
48-
return lexicographical_compare(s1.begin(), s1.end(), s2.begin(), s2.end(), ci_less);
48+
return std::lexicographical_compare(s1.begin(), s1.end(), s2.begin(), s2.end(), ci_less);
4949
}
5050

5151

0 commit comments

Comments
 (0)