Skip to content

Commit

Permalink
Cleanup: remove using namespace std; (#3016)
Browse files Browse the repository at this point in the history
* remove using namespace std from headers

* more std::

* more std::

* more std:: on windows stuff

* remove uses of using namespace std::chrono

* do not use C++17 features

* Add Davis suggestion

* revert some more stuff

* revert removing include

* more std::chrono stuff
  • Loading branch information
arrufat authored Sep 23, 2024
1 parent fafdac3 commit fe6e052
Show file tree
Hide file tree
Showing 50 changed files with 230 additions and 317 deletions.
1 change: 0 additions & 1 deletion dlib/any/any_function_abstract.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ namespace dlib
#include <iostream>
#include <string>
#include "dlib/any.h"
using namespace std;
void print_message(string str) { cout << str << endl; }
int main()
Expand Down
2 changes: 0 additions & 2 deletions dlib/cmd_line_parser/cmd_line_parser_kernel_1.h
Original file line number Diff line number Diff line change
Expand Up @@ -414,8 +414,6 @@ namespace dlib
const charT** argv
)
{
using namespace std;

// make sure there aren't any arguments hanging around from the last time
// parse was called
this->argv.clear();
Expand Down
1 change: 0 additions & 1 deletion dlib/config_reader/config_reader_thread_safe_1.h
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,6 @@ namespace dlib
fill_block_table (
)
{
using namespace std;
// first empty out the block table
block_table.reset();
while (block_table.move_next())
Expand Down
15 changes: 6 additions & 9 deletions dlib/cpp_pretty_printer/cpp_pretty_printer_kernel_1.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,6 @@ namespace dlib
const std::string& title
) const
{
using namespace std;

if (!out)
throw std::ios::failure("error occurred in cpp_pretty_printer_kernel_1::print");

Expand Down Expand Up @@ -172,7 +170,7 @@ namespace dlib

int type;
stack scopes; // a stack to hold old scopes
string token, temp;
std::string token, temp;
t.get_token(type,token);
while (type != tok::END_OF_FILE)
{
Expand All @@ -188,7 +186,7 @@ namespace dlib
if (type == tok::WHITE_SPACE)
{
t.get_token(type,temp);
if (temp.find_first_of("\n\r") != string::npos)
if (temp.find_first_of("\n\r") != std::string::npos)
recently_seen_preprocessor = false;
}
if (t.peek_type() != tok::IDENTIFIER &&
Expand Down Expand Up @@ -322,7 +320,7 @@ namespace dlib
)
{
temp = token;
istringstream sin(token);
std::istringstream sin(token);
sin >> temp;
sin >> temp;
sin.get();
Expand Down Expand Up @@ -351,7 +349,7 @@ namespace dlib
case tok::WHITE_SPACE: // -----------------------------------------
{
out << token;
if (token.find_first_of("\n\r") != string::npos)
if (token.find_first_of("\n\r") != std::string::npos)
recently_seen_preprocessor = false;
}
break;
Expand Down Expand Up @@ -497,10 +495,9 @@ namespace dlib
const std::string& title
) const
{
using namespace std;
ostringstream sout;
std::ostringstream sout;
print(in,sout,title);
istringstream sin(sout.str());
std::istringstream sin(sout.str());
number(sin,out);
}

Expand Down
13 changes: 5 additions & 8 deletions dlib/cpp_pretty_printer/cpp_pretty_printer_kernel_2.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,6 @@ namespace dlib
const std::string& title
) const
{
using namespace std;

if (!out)
throw std::ios::failure("error occurred in cpp_pretty_printer_kernel_2::print");

Expand Down Expand Up @@ -177,7 +175,7 @@ namespace dlib

int type;
stack scopes; // a stack to hold old scopes
string token, temp;
std::string token, temp;
t.get_token(type,token);
while (type != tok::END_OF_FILE)
{
Expand All @@ -193,7 +191,7 @@ namespace dlib
if (type == tok::WHITE_SPACE)
{
t.get_token(type,temp);
if (temp.find_first_of("\n\r") != string::npos)
if (temp.find_first_of("\n\r") != std::string::npos)
recently_seen_preprocessor = false;
}
if (t.peek_token() != ";" && t.peek_type() != tok::IDENTIFIER &&
Expand Down Expand Up @@ -306,7 +304,7 @@ namespace dlib
case tok::WHITE_SPACE: // -----------------------------------------
{
out << token;
if (token.find_first_of("\n\r") != string::npos)
if (token.find_first_of("\n\r") != std::string::npos)
recently_seen_preprocessor = false;
}
break;
Expand Down Expand Up @@ -434,10 +432,9 @@ namespace dlib
const std::string& title
) const
{
using namespace std;
ostringstream sout;
std::ostringstream sout;
print(in,sout,title);
istringstream sin(sout.str());
std::istringstream sin(sout.str());
number(sin,out);
}

Expand Down
10 changes: 4 additions & 6 deletions dlib/cpp_tokenizer/cpp_tokenizer_kernel_1.h
Original file line number Diff line number Diff line change
Expand Up @@ -380,8 +380,6 @@ namespace dlib
std::string& token
)
{
using namespace std;

if (!have_peeked)
{

Expand Down Expand Up @@ -501,7 +499,7 @@ namespace dlib

case '"':
{
string temp;
std::string temp;
tokenizer.get_token(type,token);
while (type != tok::END_OF_FILE)
{
Expand All @@ -528,7 +526,7 @@ namespace dlib

case '\'':
{
string temp;
std::string temp;
tokenizer.get_token(type,token);
if (type == tok::CHAR && token[0] == '\\')
{
Expand Down Expand Up @@ -557,7 +555,7 @@ namespace dlib
tokenizer.get_token(type,token);
// this is the start of a line comment
token = "//";
string temp;
std::string temp;
tokenizer.get_token(type,temp);
while (type != tok::END_OF_FILE)
{
Expand All @@ -582,7 +580,7 @@ namespace dlib
tokenizer.get_token(type,token);
// this is the start of a block comment
token = "/*";
string temp;
std::string temp;
tokenizer.get_token(type,temp);
while (type != tok::END_OF_FILE)
{
Expand Down
27 changes: 12 additions & 15 deletions dlib/data_io/libsvm_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ namespace dlib
std::vector<label_type, alloc2>& labels
)
{
using namespace std;
typedef typename sample_type::value_type pair_type;
typedef typename basic_type<typename pair_type::first_type>::type key_type;
typedef typename pair_type::second_type value_type;
Expand All @@ -41,13 +40,13 @@ namespace dlib
samples.clear();
labels.clear();

ifstream fin(file_name.c_str());
std::ifstream fin(file_name.c_str());

if (!fin)
throw sample_data_io_error("Unable to open file " + file_name);

string line;
istringstream sin;
std::string line;
std::istringstream sin;
key_type key;
value_type value;
label_type label;
Expand All @@ -56,12 +55,12 @@ namespace dlib
while (fin.peek() != EOF)
{
++line_num;
getline(fin, line);
std::getline(fin, line);

string::size_type pos = line.find_first_not_of(" \t\r\n");
std::string::size_type pos = line.find_first_not_of(" \t\r\n");

// ignore empty lines or comment lines
if (pos == string::npos || line[pos] == '#')
if (pos == std::string::npos || line[pos] == '#')
continue;

sin.clear();
Expand All @@ -74,12 +73,12 @@ namespace dlib
throw sample_data_io_error("On line: " + cast_to_string(line_num) + ", error while reading file " + file_name );

// eat whitespace
sin >> ws;
sin >> std::ws;

while (sin.peek() != EOF && sin.peek() != '#')
{

sin >> key >> ws;
sin >> key >> std::ws;

// ignore what should be a : character
if (sin.get() != ':')
Expand All @@ -89,10 +88,10 @@ namespace dlib

if (sin && value != 0)
{
sample.insert(sample.end(), make_pair(key, value));
sample.insert(sample.end(), std::make_pair(key, value));
}

sin >> ws;
sin >> std::ws;
}

samples.push_back(sample);
Expand Down Expand Up @@ -202,8 +201,7 @@ namespace dlib
);


using namespace std;
ofstream fout(file_name.c_str());
std::ofstream fout(file_name.c_str());
fout.precision(14);

if (!fout)
Expand Down Expand Up @@ -244,8 +242,7 @@ namespace dlib
<< "\n\t labels.size(): " << labels.size()
);

using namespace std;
ofstream fout(file_name.c_str());
std::ofstream fout(file_name.c_str());
fout.precision(14);

if (!fout)
Expand Down
8 changes: 3 additions & 5 deletions dlib/dir_nav/dir_nav_kernel_1.h
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,6 @@ namespace dlib
queue_of_files& files
)
{
using namespace std;
typedef directory::listing_error listing_error;
typedef file::private_constructor private_constructor;

Expand All @@ -402,7 +401,7 @@ namespace dlib
try
{
WIN32_FIND_DATAA data;
string path = state.full_name;
std::string path = state.full_name;
// ensure that the path ends with a separator
if (path[path.size()-1] != directory::get_separator())
path += directory::get_separator();
Expand Down Expand Up @@ -514,7 +513,6 @@ namespace dlib
queue_of_dirs& dirs
)
{
using namespace std;
typedef directory::listing_error listing_error;
typedef directory::private_constructor private_constructor;

Expand All @@ -526,7 +524,7 @@ namespace dlib
try
{
WIN32_FIND_DATAA data;
string path = state.full_name;
std::string path = state.full_name;
// ensure that the path ends with a separator
if (path[path.size()-1] != directory::get_separator())
path += directory::get_separator();
Expand All @@ -541,7 +539,7 @@ namespace dlib
bool no_more_files = false;
do
{
string tname(data.cFileName);
std::string tname(data.cFileName);
if ((data.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY) != 0 &&
tname != "." &&
tname != "..")
Expand Down
10 changes: 3 additions & 7 deletions dlib/dir_nav/dir_nav_kernel_2.h
Original file line number Diff line number Diff line change
Expand Up @@ -333,8 +333,6 @@ namespace dlib
queue_of_files& files
)
{
using namespace std;

files.clear();
if (state.full_name.size() == 0)
throw directory::listing_error("This directory object currently doesn't represent any directory.");
Expand All @@ -345,7 +343,7 @@ namespace dlib

try
{
string path = state.full_name;
std::string path = state.full_name;
// ensure that the path ends with a separator
if (path[path.size()-1] != directory::get_separator())
path += directory::get_separator();
Expand Down Expand Up @@ -490,8 +488,6 @@ namespace dlib
queue_of_dirs& dirs
)
{
using namespace std;

dirs.clear();
if (state.full_name.size() == 0)
throw directory::listing_error("This directory object currently doesn't represent any directory.");
Expand All @@ -502,7 +498,7 @@ namespace dlib

try
{
string path = state.full_name;
std::string path = state.full_name;
// ensure that the path ends with a separator
if (path[path.size()-1] != directory::get_separator())
path += directory::get_separator();
Expand Down Expand Up @@ -540,7 +536,7 @@ namespace dlib
continue;
}

string dtemp(data->d_name);
std::string dtemp(data->d_name);
if (S_ISDIR(buffer.st_mode) &&
dtemp != "." &&
dtemp != ".." )
Expand Down
Loading

0 comments on commit fe6e052

Please sign in to comment.