Skip to content

Commit

Permalink
remove using namespace std from headers
Browse files Browse the repository at this point in the history
  • Loading branch information
arrufat committed Sep 19, 2024
1 parent fafdac3 commit 94c4b69
Show file tree
Hide file tree
Showing 45 changed files with 152 additions and 248 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
3 changes: 0 additions & 3 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 @@ -497,7 +495,6 @@ namespace dlib
const std::string& title
) const
{
using namespace std;
ostringstream sout;
print(in,sout,title);
istringstream sin(sout.str());
Expand Down
3 changes: 0 additions & 3 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 @@ -434,7 +432,6 @@ namespace dlib
const std::string& title
) const
{
using namespace std;
ostringstream sout;
print(in,sout,title);
istringstream sin(sout.str());
Expand Down
2 changes: 0 additions & 2 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
25 changes: 11 additions & 14 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 @@ -92,7 +91,7 @@ namespace dlib
sample.insert(sample.end(), 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
2 changes: 0 additions & 2 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 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 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
33 changes: 13 additions & 20 deletions dlib/dnn/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -3390,9 +3390,8 @@ namespace dlib
const auto forward_error = max(abs(mat(ip_out) - mat(subnetwork2.get_output())));
if (forward_error > 0.00001)
{
using namespace std;
sout << "This layer is supposed to support in-place computations but the output of forward_inplace()\n";
sout << "changes when invoked in-place vs. out-of-place. The error was: " << forward_error << endl;
sout << "changes when invoked in-place vs. out-of-place. The error was: " << forward_error << std::endl;
return layer_test_results(sout.str());
}

Expand Down Expand Up @@ -3422,18 +3421,16 @@ namespace dlib
const auto backward_param_error = max(abs(mat(params_grad1) - mat(params_grad2)));
if (backward_param_error > 0.00001)
{
using namespace std;
sout << "This layer is supposed to support in-place computations but the output of backward_inplace()\n";
sout << "changes when invoked in-place vs. out-of-place. The error was: " << backward_param_error << endl;
sout << "changes when invoked in-place vs. out-of-place. The error was: " << backward_param_error << std::endl;
return layer_test_results(sout.str());
}
}
const auto backward_data_error = max(abs(mat(data_grad1)-9 - mat(data_grad2)));
if (backward_data_error > 0.00001)
{
using namespace std;
sout << "This layer is supposed to support in-place computations but the output of backward_inplace()\n";
sout << "changes when invoked in-place vs. out-of-place. The error was: " << backward_data_error << endl;
sout << "changes when invoked in-place vs. out-of-place. The error was: " << backward_data_error << std::endl;
return layer_test_results(sout.str());
}
}
Expand Down Expand Up @@ -3467,11 +3464,10 @@ namespace dlib
rs_params.add(std::abs(relative_error));
if (std::abs(relative_error) > 0.05 && std::abs(absolute_error) > 0.006)
{
using namespace std;
sout << "Gradient error in parameter #" << i <<". Relative error: "<< relative_error << endl;
sout << "expected derivative: " << reference_derivative << endl;
sout << "output derivative: " << output_derivative << endl;
sout << "iteration: " << iter << endl;
sout << "Gradient error in parameter #" << i <<". Relative error: "<< relative_error << std::endl;
sout << "expected derivative: " << reference_derivative << std::endl;
sout << "output derivative: " << output_derivative << std::endl;
sout << "iteration: " << iter << std::endl;
return layer_test_results(sout.str());
}
}
Expand Down Expand Up @@ -3504,11 +3500,10 @@ namespace dlib
rs_data.add(std::abs(relative_error));
if (std::abs(relative_error) > 0.05 && std::abs(absolute_error) > 0.006)
{
using namespace std;
sout << "Gradient error in data variable #" << i <<". Relative error: "<< relative_error << endl;
sout << "expected derivative: " << reference_derivative << endl;
sout << "output derivative: " << output_derivative << endl;
sout << "iteration: " << iter << endl;
sout << "Gradient error in data variable #" << i <<". Relative error: "<< relative_error << std::endl;
sout << "expected derivative: " << reference_derivative << std::endl;
sout << "output derivative: " << output_derivative << std::endl;
sout << "iteration: " << iter << std::endl;
return layer_test_results(sout.str());
}
}
Expand All @@ -3517,14 +3512,12 @@ namespace dlib

