diff --git a/dlib/any/any_function_abstract.h b/dlib/any/any_function_abstract.h index 8c0da07365..fc7db2f9a2 100644 --- a/dlib/any/any_function_abstract.h +++ b/dlib/any/any_function_abstract.h @@ -46,7 +46,6 @@ namespace dlib #include #include #include "dlib/any.h" - using namespace std; void print_message(string str) { cout << str << endl; } int main() diff --git a/dlib/cmd_line_parser/cmd_line_parser_kernel_1.h b/dlib/cmd_line_parser/cmd_line_parser_kernel_1.h index 68ea5a1350..2a1bef0702 100644 --- a/dlib/cmd_line_parser/cmd_line_parser_kernel_1.h +++ b/dlib/cmd_line_parser/cmd_line_parser_kernel_1.h @@ -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(); diff --git a/dlib/config_reader/config_reader_thread_safe_1.h b/dlib/config_reader/config_reader_thread_safe_1.h index 1ad250c99a..6098ad3b45 100644 --- a/dlib/config_reader/config_reader_thread_safe_1.h +++ b/dlib/config_reader/config_reader_thread_safe_1.h @@ -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()) diff --git a/dlib/cpp_pretty_printer/cpp_pretty_printer_kernel_1.h b/dlib/cpp_pretty_printer/cpp_pretty_printer_kernel_1.h index c8bee1e4b2..97b82c475d 100644 --- a/dlib/cpp_pretty_printer/cpp_pretty_printer_kernel_1.h +++ b/dlib/cpp_pretty_printer/cpp_pretty_printer_kernel_1.h @@ -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"); @@ -497,7 +495,6 @@ namespace dlib const std::string& title ) const { - using namespace std; ostringstream sout; print(in,sout,title); istringstream sin(sout.str()); diff --git a/dlib/cpp_pretty_printer/cpp_pretty_printer_kernel_2.h b/dlib/cpp_pretty_printer/cpp_pretty_printer_kernel_2.h index 5ac894b339..5123d77f3c 100644 --- a/dlib/cpp_pretty_printer/cpp_pretty_printer_kernel_2.h +++ b/dlib/cpp_pretty_printer/cpp_pretty_printer_kernel_2.h @@ -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"); @@ -434,7 +432,6 @@ namespace dlib const std::string& title ) const { - using namespace std; ostringstream sout; print(in,sout,title); istringstream sin(sout.str()); diff --git a/dlib/cpp_tokenizer/cpp_tokenizer_kernel_1.h b/dlib/cpp_tokenizer/cpp_tokenizer_kernel_1.h index b26cfc8a54..e930eef981 100644 --- a/dlib/cpp_tokenizer/cpp_tokenizer_kernel_1.h +++ b/dlib/cpp_tokenizer/cpp_tokenizer_kernel_1.h @@ -380,8 +380,6 @@ namespace dlib std::string& token ) { - using namespace std; - if (!have_peeked) { diff --git a/dlib/data_io/libsvm_io.h b/dlib/data_io/libsvm_io.h index f365e82d7d..3905b24488 100644 --- a/dlib/data_io/libsvm_io.h +++ b/dlib/data_io/libsvm_io.h @@ -30,7 +30,6 @@ namespace dlib std::vector& labels ) { - using namespace std; typedef typename sample_type::value_type pair_type; typedef typename basic_type::type key_type; typedef typename pair_type::second_type value_type; @@ -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; @@ -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(); @@ -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() != ':') @@ -92,7 +91,7 @@ namespace dlib sample.insert(sample.end(), make_pair(key, value)); } - sin >> ws; + sin >> std::ws; } samples.push_back(sample); @@ -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) @@ -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) diff --git a/dlib/dir_nav/dir_nav_kernel_1.h b/dlib/dir_nav/dir_nav_kernel_1.h index a31f689de8..178cf4e425 100644 --- a/dlib/dir_nav/dir_nav_kernel_1.h +++ b/dlib/dir_nav/dir_nav_kernel_1.h @@ -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; @@ -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; diff --git a/dlib/dir_nav/dir_nav_kernel_2.h b/dlib/dir_nav/dir_nav_kernel_2.h index af2f3d5dc9..3560153bbf 100644 --- a/dlib/dir_nav/dir_nav_kernel_2.h +++ b/dlib/dir_nav/dir_nav_kernel_2.h @@ -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."); @@ -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(); @@ -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."); @@ -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(); @@ -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 != ".." ) diff --git a/dlib/dnn/core.h b/dlib/dnn/core.h index 6cfb41bc50..dd4f7eb0fb 100644 --- a/dlib/dnn/core.h +++ b/dlib/dnn/core.h @@ -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()); } @@ -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()); } } @@ -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()); } } @@ -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()); } } @@ -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()); } diff --git a/dlib/dnn/loss.h b/dlib/dnn/loss.h index 70c316b0fc..a569268398 100644 --- a/dlib/dnn/loss.h +++ b/dlib/dnn/loss.h @@ -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()); } diff --git a/dlib/dnn/utilities.h b/dlib/dnn/utilities.h index ac7d6c6282..1aaba86ee0 100644 --- a/dlib/dnn/utilities.h +++ b/dlib/dnn/utilities.h @@ -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) diff --git a/dlib/error.h b/dlib/error.h index ce9b95b1a8..898019a99a 100644 --- a/dlib/error.h +++ b/dlib/error.h @@ -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(); } diff --git a/dlib/graph_utils/graph_utils.h b/dlib/graph_utils/graph_utils.h index 81262b7f5c..fd5135cc15 100644 --- a/dlib/graph_utils/graph_utils.h +++ b/dlib/graph_utils/graph_utils.h @@ -224,7 +224,6 @@ namespace dlib - #visited[N.index()] == true !*/ { - using namespace std; if (visited[node.index()] == true) return true; @@ -269,7 +268,6 @@ namespace dlib - #visited[N.index()] == true !*/ { - using namespace std; if (visited[node.index()] == true) return true; @@ -511,7 +509,6 @@ namespace dlib const T& graph ) { - using namespace std; using namespace graph_helpers; std::vector visited(graph.number_of_nodes(), false); std::vector temp(graph.number_of_nodes(), false); @@ -544,7 +541,6 @@ namespace dlib const T& graph ) { - using namespace std; using namespace graph_helpers; std::vector visited(graph.number_of_nodes(), false); @@ -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(); diff --git a/dlib/image_keypoint/hessian_pyramid.h b/dlib/image_keypoint/hessian_pyramid.h index 9d6d8902dd..57b76663d3 100644 --- a/dlib/image_keypoint/hessian_pyramid.h +++ b/dlib/image_keypoint/hessian_pyramid.h @@ -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(); diff --git a/dlib/image_loader/image_loader.h b/dlib/image_loader/image_loader.h index e959973f63..1201529852 100644 --- a/dlib/image_loader/image_loader.h +++ b/dlib/image_loader/image_loader.h @@ -14,7 +14,6 @@ #include "../uintn.h" #include "../image_transforms/assign_image.h" #include -#include "../vectorstream.h" namespace dlib { @@ -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]; diff --git a/dlib/image_processing/detection_template_tools.h b/dlib/image_processing/detection_template_tools.h index b22c109fe5..09b6e69ff1 100644 --- a/dlib/image_processing/detection_template_tools.h +++ b/dlib/image_processing/detection_template_tools.h @@ -32,7 +32,6 @@ namespace dlib width*height == area width/height == width_to_height_ratio */ - using namespace std; const int height = (int)std::floor(std::sqrt(area/width_to_height_ratio) + 0.5); const int width = (int)std::floor(area/height + 0.5); diff --git a/dlib/matrix/matrix.h b/dlib/matrix/matrix.h index 9073c36b46..2cbebe12ba 100644 --- a/dlib/matrix/matrix.h +++ b/dlib/matrix/matrix.h @@ -1995,12 +1995,11 @@ namespace dlib const matrix_exp& m ) { - using namespace std; - const streamsize old = out.width(); + const std::streamsize old = out.width(); // first figure out how wide we should make each field - string::size_type w = 0; - ostringstream sout; + std::string::size_type w = 0; + std::ostringstream sout; for (long r = 0; r < m.nr(); ++r) { for (long c = 0; c < m.nc(); ++c) @@ -2016,7 +2015,7 @@ namespace dlib { for (long c = 0; c < m.nc(); ++c) { - out.width(static_cast(w)); + out.width(static_cast(w)); out << m(r,c) << " "; } out << "\n"; diff --git a/dlib/matrix/matrix_blas_bindings.h b/dlib/matrix/matrix_blas_bindings.h index e69739fd24..513b1ee6a9 100644 --- a/dlib/matrix/matrix_blas_bindings.h +++ b/dlib/matrix/matrix_blas_bindings.h @@ -13,13 +13,8 @@ #include "cblas_constants.h" #include -//#include -//using namespace std; - namespace dlib { - - namespace blas_bindings { diff --git a/dlib/matrix/matrix_lu.h b/dlib/matrix/matrix_lu.h index 3e49cd6533..faedd53f85 100644 --- a/dlib/matrix/matrix_lu.h +++ b/dlib/matrix/matrix_lu.h @@ -101,7 +101,6 @@ namespace dlib m(A.nr()), n(A.nc()) { - using namespace std; using std::abs; COMPILE_TIME_ASSERT((is_same_type::value)); diff --git a/dlib/optimization/elastic_net.h b/dlib/optimization/elastic_net.h index 6c4b6d0b43..ced2b28a8a 100644 --- a/dlib/optimization/elastic_net.h +++ b/dlib/optimization/elastic_net.h @@ -297,7 +297,6 @@ namespace dlib if (verbose) { - using namespace std; cout << "gap: " << PG_max - PG_min << endl; cout << "active_size: " << active_size << endl; cout << "iter: " << iter << endl; diff --git a/dlib/optimization/optimization_solve_qp2_using_smo.h b/dlib/optimization/optimization_solve_qp2_using_smo.h index 88cad0cf3c..787d4ae416 100644 --- a/dlib/optimization/optimization_solve_qp2_using_smo.h +++ b/dlib/optimization/optimization_solve_qp2_using_smo.h @@ -281,7 +281,6 @@ namespace dlib long& j_out ) const { - using namespace std; long ip = 0; long jp = 0; long in = 0; @@ -291,10 +290,10 @@ namespace dlib typedef typename colm_exp::type col_type; typedef typename diag_exp::type diag_type; - scalar_type ip_val = -numeric_limits::infinity(); - scalar_type jp_val = numeric_limits::infinity(); - scalar_type in_val = -numeric_limits::infinity(); - scalar_type jn_val = numeric_limits::infinity(); + scalar_type ip_val = -std::numeric_limits::infinity(); + scalar_type jp_val = std::numeric_limits::infinity(); + scalar_type in_val = -std::numeric_limits::infinity(); + scalar_type jn_val = std::numeric_limits::infinity(); // loop over the alphas and find the maximum ip and in indices. for (long i = 0; i < alpha.nr(); ++i) @@ -323,8 +322,8 @@ namespace dlib } } - scalar_type Mp = numeric_limits::infinity(); - scalar_type Mn = numeric_limits::infinity(); + scalar_type Mp = std::numeric_limits::infinity(); + scalar_type Mn = std::numeric_limits::infinity(); // Pick out the columns and diagonal of Q we need below. Doing // it this way is faster if Q is actually a symmetric_matrix_cache diff --git a/dlib/optimization/optimization_solve_qp3_using_smo.h b/dlib/optimization/optimization_solve_qp3_using_smo.h index 617ecc408c..eb83fc85d1 100644 --- a/dlib/optimization/optimization_solve_qp3_using_smo.h +++ b/dlib/optimization/optimization_solve_qp3_using_smo.h @@ -218,17 +218,14 @@ namespace dlib long& j_out ) const { - using namespace std; - long ip = 0; long jp = 0; - typedef typename colm_exp::type col_type; typedef typename diag_exp::type diag_type; - scalar_type ip_val = -numeric_limits::infinity(); - scalar_type jp_val = numeric_limits::infinity(); + scalar_type ip_val = -std::numeric_limits::infinity(); + scalar_type jp_val = std::numeric_limits::infinity(); // loop over the alphas and find the maximum ip and in indices. for (long i = 0; i < alpha.nr(); ++i) @@ -257,7 +254,7 @@ namespace dlib } } - scalar_type Mp = -numeric_limits::infinity(); + scalar_type Mp = -std::numeric_limits::infinity(); // Pick out the column and diagonal of Q we need below. Doing // it this way is faster if Q is actually a symmetric_matrix_cache diff --git a/dlib/optimization/optimization_solve_qp_using_smo.h b/dlib/optimization/optimization_solve_qp_using_smo.h index c942d064a4..339fe77ce0 100644 --- a/dlib/optimization/optimization_solve_qp_using_smo.h +++ b/dlib/optimization/optimization_solve_qp_using_smo.h @@ -200,7 +200,6 @@ namespace dlib } /* - using namespace std; cout << "SMO: " << endl; cout << " duality gap: "<< trans(alpha)*df - C*min(df) << endl; cout << " KKT gap: "<< big-little << endl; @@ -394,7 +393,6 @@ namespace dlib } /* - using namespace std; cout << "SMO: " << endl; cout << " duality gap: "<< trans(alpha)*df - C*min(df) << endl; cout << " KKT gap: "<< big-little << endl; diff --git a/dlib/optimization/optimization_stop_strategies.h b/dlib/optimization/optimization_stop_strategies.h index a0243cacf4..ff64ef8a86 100644 --- a/dlib/optimization/optimization_stop_strategies.h +++ b/dlib/optimization/optimization_stop_strategies.h @@ -60,8 +60,7 @@ namespace dlib { if (_verbose) { - using namespace std; - cout << "iteration: " << _cur_iter << " objective: " << funct_value << endl; + std::cout << "iteration: " << _cur_iter << " objective: " << funct_value << std::endl; } ++_cur_iter; @@ -139,8 +138,7 @@ namespace dlib { if (_verbose) { - using namespace std; - cout << "iteration: " << _cur_iter << " objective: " << funct_value << " gradient norm: " << length(funct_derivative) << endl; + std::cout << "iteration: " << _cur_iter << " objective: " << funct_value << " gradient norm: " << length(funct_derivative) << std::endl; } ++_cur_iter; diff --git a/dlib/pixel.h b/dlib/pixel.h index f995dd477f..d53a0fbe18 100644 --- a/dlib/pixel.h +++ b/dlib/pixel.h @@ -1068,7 +1068,6 @@ namespace dlib { double themin,themax,delta; HSL c2; - using namespace std; themin = std::min(c1.r,std::min(c1.g,c1.b)); themax = std::max(c1.r,std::max(c1.g,c1.b)); @@ -1099,7 +1098,6 @@ namespace dlib inline COLOUR HSL2RGB(HSL c1) { COLOUR c2,sat,ctmp; - using namespace std; if (c1.h < 120) { sat.r = (120 - c1.h) / 60.0; @@ -1267,26 +1265,25 @@ namespace dlib inline Lab RGB2Lab(COLOUR c1) { Lab c2; - using namespace std; double var_R = c1.r; double var_G = c1.g; double var_B = c1.b; if (var_R > 0.04045) { - var_R = pow(((var_R + 0.055) / 1.055), 2.4); + var_R = std::pow(((var_R + 0.055) / 1.055), 2.4); } else { var_R = var_R / 12.92; } if (var_G > 0.04045) { - var_G = pow(((var_G + 0.055) / 1.055), 2.4); + var_G = std::pow(((var_G + 0.055) / 1.055), 2.4); } else { var_G = var_G / 12.92; } if (var_B > 0.04045) { - var_B = pow(((var_B + 0.055) / 1.055), 2.4); + var_B = std::pow(((var_B + 0.055) / 1.055), 2.4); } else { var_B = var_B / 12.92; } @@ -1305,21 +1302,21 @@ namespace dlib double var_Z = Z / 108.883; if (var_X > 0.008856) { - var_X = pow(var_X, (1.0 / 3)); + var_X = std::pow(var_X, (1.0 / 3)); } else { var_X = (7.787 * var_X) + (16.0 / 116); } if (var_Y > 0.008856) { - var_Y = pow(var_Y, (1.0 / 3)); + var_Y = std::pow(var_Y, (1.0 / 3)); } else { var_Y = (7.787 * var_Y) + (16.0 / 116); } if (var_Z > 0.008856) { - var_Z = pow(var_Z, (1.0 / 3)); + var_Z = std::pow(var_Z, (1.0 / 3)); } else { var_Z = (7.787 * var_Z) + (16.0 / 116); @@ -1342,26 +1339,25 @@ namespace dlib */ inline COLOUR Lab2RGB(Lab c1) { COLOUR c2; - using namespace std; double var_Y = (c1.l + 16) / 116.0; double var_X = (c1.a / 500.0) + var_Y; double var_Z = var_Y - (c1.b / 200); - if (pow(var_Y, 3) > 0.008856) { - var_Y = pow(var_Y, 3); + if (std::pow(var_Y, 3) > 0.008856) { + var_Y = std::pow(var_Y, 3); } else { var_Y = (var_Y - 16.0 / 116) / 7.787; } - if (pow(var_X, 3) > 0.008856) { - var_X = pow(var_X, 3); + if (std::pow(var_X, 3) > 0.008856) { + var_X = std::pow(var_X, 3); } else { var_X = (var_X - 16.0 / 116) / 7.787; } - if (pow(var_Z, 3) > 0.008856) { - var_Z = pow(var_Z, 3); + if (std::pow(var_Z, 3) > 0.008856) { + var_Z = std::pow(var_Z, 3); } else { var_Z = (var_Z - 16.0 / 116) / 7.787; } @@ -1379,19 +1375,19 @@ namespace dlib double var_B = var_X * 0.0557 + var_Y * -0.2040 + var_Z * 1.0570; if (var_R > 0.0031308) { - var_R = 1.055 * pow(var_R, (1 / 2.4)) - 0.055; + var_R = 1.055 * std::pow(var_R, (1 / 2.4)) - 0.055; } else { var_R = 12.92 * var_R; } if (var_G > 0.0031308) { - var_G = 1.055 * pow(var_G, (1 / 2.4)) - 0.055; + var_G = 1.055 * std::pow(var_G, (1 / 2.4)) - 0.055; } else { var_G = 12.92 * var_G; } if (var_B > 0.0031308) { - var_B = 1.055 * pow(var_B, (1 / 2.4)) - 0.055; + var_B = 1.055 * std::pow(var_B, (1 / 2.4)) - 0.055; } else { var_B = 12.92 * var_B; } diff --git a/dlib/string/string.h b/dlib/string/string.h index 2c26021988..bf300fd350 100644 --- a/dlib/string/string.h +++ b/dlib/string/string.h @@ -290,8 +290,7 @@ namespace dlib const std::basic_string& str ) { - using namespace std; - basic_istringstream sin(str); + std::basic_istringstream sin(str); T temp; sin >> temp; if (!sin) throw string_cast_error(narrow(str)); @@ -324,7 +323,6 @@ namespace dlib const std::basic_string& str ) { - using namespace std; if (str.size() == 1 && str[0] == '1') return true; if (str.size() == 1 && str[0] == '0') @@ -347,14 +345,13 @@ namespace dlib const std::basic_string& str \ ) \ { \ - using namespace std; \ - basic_istringstream sin(str); \ + std::basic_istringstream sin(str); \ type temp; \ if (str.size() > 2 && str[0] == _dT(charT,'0') && str[1] == _dT(charT,'x')) \ - sin >> hex >> temp; \ + sin >> std::hex >> temp; \ else \ sin >> temp; \ - if (!sin) throw string_cast_error(narrow(str)); \ + if (!sin) throw string_cast_error(narrow(str)); \ if (sin.get() != std::char_traits::eof()) throw string_cast_error(narrow(str)); \ return temp; \ } \ @@ -508,23 +505,21 @@ namespace dlib << "\n\trest_pad: " << rest_pad << "\n\tmax_per_line: " << max_per_line ); - using namespace std; - - basic_ostringstream sout; - basic_istringstream sin(str); + std::basic_ostringstream sout; + std::basic_istringstream sin(str); for (unsigned long i = 0; i < rest_pad; ++i) sout << _dT(charT," "); - const basic_string pad(sout.str()); + const std::basic_string pad(sout.str()); sout.str(_dT(charT,"")); for (unsigned long i = 0; i < first_pad; ++i) sout << _dT(charT," "); - typename basic_string::size_type remaining = max_per_line - rest_pad; + typename std::basic_string::size_type remaining = max_per_line - rest_pad; - basic_string temp; + std::basic_string temp; sin >> temp; while (sin) @@ -533,7 +528,7 @@ namespace dlib { if (temp.size() + rest_pad >= max_per_line) { - string::size_type i = 0; + std::string::size_type i = 0; for (; i < temp.size(); ++i) { sout << temp[i]; diff --git a/dlib/svm/feature_ranking.h b/dlib/svm/feature_ranking.h index f6324fe3d3..c1275c27f1 100644 --- a/dlib/svm/feature_ranking.h +++ b/dlib/svm/feature_ranking.h @@ -69,8 +69,6 @@ namespace dlib } - using namespace std; - for (long i = results.nr()-1; i >= 0; --i) { long worst_feature_idx = 0; @@ -189,8 +187,6 @@ namespace dlib matrix mask(samples(0).nr()); set_all_elements(mask,0); - using namespace std; - for (long i = 0; i < results.nr(); ++i) { long best_feature_idx = 0; @@ -332,8 +328,6 @@ namespace dlib double gamma ) const { - using namespace std; - // we are doing the optimization in log space so don't forget to convert back to normal space gamma = std::exp(gamma); @@ -347,8 +341,8 @@ namespace dlib if (verbose) { - cout << "\rChecking goodness of gamma = " << gamma << ". Goodness = " - << temp << " " << flush; + std::cout << "\rChecking goodness of gamma = " << gamma << ". Goodness = " + << temp << " " << std::flush; } return temp; } @@ -372,11 +366,9 @@ namespace dlib bool verbose ) { - using namespace std; - if (verbose) { - cout << endl; + std::cout << std::endl; } test funct(samples, labels, num_sv, verbose); @@ -385,8 +377,8 @@ namespace dlib if (verbose) { - cout << "\rBest gamma = " << std::exp(best_gamma) << ". Goodness = " - << goodness << " " << endl; + std::cout << "\rBest gamma = " << std::exp(best_gamma) << ". Goodness = " + << goodness << " " << std::endl; } return std::exp(best_gamma); diff --git a/dlib/svm/rr_trainer.h b/dlib/svm/rr_trainer.h index 09177217e3..7ea328d76c 100644 --- a/dlib/svm/rr_trainer.h +++ b/dlib/svm/rr_trainer.h @@ -394,12 +394,11 @@ namespace dlib if (verbose && did_loov) { - using namespace std; - cout << "Using lambda: " << the_lambda << endl; + std::cout << "Using lambda: " << the_lambda << std::endl; if (use_regression_loss) - cout << "LOO Mean Squared Error: " << best_looe << endl; + std::cout << "LOO Mean Squared Error: " << best_looe << std::endl; else - cout << "LOO Classification Error: " << best_looe << endl; + std::cout << "LOO Classification Error: " << best_looe << std::endl; } // convert w into a proper decision function diff --git a/dlib/svm/structural_svm_object_detection_problem.h b/dlib/svm/structural_svm_object_detection_problem.h index 1c54a42b11..ee9ed6a1cd 100644 --- a/dlib/svm/structural_svm_object_detection_problem.h +++ b/dlib/svm/structural_svm_object_detection_problem.h @@ -230,8 +230,7 @@ namespace dlib const double match_amount = area_overlap/(double)( mapped_rects[i]+mapped_rects[j]).area(); const double overlap_amount = area_overlap/std::min(mapped_rects[i].area(),mapped_rects[j].area()); - using namespace std; - ostringstream sout; + std::ostringstream sout; sout << "An impossible set of object labels was detected. This is happening because "; sout << "the truth labels for an image contain rectangles which overlap according to the "; sout << "test_box_overlap object supplied for non-max suppression. To resolve this, you "; @@ -239,16 +238,16 @@ namespace dlib sout << "overlapping or adjust the truth rectangles in your training dataset. "; // make sure the above string fits nicely into a command prompt window. - string temp = sout.str(); - sout.str(""); sout << wrap_string(temp,0,0) << endl << endl; + std::string temp = sout.str(); + sout.str(""); sout << wrap_string(temp,0,0) << std::endl << std::endl; - sout << "image index: "<< idx << endl; + sout << "image index: "<< idx << std::endl; sout << "The offending rectangles are:\n"; - sout << "rect1: "<< mapped_rects[i] << endl; - sout << "rect2: "<< mapped_rects[j] << endl; - sout << "match amount: " << match_amount << endl; - sout << "overlap amount: " << overlap_amount << endl; + sout << "rect1: "<< mapped_rects[i] << std::endl; + sout << "rect2: "<< mapped_rects[j] << std::endl; + sout << "match amount: " << match_amount << std::endl; + sout << "overlap amount: " << overlap_amount << std::endl; throw dlib::impossible_labeling_error(sout.str()); } } @@ -262,8 +261,7 @@ namespace dlib const double total_area = (truth_object_detections[idx][i].get_rect() + mapped_rects[i]).area(); if (area/total_area <= match_eps) { - using namespace std; - ostringstream sout; + std::ostringstream sout; sout << "An impossible set of object labels was detected. This is happening because "; sout << "none of the object locations checked by the supplied image scanner is a close "; sout << "enough match to one of the truth boxes in your training dataset. To resolve this "; @@ -278,18 +276,18 @@ namespace dlib // make sure the above string fits nicely into a command prompt window. - string temp = sout.str(); - sout.str(""); sout << wrap_string(temp,0,0) << endl << endl; - - sout << "image index "<< idx << endl; - sout << "match_eps: "<< match_eps << endl; - sout << "best possible match: "<< area/total_area << endl; - sout << "truth rect: "<< truth_object_detections[idx][i].get_rect() << endl; - sout << "truth rect width/height: "<< truth_object_detections[idx][i].get_rect().width()/(double)truth_object_detections[idx][i].get_rect().height() << endl; - sout << "truth rect area: "<< truth_object_detections[idx][i].get_rect().area() << endl; - sout << "nearest detection template rect: "<< mapped_rects[i] << endl; - sout << "nearest detection template rect width/height: "<< mapped_rects[i].width()/(double)mapped_rects[i].height() << endl; - sout << "nearest detection template rect area: "<< mapped_rects[i].area() << endl; + std::string temp = sout.str(); + sout.str(""); sout << wrap_string(temp,0,0) << std::endl << std::endl; + + sout << "image index "<< idx << std::endl; + sout << "match_eps: "<< match_eps << std::endl; + sout << "best possible match: "<< area/total_area << std::endl; + sout << "truth rect: "<< truth_object_detections[idx][i].get_rect() << std::endl; + sout << "truth rect width/height: "<< truth_object_detections[idx][i].get_rect().width()/(double)truth_object_detections[idx][i].get_rect().height() << std::endl; + sout << "truth rect area: "<< truth_object_detections[idx][i].get_rect().area() << std::endl; + sout << "nearest detection template rect: "<< mapped_rects[i] << std::endl; + sout << "nearest detection template rect width/height: "<< mapped_rects[i].width()/(double)mapped_rects[i].height() << std::endl; + sout << "nearest detection template rect area: "<< mapped_rects[i].area() << std::endl; throw dlib::impossible_labeling_error(sout.str()); } diff --git a/dlib/svm/structural_svm_problem.h b/dlib/svm/structural_svm_problem.h index 3a73457b9f..b1f045449a 100644 --- a/dlib/svm/structural_svm_problem.h +++ b/dlib/svm/structural_svm_problem.h @@ -434,27 +434,26 @@ namespace dlib { if (verbose) { - using namespace std; if (nuclear_norm_regularizers.size() != 0) { - cout << "objective: " << current_objective_value << endl; - cout << "objective gap: " << current_error_gap << endl; - cout << "risk: " << current_risk_value-nuclear_norm_part << endl; - cout << "risk+nuclear norm: " << current_risk_value << endl; - cout << "risk+nuclear norm gap: " << current_risk_gap << endl; - cout << "num planes: " << num_cutting_planes << endl; - cout << "iter: " << num_iterations << endl; + std::cout << "objective: " << current_objective_value << std::endl; + std::cout << "objective gap: " << current_error_gap << std::endl; + std::cout << "risk: " << current_risk_value-nuclear_norm_part << std::endl; + std::cout << "risk+nuclear norm: " << current_risk_value << std::endl; + std::cout << "risk+nuclear norm gap: " << current_risk_gap << std::endl; + std::cout << "num planes: " << num_cutting_planes << std::endl; + std::cout << "iter: " << num_iterations << std::endl; } else { - cout << "objective: " << current_objective_value << endl; - cout << "objective gap: " << current_error_gap << endl; - cout << "risk: " << current_risk_value << endl; - cout << "risk gap: " << current_risk_gap << endl; - cout << "num planes: " << num_cutting_planes << endl; - cout << "iter: " << num_iterations << endl; + std::cout << "objective: " << current_objective_value << std::endl; + std::cout << "objective gap: " << current_error_gap << std::endl; + std::cout << "risk: " << current_risk_value << std::endl; + std::cout << "risk gap: " << current_risk_gap << std::endl; + std::cout << "num planes: " << num_cutting_planes << std::endl; + std::cout << "iter: " << num_iterations << std::endl; } - cout << endl; + std::cout << std::endl; } if (num_iterations >= max_iterations) diff --git a/dlib/svm/svm_c_linear_dcd_trainer.h b/dlib/svm/svm_c_linear_dcd_trainer.h index 039b70993e..6ac0e7ae75 100644 --- a/dlib/svm/svm_c_linear_dcd_trainer.h +++ b/dlib/svm/svm_c_linear_dcd_trainer.h @@ -619,11 +619,10 @@ namespace dlib if (verbose) { - using namespace std; - cout << "gap: " << PG_max - PG_min << endl; - cout << "active_size: " << active_size << endl; - cout << "iter: " << iter << endl; - cout << endl; + std::cout << "gap: " << PG_max - PG_min << std::endl; + std::cout << "active_size: " << active_size << std::endl; + std::cout << "iter: " << iter << std::endl; + std::cout << std::endl; } if (PG_max - PG_min <= eps) diff --git a/dlib/svm/svm_c_linear_trainer.h b/dlib/svm/svm_c_linear_trainer.h index 3764ddd8aa..e6c9730ce0 100644 --- a/dlib/svm/svm_c_linear_trainer.h +++ b/dlib/svm/svm_c_linear_trainer.h @@ -87,14 +87,13 @@ namespace dlib { if (be_verbose) { - using namespace std; - cout << "objective: " << current_objective_value << endl; - cout << "objective gap: " << current_error_gap << endl; - cout << "risk: " << current_risk_value << endl; - cout << "risk gap: " << current_risk_gap << endl; - cout << "num planes: " << num_cutting_planes << endl; - cout << "iter: " << num_iterations << endl; - cout << endl; + std::cout << "objective: " << current_objective_value << std::endl; + std::cout << "objective gap: " << current_error_gap << std::endl; + std::cout << "risk: " << current_risk_value << std::endl; + std::cout << "risk gap: " << current_risk_gap << std::endl; + std::cout << "num planes: " << num_cutting_planes << std::endl; + std::cout << "iter: " << num_iterations << std::endl; + std::cout << std::endl; } if (num_iterations >= max_iterations) diff --git a/dlib/svm/svm_c_trainer.h b/dlib/svm/svm_c_trainer.h index 445dbf69c7..b2c9d7dff2 100644 --- a/dlib/svm/svm_c_trainer.h +++ b/dlib/svm/svm_c_trainer.h @@ -277,12 +277,11 @@ namespace dlib scalar_type& b ) const { - using namespace std; long num_free = 0; scalar_type sum_free = 0; - scalar_type upper_bound = -numeric_limits::infinity(); - scalar_type lower_bound = numeric_limits::infinity(); + scalar_type upper_bound = -std::numeric_limits::infinity(); + scalar_type lower_bound = std::numeric_limits::infinity(); for(long i = 0; i < alpha.nr(); ++i) { diff --git a/dlib/svm/svm_nu_trainer.h b/dlib/svm/svm_nu_trainer.h index cf041b2354..59f49ab208 100644 --- a/dlib/svm/svm_nu_trainer.h +++ b/dlib/svm/svm_nu_trainer.h @@ -233,16 +233,15 @@ namespace dlib scalar_type& b ) const { - using namespace std; long num_p_free = 0; long num_n_free = 0; scalar_type sum_p_free = 0; scalar_type sum_n_free = 0; - scalar_type upper_bound_p = -numeric_limits::infinity(); - scalar_type upper_bound_n = -numeric_limits::infinity(); - scalar_type lower_bound_p = numeric_limits::infinity(); - scalar_type lower_bound_n = numeric_limits::infinity(); + scalar_type upper_bound_p = -std::numeric_limits::infinity(); + scalar_type upper_bound_n = -std::numeric_limits::infinity(); + scalar_type lower_bound_p = std::numeric_limits::infinity(); + scalar_type lower_bound_n = std::numeric_limits::infinity(); for(long i = 0; i < alpha.nr(); ++i) { diff --git a/dlib/svm/svm_one_class_trainer.h b/dlib/svm/svm_one_class_trainer.h index be3cc8caf3..6a5c55e951 100644 --- a/dlib/svm/svm_one_class_trainer.h +++ b/dlib/svm/svm_one_class_trainer.h @@ -224,7 +224,6 @@ namespace dlib scalar_type& rho ) const { - using namespace std; long num_p_free = 0; scalar_type sum_p_free = 0; diff --git a/dlib/svm/svm_rank_trainer.h b/dlib/svm/svm_rank_trainer.h index 0be737f485..03a7aeefa1 100644 --- a/dlib/svm/svm_rank_trainer.h +++ b/dlib/svm/svm_rank_trainer.h @@ -72,14 +72,13 @@ namespace dlib { if (be_verbose) { - using namespace std; - cout << "objective: " << current_objective_value << endl; - cout << "objective gap: " << current_error_gap << endl; - cout << "risk: " << current_risk_value << endl; - cout << "risk gap: " << current_risk_gap << endl; - cout << "num planes: " << num_cutting_planes << endl; - cout << "iter: " << num_iterations << endl; - cout << endl; + std::cout << "objective: " << current_objective_value << std::endl; + std::cout << "objective gap: " << current_error_gap << std::endl; + std::cout << "risk: " << current_risk_value << std::endl; + std::cout << "risk gap: " << current_risk_gap << std::endl; + std::cout << "num planes: " << num_cutting_planes << std::endl; + std::cout << "iter: " << num_iterations << std::endl; + std::cout << std::endl; } if (num_iterations >= max_iterations) diff --git a/dlib/svm/svr_linear_trainer.h b/dlib/svm/svr_linear_trainer.h index 27ce5b52a1..0708c29383 100644 --- a/dlib/svm/svr_linear_trainer.h +++ b/dlib/svm/svr_linear_trainer.h @@ -76,14 +76,13 @@ namespace dlib current_risk_gap /= samples.size(); if (be_verbose) { - using namespace std; - cout << "objective: " << current_objective_value << endl; - cout << "objective gap: " << current_error_gap << endl; - cout << "risk: " << current_risk_value << endl; - cout << "risk gap: " << current_risk_gap << endl; - cout << "num planes: " << num_cutting_planes << endl; - cout << "iter: " << num_iterations << endl; - cout << endl; + std::cout << "objective: " << current_objective_value << std::endl; + std::cout << "objective gap: " << current_error_gap << std::endl; + std::cout << "risk: " << current_risk_value << std::endl; + std::cout << "risk gap: " << current_risk_gap << std::endl; + std::cout << "num planes: " << num_cutting_planes << std::endl; + std::cout << "iter: " << num_iterations << std::endl; + std::cout << std::endl; } if (num_iterations >= max_iterations) diff --git a/dlib/svm/svr_trainer.h b/dlib/svm/svr_trainer.h index bc6378a200..6560b1513a 100644 --- a/dlib/svm/svr_trainer.h +++ b/dlib/svm/svr_trainer.h @@ -312,12 +312,11 @@ namespace dlib scalar_type& b ) const { - using namespace std; long num_free = 0; scalar_type sum_free = 0; - scalar_type upper_bound = -numeric_limits::infinity(); - scalar_type lower_bound = numeric_limits::infinity(); + scalar_type upper_bound = -std::numeric_limits::infinity(); + scalar_type lower_bound = std::numeric_limits::infinity(); find_min_and_max(df, upper_bound, lower_bound); diff --git a/dlib/test/binary_search_tree.h b/dlib/test/binary_search_tree.h index 18bdff70de..b1f6ecddfd 100644 --- a/dlib/test/binary_search_tree.h +++ b/dlib/test/binary_search_tree.h @@ -18,7 +18,6 @@ namespace { using namespace test; - using namespace std; using namespace dlib; logger dlog("test.binary_search_tree"); diff --git a/dlib/test/cmd_line_parser.h b/dlib/test/cmd_line_parser.h index 6f8e411a48..f5c7090607 100644 --- a/dlib/test/cmd_line_parser.h +++ b/dlib/test/cmd_line_parser.h @@ -15,7 +15,6 @@ namespace { using namespace test; using namespace dlib; - using namespace std; logger dlog("test.cmd_line_parser"); diff --git a/dlib/test/conditioning_class.h b/dlib/test/conditioning_class.h index 3c6c88b8dd..f8fe8ed30f 100644 --- a/dlib/test/conditioning_class.h +++ b/dlib/test/conditioning_class.h @@ -4,7 +4,6 @@ #define DLIB_TEST_CONDITIONING_CLASs_H_ -#include #include #include #include @@ -17,7 +16,6 @@ namespace { using namespace test; - using namespace std; using namespace dlib; logger dlog("test.conditioning_class"); diff --git a/dlib/threads/thread_pool_extension.h b/dlib/threads/thread_pool_extension.h index 06d091c874..bd459ed6f8 100644 --- a/dlib/threads/thread_pool_extension.h +++ b/dlib/threads/thread_pool_extension.h @@ -516,14 +516,12 @@ namespace dlib { std::cerr << "An unhandled exception was inside a dlib::thread_pool when it was destructed." << std::endl; std::cerr << "It's what string is: \n" << e.what() << std::endl; - using namespace std; assert(false); abort(); } catch (...) { std::cerr << "An unhandled exception was inside a dlib::thread_pool when it was destructed." << std::endl; - using namespace std; assert(false); abort(); } diff --git a/dlib/timing.h b/dlib/timing.h index 2d5116ade4..9bfcd7092f 100644 --- a/dlib/timing.h +++ b/dlib/timing.h @@ -89,8 +89,7 @@ namespace dlib // if this name buffer is empty then copy name into it if (buf[i][0] == '\0') { - using namespace std; - strncpy(buf[i], name, NAME_LENGTH-1); + std::strncpy(buf[i], name, NAME_LENGTH-1); buf[i][NAME_LENGTH-1] = '\0'; } // return the name buffer @@ -121,14 +120,13 @@ namespace dlib inline void print() { - using namespace std; - cout << "Timing report: " << endl; + std::cout << "Timing report: " << std::endl; // figure out how long the longest name is going to be. unsigned long max_name_length = 0; for (int i = 0; i < TIME_SLOTS; ++i) { - string name; + std::string name; // Check if the name buffer is empty. Use the name it contains if it isn't. if (name_buf(i,"")[0] != '\0') name = cast_to_string(i) + ": " + name_buf(i,""); diff --git a/dlib/tokenizer/tokenizer_kernel_c.h b/dlib/tokenizer/tokenizer_kernel_c.h index f9604809d9..67abece181 100644 --- a/dlib/tokenizer/tokenizer_kernel_c.h +++ b/dlib/tokenizer/tokenizer_kernel_c.h @@ -61,16 +61,15 @@ namespace dlib const std::string& body ) { - using namespace std; // make sure requires clause is not broken - DLIB_CASSERT( head.find_first_of(" \r\t\n0123456789") == string::npos && - body.find_first_of(" \r\t\n") == string::npos , + DLIB_CASSERT( head.find_first_of(" \r\t\n0123456789") == std::string::npos && + body.find_first_of(" \r\t\n") == std::string::npos , "\tvoid tokenizer::set_identifier_token()" << "\n\tyou can't define the IDENTIFIER token this way." << "\n\thead: " << head << "\n\tbody: " << body << "\n\tthis: " << this - ); + ) // call the real function tokenizer::set_identifier_token(head,body);