]> git.sesse.net Git - stockfish/commitdiff
Fix compilation with Android NDK
authorMarco Costalba <mcostalba@gmail.com>
Wed, 9 May 2012 07:33:25 +0000 (09:33 +0200)
committerMarco Costalba <mcostalba@gmail.com>
Fri, 11 May 2012 16:16:51 +0000 (17:16 +0100)
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>
src/endgame.cpp
src/search.cpp
src/types.h
src/ucioption.cpp

index a3961840bc29d320bd56adb7d37349f613b76613..feaf59aafc20c04d2babdaae0e0e0a32e3e2664b 100644 (file)
@@ -72,7 +72,7 @@ namespace {
     string sides[] = { code.substr(code.find('K', 1)),      // Weaker
                        code.substr(0, code.find('K', 1)) }; // Stronger
 
-    transform(sides[c].begin(), sides[c].end(), sides[c].begin(), tolower);
+    std::transform(sides[c].begin(), sides[c].end(), sides[c].begin(), tolower);
 
     string fen =  sides[0] + char('0' + int(8 - code.length()))
                 + sides[1] + "/8/8/8/8/8/8/8 w - - 0 10";
index d711d743a7a455a5db265715c62facc1f301ddeb..27365069420871c0dcddd0ba8308dcf63d7e4947 100644 (file)
@@ -51,6 +51,11 @@ using std::endl;
 using Eval::evaluate;
 using namespace Search;
 
+// For some reason argument-dependent lookup (ADL) doesn't work for Android's
+// STLPort, so explicitly qualify following functions.
+using std::count;
+using std::find;
+
 namespace {
 
   // Set to true to force running with one thread. Used for debugging
index cf0b3f953dedcad5826f47c21a2deb2fd6000699..02e2d45515a1588b8bfbd7792f7fbc4381750371 100644 (file)
@@ -35,6 +35,7 @@
 ///               | only in 64-bit mode. For compiling requires hardware with
 ///               | popcnt support.
 
+#include <cctype>
 #include <climits>
 #include <cstdlib>
 
index 4be580fcbfaf0760974300e02871580549577686..4761004d735555696f5c22d1b60ff55e190a5fff 100644 (file)
@@ -45,7 +45,7 @@ bool ci_less(char c1, char c2) { return tolower(c1) < tolower(c2); }
 }
 
 bool CaseInsensitiveLess::operator() (const string& s1, const string& s2) const {
-  return lexicographical_compare(s1.begin(), s1.end(), s2.begin(), s2.end(), ci_less);
+  return std::lexicographical_compare(s1.begin(), s1.end(), s2.begin(), s2.end(), ci_less);
 }