if (rs_params.mean() > 0.003)
{
using namespace std;
sout << "Average parameter gradient error is somewhat large at: "<< rs_params.mean() << endl;
sout << "Average parameter gradient error is somewhat large at: "<< rs_params.mean() << std::endl;
return layer_test_results(sout.str());
}
if (rs_data.mean() > 0.003)
{
using namespace std;
sout << "Average data gradient error is somewhat large at: "<< rs_data.mean() << endl;
sout << "Average data gradient error is somewhat large at: "<< rs_data.mean() << std::endl;
return layer_test_results(sout.str());
}

Expand Down
5 changes: 2 additions & 3 deletions dlib/dnn/loss.h
Original file line number Diff line number Diff line change
Expand Up @@ -1843,12 +1843,11 @@ namespace dlib
use_image_pyramid assume_image_pyramid
) const
{
using namespace std;
if (!input_layer(net).image_contained_point(input_tensor,center(rect)))
{
std::ostringstream sout;
sout << "Encountered a truth rectangle located at " << rect << " that is outside the image." << endl;
sout << "The center of each truth rectangle must be within the image." << endl;
sout << "Encountered a truth rectangle located at " << rect << " that is outside the image." << std::endl;
sout << "The center of each truth rectangle must be within the image." << std::endl;
throw impossible_labeling_error(sout.str());
}

Expand Down
2 changes: 0 additions & 2 deletions dlib/dnn/utilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ namespace dlib
inline double log1pexp(double x)
{
using std::exp;
using namespace std; // Do this instead of using std::log1p because some compilers
// error out otherwise (E.g. gcc 4.9 in cygwin)
if (x <= -37)
return exp(x);
else if (-37 < x && x <= 18)
Expand Down
1 change: 0 additions & 1 deletion dlib/error.h
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,6 @@ namespace dlib
<< "To prevent further fatal errors from being ignored this application will be \n"
<< "terminated immediately and you should go fix this buggy program.\n\n"
<< "The error message from this fatal error was:\n" << this->what() << "\n\n" << std::endl;
using namespace std;
assert(false);
abort();
}
Expand Down
5 changes: 0 additions & 5 deletions dlib/graph_utils/graph_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,6 @@ namespace dlib
- #visited[N.index()] == true
!*/
{
using namespace std;
if (visited[node.index()] == true)
return true;

Expand Down Expand Up @@ -269,7 +268,6 @@ namespace dlib
- #visited[N.index()] == true
!*/
{
using namespace std;
if (visited[node.index()] == true)
return true;

Expand Down Expand Up @@ -511,7 +509,6 @@ namespace dlib
const T& graph
)
{
using namespace std;
using namespace graph_helpers;
std::vector<bool> visited(graph.number_of_nodes(), false);
std::vector<bool> temp(graph.number_of_nodes(), false);
Expand Down Expand Up @@ -544,7 +541,6 @@ namespace dlib
const T& graph
)
{
using namespace std;
using namespace graph_helpers;
std::vector<bool> visited(graph.number_of_nodes(), false);

Expand Down Expand Up @@ -860,7 +856,6 @@ namespace dlib


using namespace graph_helpers;
using namespace std;
typedef typename set_of_sets_of_int::type set_of_int;

cliques.clear();
Expand Down
1 change: 0 additions & 1 deletion dlib/image_keypoint/hessian_pyramid.h
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,6 @@ namespace dlib
<< "\n\t Invalid arguments to this function"
<< "\n\t threshold: " << threshold
);
using namespace std;
using namespace hessian_pyramid_helpers;

result_points.clear();
Expand Down
5 changes: 1 addition & 4 deletions dlib/image_loader/image_loader.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include "../uintn.h"
#include "../image_transforms/assign_image.h"
#include <algorithm>
#include "../vectorstream.h"

namespace dlib
{
Expand Down Expand Up @@ -48,9 +47,7 @@ namespace dlib
unsigned long biCompression;
unsigned long a, b, c, d, i;

using namespace std;

streambuf& in = *in_.rdbuf();
std::streambuf& in = *in_.rdbuf();
unsigned char buf[100];


Expand Down
Loading

0 comments on commit 94c4b69

Please sign in to comment.