Avoid "using namespace std"

This is a cleanup PR that prepares the automatic checking of missing or
superfluous #include directives via the include-what-you-use (IWYU) tool
on the CI. Unfortunately, IWYU proposes additional includes for
"namespace std" although we don't need them.

To avoid the problem, the commit removes all "using namespace std"
statements from the code and directly uses the std:: prefix instead.
Alternatively, we could add specific usings (e.g. "using std::string")
foreach used type. Also, a mix of both approaches would be possible.
I decided for the prefix approach because most of the files were already
using the std:: prefixes despite the "using namespace std".

closes https://github.com/official-stockfish/Stockfish/pull/4772

No functional change
This commit is contained in:
Sebastian Buchwald
2023-09-04 22:01:20 +02:00
committed by Disservin
parent b25d68f6ee
commit a8b4fd1671
4 changed files with 80 additions and 88 deletions
+14 -16
View File
@@ -25,11 +25,9 @@
#include "position.h"
using namespace std;
namespace {
const vector<string> Defaults = {
const std::vector<std::string> Defaults = {
"setoption name UCI_Chess960 value false",
"rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1",
"r3k2r/p1ppqpb1/bn2pnp1/3PN3/1p2P3/2N2Q1p/PPPBBPPP/R3K2R w KQkq - 0 10",
@@ -109,17 +107,17 @@ namespace Stockfish {
/// bench 64 4 5000 current movetime : search current position with 4 threads for 5 sec
/// bench 16 1 5 blah perft : run a perft 5 on positions in file "blah"
vector<string> setup_bench(const Position& current, istream& is) {
std::vector<std::string> setup_bench(const Position& current, std::istream& is) {
vector<string> fens, list;
string go, token;
std::vector<std::string> fens, list;
std::string go, token;
// Assign default values to missing arguments
string ttSize = (is >> token) ? token : "16";
string threads = (is >> token) ? token : "1";
string limit = (is >> token) ? token : "13";
string fenFile = (is >> token) ? token : "default";
string limitType = (is >> token) ? token : "depth";
std::string ttSize = (is >> token) ? token : "16";
std::string threads = (is >> token) ? token : "1";
std::string limit = (is >> token) ? token : "13";
std::string fenFile = (is >> token) ? token : "default";
std::string limitType = (is >> token) ? token : "depth";
go = limitType == "eval" ? "eval" : "go " + limitType + " " + limit;
@@ -131,12 +129,12 @@ vector<string> setup_bench(const Position& current, istream& is) {
else
{
string fen;
ifstream file(fenFile);
std::string fen;
std::ifstream file(fenFile);
if (!file.is_open())
{
cerr << "Unable to open file " << fenFile << endl;
std::cerr << "Unable to open file " << fenFile << std::endl;
exit(EXIT_FAILURE);
}
@@ -151,8 +149,8 @@ vector<string> setup_bench(const Position& current, istream& is) {
list.emplace_back("setoption name Hash value " + ttSize);
list.emplace_back("ucinewgame");
for (const string& fen : fens)
if (fen.find("setoption") != string::npos)
for (const std::string& fen : fens)
if (fen.find("setoption") != std::string::npos)
list.emplace_back(fen);
else
{