From: Kefu Chai Date: Wed, 11 Aug 2021 03:56:21 +0000 (+0800) Subject: common: build without "using namespace std" X-Git-Tag: v17.1.0~1121^2~22 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=61219632bd3ee9f97556b396c8755abe666cb14d;p=ceph.git common: build without "using namespace std" * add "std::" prefix in headers * add "using" declarations in .cc files. so we don't rely on "using namespace std" in one or more included headers. Signed-off-by: Kefu Chai --- diff --git a/src/common/Continuation.h b/src/common/Continuation.h index 1c61e7c4eba3c..731830d1901f3 100644 --- a/src/common/Continuation.h +++ b/src/common/Continuation.h @@ -122,19 +122,20 @@ private: std::map callbacks; bool _continue_function(int r, int n) { - set::iterator stage_iter = stages_in_flight.find(n); - ceph_assert(stage_iter != stages_in_flight.end()); + std::set::iterator in_flight_iter = stages_in_flight.find(n); + ceph_assert(in_flight_iter != stages_in_flight.end()); ceph_assert(callbacks.count(n)); stagePtr p = callbacks[n]; - pair::iterator,bool> insert_r = stages_processing.insert(n); + [[maybe_unused]] auto [processing_iter, inserted] = + stages_processing.insert(n); bool done = (this->*p)(r); if (done) reported_done = true; - stages_processing.erase(insert_r.first); - stages_in_flight.erase(stage_iter); + stages_processing.erase(processing_iter); + stages_in_flight.erase(in_flight_iter); return done; } diff --git a/src/common/Journald.cc b/src/common/Journald.cc index 590030e386de2..5207608d1a313 100644 --- a/src/common/Journald.cc +++ b/src/common/Journald.cc @@ -284,7 +284,7 @@ err_close_buffer_fd: } // namespace ceph::logging::detail JournaldLogger::JournaldLogger(const SubsystemMap *s) : - m_entry_encoder(make_unique()), + m_entry_encoder(std::make_unique()), m_subs(s) { client.m_msghdr.msg_iov = m_entry_encoder->iovec(); @@ -300,7 +300,7 @@ int JournaldLogger::log_entry(const Entry& e) } JournaldClusterLogger::JournaldClusterLogger() : - m_log_entry_encoder(make_unique()) + m_log_entry_encoder(std::make_unique()) { client.m_msghdr.msg_iov = m_log_entry_encoder->iovec(); client.m_msghdr.msg_iovlen = m_log_entry_encoder->iovec_len(); diff --git a/src/common/LogEntry.h b/src/common/LogEntry.h index 5da6a3210552c..124a207992070 100644 --- a/src/common/LogEntry.h +++ b/src/common/LogEntry.h @@ -136,7 +136,7 @@ struct LogSummary { // ---- quincy+ ---- LRUSet recent_keys; - std::map> channel_info; // channel -> [begin, end) + std::map> channel_info; // channel -> [begin, end) LogSummary() : version(0) {} diff --git a/src/common/MemoryModel.cc b/src/common/MemoryModel.cc index 14d31cc9a76fa..0f6ab986f5aa6 100644 --- a/src/common/MemoryModel.cc +++ b/src/common/MemoryModel.cc @@ -9,6 +9,8 @@ #define dout_subsys ceph_subsys_ +using namespace std; + MemoryModel::MemoryModel(CephContext *cct_) : cct(cct_) { diff --git a/src/common/cmdparse.cc b/src/common/cmdparse.cc index 7e66869097d81..368e1b726d76d 100644 --- a/src/common/cmdparse.cc +++ b/src/common/cmdparse.cc @@ -26,6 +26,8 @@ using std::stringstream; using std::string_view; using std::vector; +using namespace std::literals; + /** * Given a cmddesc like "foo baz name=bar,type=CephString", * return the prefix "foo baz". diff --git a/src/common/obj_bencher.cc b/src/common/obj_bencher.cc index e94fd7c3e346c..32ecc95861882 100644 --- a/src/common/obj_bencher.cc +++ b/src/common/obj_bencher.cc @@ -21,6 +21,16 @@ #include "common/Clock.h" #include "obj_bencher.h" +using std::ostream; +using std::cerr; +using std::cout; +using std::setfill; +using std::setprecision; +using std::setw; +using std::string; +using std::unique_lock; +using std::unique_ptr; + const std::string BENCH_LASTRUN_METADATA = "benchmark_last_metadata"; const std::string BENCH_PREFIX = "benchmark_data"; const std::string BENCH_OBJ_NAME = BENCH_PREFIX + "_%s_%d_object%d"; diff --git a/src/common/obj_bencher.h b/src/common/obj_bencher.h index f23e2d6354ce9..96589db27c3b7 100644 --- a/src/common/obj_bencher.h +++ b/src/common/obj_bencher.h @@ -64,7 +64,7 @@ typedef std::pair Object; class ObjBencher { bool show_time; Formatter *formatter = NULL; - ostream *outstream = NULL; + std::ostream *outstream = NULL; public: CephContext *cct; protected: @@ -77,7 +77,7 @@ protected: int fetch_bench_metadata(const std::string& metadata_file, uint64_t* op_size, uint64_t* object_size, int* num_ops, int* num_objects, int* prev_pid); - int write_bench(int secondsToRun, int concurrentios, const string& run_name_meta, unsigned max_objects, int prev_pid); + int write_bench(int secondsToRun, int concurrentios, const std::string& run_name_meta, unsigned max_objects, int prev_pid); int seq_read_bench(int secondsToRun, int num_ops, int num_objects, int concurrentios, int writePid, bool no_verify=false); int rand_read_bench(int secondsToRun, int num_ops, int num_objects, int concurrentios, int writePid, bool no_verify=false); @@ -104,8 +104,8 @@ protected: virtual bool get_objects(std::list< std::pair >* objects, int num) = 0; virtual void set_namespace(const std::string&) {} - ostream& out(ostream& os); - ostream& out(ostream& os, utime_t& t); + std::ostream& out(std::ostream& os); + std::ostream& out(std::ostream& os, utime_t& t); public: explicit ObjBencher(CephContext *cct_) : show_time(false), cct(cct_), data() {} virtual ~ObjBencher() {} @@ -121,7 +121,7 @@ public: void set_formatter(Formatter *f) { formatter = f; } - void set_outstream(ostream& os) { + void set_outstream(std::ostream& os) { outstream = &os; } int clean_up_slow(const std::string& prefix, int concurrentios); diff --git a/src/common/openssl_opts_handler.cc b/src/common/openssl_opts_handler.cc index c0164dc7b4137..bb5f27e6b26b1 100644 --- a/src/common/openssl_opts_handler.cc +++ b/src/common/openssl_opts_handler.cc @@ -27,6 +27,7 @@ #include "include/scope_guard.h" using std::string; +using std::ostream; using std::vector; // ----------------------------------------------------------------------------- @@ -55,7 +56,7 @@ string construct_engine_conf(const string &opts) vector confs = get_str_vec(opts, ":"); for (auto conf : confs) { // Construct engine section statement like "engine1=engine1_section" - engine_id = id_prefix + to_string(index++); + engine_id = id_prefix + std::to_string(index++); engine_statement += engine_id + "=" + engine_id + suffix + delimiter; // Adapt to OpenSSL parser diff --git a/src/common/strescape.h b/src/common/strescape.h index 6c9926cdb98c9..9bf27fc3494b0 100644 --- a/src/common/strescape.h +++ b/src/common/strescape.h @@ -15,6 +15,7 @@ #ifndef CEPH_STRESCAPE_H #define CEPH_STRESCAPE_H +#include #include #include @@ -27,7 +28,7 @@ inline std::string binstrprint(std::string_view sv, size_t maxlen=0) s = std::string(sv); } else { maxlen = std::max(8, maxlen); - s = std::string(sv.substr(0, maxlen-3))+"..."s; + s = std::string(sv.substr(0, maxlen-3)) + "..."; } std::replace_if(s.begin(), s.end(), [](char c){ return !(isalnum(c) || ispunct(c)); }, '.'); return s; diff --git a/src/common/win32/dns_resolve.cc b/src/common/win32/dns_resolve.cc index 8a7c80bff0434..6901399a78501 100644 --- a/src/common/win32/dns_resolve.cc +++ b/src/common/win32/dns_resolve.cc @@ -18,6 +18,7 @@ #define dout_subsys ceph_subsys_ +using namespace std; namespace ceph { diff --git a/src/global/global_init.cc b/src/global/global_init.cc index f5902f7f8388b..d74a0f4d2f27a 100644 --- a/src/global/global_init.cc +++ b/src/global/global_init.cc @@ -215,7 +215,7 @@ global_init(const std::map *defaults, g_ceph_context->_log->set_flush_on_exit(); // drop privileges? - ostringstream priv_ss; + std::ostringstream priv_ss; #ifndef _WIN32 // consider --setuser root a no-op, even if we're not root