Skip to content

Commit fe6e052

Browse files
authored
Cleanup: remove using namespace std; (davisking#3016)
* 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
1 parent fafdac3 commit fe6e052

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+230
-317
lines changed

dlib/any/any_function_abstract.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ namespace dlib
4646
#include <iostream>
4747
#include <string>
4848
#include "dlib/any.h"
49-
using namespace std;
5049
void print_message(string str) { cout << str << endl; }
5150
5251
int main()

dlib/cmd_line_parser/cmd_line_parser_kernel_1.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -414,8 +414,6 @@ namespace dlib
414414
const charT** argv
415415
)
416416
{
417-
using namespace std;
418-
419417
// make sure there aren't any arguments hanging around from the last time
420418
// parse was called
421419
this->argv.clear();

dlib/config_reader/config_reader_thread_safe_1.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,6 @@ namespace dlib
426426
fill_block_table (
427427
)
428428
{
429-
using namespace std;
430429
// first empty out the block table
431430
block_table.reset();
432431
while (block_table.move_next())

dlib/cpp_pretty_printer/cpp_pretty_printer_kernel_1.h

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,6 @@ namespace dlib
122122
const std::string& title
123123
) const
124124
{
125-
using namespace std;
126-
127125
if (!out)
128126
throw std::ios::failure("error occurred in cpp_pretty_printer_kernel_1::print");
129127

@@ -172,7 +170,7 @@ namespace dlib
172170

173171
int type;
174172
stack scopes; // a stack to hold old scopes
175-
string token, temp;
173+
std::string token, temp;
176174
t.get_token(type,token);
177175
while (type != tok::END_OF_FILE)
178176
{
@@ -188,7 +186,7 @@ namespace dlib
188186
if (type == tok::WHITE_SPACE)
189187
{
190188
t.get_token(type,temp);
191-
if (temp.find_first_of("\n\r") != string::npos)
189+
if (temp.find_first_of("\n\r") != std::string::npos)
192190
recently_seen_preprocessor = false;
193191
}
194192
if (t.peek_type() != tok::IDENTIFIER &&
@@ -322,7 +320,7 @@ namespace dlib
322320
)
323321
{
324322
temp = token;
325-
istringstream sin(token);
323+
std::istringstream sin(token);
326324
sin >> temp;
327325
sin >> temp;
328326
sin.get();
@@ -351,7 +349,7 @@ namespace dlib
351349
case tok::WHITE_SPACE: // -----------------------------------------
352350
{
353351
out << token;
354-
if (token.find_first_of("\n\r") != string::npos)
352+
if (token.find_first_of("\n\r") != std::string::npos)
355353
recently_seen_preprocessor = false;
356354
}
357355
break;
@@ -497,10 +495,9 @@ namespace dlib
497495
const std::string& title
498496
) const
499497
{
500-
using namespace std;
501-
ostringstream sout;
498+
std::ostringstream sout;
502499
print(in,sout,title);
503-
istringstream sin(sout.str());
500+
std::istringstream sin(sout.str());
504501
number(sin,out);
505502
}
506503

dlib/cpp_pretty_printer/cpp_pretty_printer_kernel_2.h

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,6 @@ namespace dlib
122122
const std::string& title
123123
) const
124124
{
125-
using namespace std;
126-
127125
if (!out)
128126
throw std::ios::failure("error occurred in cpp_pretty_printer_kernel_2::print");
129127

@@ -177,7 +175,7 @@ namespace dlib
177175

178176
int type;
179177
stack scopes; // a stack to hold old scopes
180-
string token, temp;
178+
std::string token, temp;
181179
t.get_token(type,token);
182180
while (type != tok::END_OF_FILE)
183181
{
@@ -193,7 +191,7 @@ namespace dlib
193191
if (type == tok::WHITE_SPACE)
194192
{
195193
t.get_token(type,temp);
196-
if (temp.find_first_of("\n\r") != string::npos)
194+
if (temp.find_first_of("\n\r") != std::string::npos)
197195
recently_seen_preprocessor = false;
198196
}
199197
if (t.peek_token() != ";" && t.peek_type() != tok::IDENTIFIER &&
@@ -306,7 +304,7 @@ namespace dlib
306304
case tok::WHITE_SPACE: // -----------------------------------------
307305
{
308306
out << token;
309-
if (token.find_first_of("\n\r") != string::npos)
307+
if (token.find_first_of("\n\r") != std::string::npos)
310308
recently_seen_preprocessor = false;
311309
}
312310
break;
@@ -434,10 +432,9 @@ namespace dlib
434432
const std::string& title
435433
) const
436434
{
437-
using namespace std;
438-
ostringstream sout;
435+
std::ostringstream sout;
439436
print(in,sout,title);
440-
istringstream sin(sout.str());
437+
std::istringstream sin(sout.str());
441438
number(sin,out);
442439
}
443440

dlib/cpp_tokenizer/cpp_tokenizer_kernel_1.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -380,8 +380,6 @@ namespace dlib
380380
std::string& token
381381
)
382382
{
383-
using namespace std;
384-
385383
if (!have_peeked)
386384
{
387385

@@ -501,7 +499,7 @@ namespace dlib
501499

502500
case '"':
503501
{
504-
string temp;
502+
std::string temp;
505503
tokenizer.get_token(type,token);
506504
while (type != tok::END_OF_FILE)
507505
{
@@ -528,7 +526,7 @@ namespace dlib
528526

529527
case '\'':
530528
{
531-
string temp;
529+
std::string temp;
532530
tokenizer.get_token(type,token);
533531
if (type == tok::CHAR && token[0] == '\\')
534532
{
@@ -557,7 +555,7 @@ namespace dlib
557555
tokenizer.get_token(type,token);
558556
// this is the start of a line comment
559557
token = "//";
560-
string temp;
558+
std::string temp;
561559
tokenizer.get_token(type,temp);
562560
while (type != tok::END_OF_FILE)
563561
{
@@ -582,7 +580,7 @@ namespace dlib
582580
tokenizer.get_token(type,token);
583581
// this is the start of a block comment
584582
token = "/*";
585-
string temp;
583+
std::string temp;
586584
tokenizer.get_token(type,temp);
587585
while (type != tok::END_OF_FILE)
588586
{

dlib/data_io/libsvm_io.h

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ namespace dlib
3030
std::vector<label_type, alloc2>& labels
3131
)
3232
{
33-
using namespace std;
3433
typedef typename sample_type::value_type pair_type;
3534
typedef typename basic_type<typename pair_type::first_type>::type key_type;
3635
typedef typename pair_type::second_type value_type;
@@ -41,13 +40,13 @@ namespace dlib
4140
samples.clear();
4241
labels.clear();
4342

44-
ifstream fin(file_name.c_str());
43+
std::ifstream fin(file_name.c_str());
4544

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

49-
string line;
50-
istringstream sin;
48+
std::string line;
49+
std::istringstream sin;
5150
key_type key;
5251
value_type value;
5352
label_type label;
@@ -56,12 +55,12 @@ namespace dlib
5655
while (fin.peek() != EOF)
5756
{
5857
++line_num;
59-
getline(fin, line);
58+
std::getline(fin, line);
6059

61-
string::size_type pos = line.find_first_not_of(" \t\r\n");
60+
std::string::size_type pos = line.find_first_not_of(" \t\r\n");
6261

6362
// ignore empty lines or comment lines
64-
if (pos == string::npos || line[pos] == '#')
63+
if (pos == std::string::npos || line[pos] == '#')
6564
continue;
6665

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

7675
// eat whitespace
77-
sin >> ws;
76+
sin >> std::ws;
7877

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

82-
sin >> key >> ws;
81+
sin >> key >> std::ws;
8382

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

9089
if (sin && value != 0)
9190
{
92-
sample.insert(sample.end(), make_pair(key, value));
91+
sample.insert(sample.end(), std::make_pair(key, value));
9392
}
9493

95-
sin >> ws;
94+
sin >> std::ws;
9695
}
9796

9897
samples.push_back(sample);
@@ -202,8 +201,7 @@ namespace dlib
202201
);
203202

204203

205-
using namespace std;
206-
ofstream fout(file_name.c_str());
204+
std::ofstream fout(file_name.c_str());
207205
fout.precision(14);
208206

209207
if (!fout)
@@ -244,8 +242,7 @@ namespace dlib
244242
<< "\n\t labels.size(): " << labels.size()
245243
);
246244

247-
using namespace std;
248-
ofstream fout(file_name.c_str());
245+
std::ofstream fout(file_name.c_str());
249246
fout.precision(14);
250247

251248
if (!fout)

dlib/dir_nav/dir_nav_kernel_1.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,6 @@ namespace dlib
390390
queue_of_files& files
391391
)
392392
{
393-
using namespace std;
394393
typedef directory::listing_error listing_error;
395394
typedef file::private_constructor private_constructor;
396395

@@ -402,7 +401,7 @@ namespace dlib
402401
try
403402
{
404403
WIN32_FIND_DATAA data;
405-
string path = state.full_name;
404+
std::string path = state.full_name;
406405
// ensure that the path ends with a separator
407406
if (path[path.size()-1] != directory::get_separator())
408407
path += directory::get_separator();
@@ -514,7 +513,6 @@ namespace dlib
514513
queue_of_dirs& dirs
515514
)
516515
{
517-
using namespace std;
518516
typedef directory::listing_error listing_error;
519517
typedef directory::private_constructor private_constructor;
520518

@@ -526,7 +524,7 @@ namespace dlib
526524
try
527525
{
528526
WIN32_FIND_DATAA data;
529-
string path = state.full_name;
527+
std::string path = state.full_name;
530528
// ensure that the path ends with a separator
531529
if (path[path.size()-1] != directory::get_separator())
532530
path += directory::get_separator();
@@ -541,7 +539,7 @@ namespace dlib
541539
bool no_more_files = false;
542540
do
543541
{
544-
string tname(data.cFileName);
542+
std::string tname(data.cFileName);
545543
if ((data.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY) != 0 &&
546544
tname != "." &&
547545
tname != "..")

dlib/dir_nav/dir_nav_kernel_2.h

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -333,8 +333,6 @@ namespace dlib
333333
queue_of_files& files
334334
)
335335
{
336-
using namespace std;
337-
338336
files.clear();
339337
if (state.full_name.size() == 0)
340338
throw directory::listing_error("This directory object currently doesn't represent any directory.");
@@ -345,7 +343,7 @@ namespace dlib
345343

346344
try
347345
{
348-
string path = state.full_name;
346+
std::string path = state.full_name;
349347
// ensure that the path ends with a separator
350348
if (path[path.size()-1] != directory::get_separator())
351349
path += directory::get_separator();
@@ -490,8 +488,6 @@ namespace dlib
490488
queue_of_dirs& dirs
491489
)
492490
{
493-
using namespace std;
494-
495491
dirs.clear();
496492
if (state.full_name.size() == 0)
497493
throw directory::listing_error("This directory object currently doesn't represent any directory.");
@@ -502,7 +498,7 @@ namespace dlib
502498

503499
try
504500
{
505-
string path = state.full_name;
501+
std::string path = state.full_name;
506502
// ensure that the path ends with a separator
507503
if (path[path.size()-1] != directory::get_separator())
508504
path += directory::get_separator();
@@ -540,7 +536,7 @@ namespace dlib
540536
continue;
541537
}
542538

543-
string dtemp(data->d_name);
539+
std::string dtemp(data->d_name);
544540
if (S_ISDIR(buffer.st_mode) &&
545541
dtemp != "." &&
546542
dtemp != ".." )

0 commit comments

Comments
 (0)