]> git.sesse.net Git - stockfish/blobdiff - src/types.h
Rename and de-templetize sort()
[stockfish] / src / types.h
index d4ebec9f06fe977fa0d5df482fecab850af063f3..aa1f34fc112eaadf00663778a94a5e3ba11f2440 100644 (file)
@@ -35,6 +35,7 @@
 ///               | only in 64-bit mode. For compiling requires hardware with
 ///               | popcnt support.
 
+#include <cassert>
 #include <cctype>
 #include <climits>
 #include <cstdlib>
@@ -391,7 +392,8 @@ inline PieceType type_of(Piece p)  {
 }
 
 inline Color color_of(Piece p) {
-  return p == NO_PIECE ? NO_COLOR : Color(p >> 3);
+  assert(p != NO_PIECE);
+  return Color(p >> 3);
 }
 
 inline bool is_ok(Square s) {
@@ -439,12 +441,12 @@ inline int square_distance(Square s1, Square s2) {
   return SquareDistance[s1][s2];
 }
 
-inline char file_to_char(File f) {
-  return char(f - FILE_A + int('a'));
+inline char file_to_char(File f, bool tolower = true) {
+  return char(f - FILE_A + (tolower ? 'a' : 'A'));
 }
 
 inline char rank_to_char(Rank r) {
-  return char(r - RANK_1 + int('1'));
+  return char(r - RANK_1 + '1');
 }
 
 inline Square pawn_push(Color c) {
@@ -473,7 +475,7 @@ inline Move make_move(Square from, Square to) {
 
 template<MoveType T>
 inline Move make(Square from, Square to, PieceType pt = KNIGHT) {
-  return Move(to | (from << 6) | T | ((pt - KNIGHT) << 12)) ;
+  return Move(to | (from << 6) | T | ((pt - KNIGHT) << 12));
 }
 
 inline bool is_ok(Move m) {
@@ -487,21 +489,4 @@ inline const std::string square_to_string(Square s) {
   return ch;
 }
 
-/// Our insertion sort implementation, works with pointers and iterators and is
-/// guaranteed to be stable, as is needed.
-template<typename T, typename K>
-void sort(K first, K last)
-{
-  T tmp;
-  K p, q;
-
-  for (p = first + 1; p < last; p++)
-  {
-      tmp = *p;
-      for (q = p; q != first && *(q-1) < tmp; --q)
-          *q = *(q-1);
-      *q = tmp;
-  }
-}
-
 #endif // !defined(TYPES_H_INCLUDED)