std::string_view is more lightweight than std::string. Furthermore,
std::string_view variables can be declared constexpr.
closes https://github.com/official-stockfish/Stockfish/pull/4328
No functional change
#include <fstream>
#include <iomanip>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <sstream>
#if defined(__linux__) && !defined(__ANDROID__)
#include <stdlib.h>
#if defined(__linux__) && !defined(__ANDROID__)
#include <stdlib.h>
namespace {
/// Version number or dev.
namespace {
/// Version number or dev.
-const string version = "dev";
+constexpr string_view version = "dev";
/// Our fancy logging facility. The trick here is to replace cin.rdbuf() and
/// cout.rdbuf() with two Tie objects that tie cin and cout to a file stream. We
/// Our fancy logging facility. The trick here is to replace cin.rdbuf() and
/// cout.rdbuf() with two Tie objects that tie cin and cout to a file stream. We
stringstream ss;
ss << "Stockfish " << version << setfill('0');
stringstream ss;
ss << "Stockfish " << version << setfill('0');
+ if constexpr (version == "dev")
{
ss << "-";
#ifdef GIT_DATE
ss << GIT_DATE;
#else
{
ss << "-";
#ifdef GIT_DATE
ss << GIT_DATE;
#else
- const string months("Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec");
+ constexpr string_view months("Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec");
string month, day, year;
stringstream date(__DATE__); // From compiler, format is "Sep 21 2008"
string month, day, year;
stringstream date(__DATE__); // From compiler, format is "Sep 21 2008"
// Code for calculating NNUE evaluation function
// Code for calculating NNUE evaluation function
+#include <fstream>
+#include <iomanip>
#include <iostream>
#include <set>
#include <sstream>
#include <iostream>
#include <set>
#include <sstream>
-#include <iomanip>
-#include <fstream>
#include "../evaluate.h"
#include "../position.h"
#include "../evaluate.h"
#include "../position.h"
- static const std::string PieceToChar(" PNBRQK pnbrqk");
+ constexpr std::string_view PieceToChar(" PNBRQK pnbrqk");
// format_cp_compact() converts a Value into (centi)pawns and writes it in a buffer.
// format_cp_compact() converts a Value into (centi)pawns and writes it in a buffer.
#include <cstring> // For std::memset, std::memcmp
#include <iomanip>
#include <sstream>
#include <cstring> // For std::memset, std::memcmp
#include <iomanip>
#include <sstream>
#include "bitboard.h"
#include "misc.h"
#include "bitboard.h"
#include "misc.h"
-const string PieceToChar(" PNBRQK pnbrqk");
+constexpr std::string_view PieceToChar(" PNBRQK pnbrqk");
constexpr Piece Pieces[] = { W_PAWN, W_KNIGHT, W_BISHOP, W_ROOK, W_QUEEN, W_KING,
B_PAWN, B_KNIGHT, B_BISHOP, B_ROOK, B_QUEEN, B_KING };
constexpr Piece Pieces[] = { W_PAWN, W_KNIGHT, W_BISHOP, W_ROOK, W_QUEEN, W_KING,
B_PAWN, B_KNIGHT, B_BISHOP, B_ROOK, B_QUEEN, B_KING };
#include <fstream>
#include <iostream>
#include <list>
#include <fstream>
#include <iostream>
#include <list>
#include "../bitboard.h"
#include "../movegen.h"
#include "../bitboard.h"
#include "../movegen.h"
inline WDLScore operator-(WDLScore d) { return WDLScore(-int(d)); }
inline Square operator^(Square s, int i) { return Square(int(s) ^ i); }
inline WDLScore operator-(WDLScore d) { return WDLScore(-int(d)); }
inline Square operator^(Square s, int i) { return Square(int(s) ^ i); }
-const std::string PieceToChar = " PNBRQK pnbrqk";
+constexpr std::string_view PieceToChar = " PNBRQK pnbrqk";
int MapPawns[SQUARE_NB];
int MapB1H1H7[SQUARE_NB];
int MapPawns[SQUARE_NB];
int MapB1H1H7[SQUARE_NB];