]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
common: build without "using namespace std"
authorKefu Chai <kchai@redhat.com>
Wed, 11 Aug 2021 03:56:21 +0000 (11:56 +0800)
committerKefu Chai <kchai@redhat.com>
Fri, 13 Aug 2021 04:23:37 +0000 (12:23 +0800)
* 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 <kchai@redhat.com>
src/common/Continuation.h
src/common/Journald.cc
src/common/LogEntry.h
src/common/MemoryModel.cc
src/common/cmdparse.cc
src/common/obj_bencher.cc
src/common/obj_bencher.h
src/common/openssl_opts_handler.cc
src/common/strescape.h
src/common/win32/dns_resolve.cc
src/global/global_init.cc

index 1c61e7c4eba3c8be9e5d62748d00c5b64279b075..731830d1901f30adedad92dc38d6254bde5fdf00 100644 (file)
@@ -122,19 +122,20 @@ private:
   std::map<int, Continuation::stagePtr> callbacks;
 
   bool _continue_function(int r, int n) {
-    set<int>::iterator stage_iter = stages_in_flight.find(n);
-    ceph_assert(stage_iter != stages_in_flight.end());
+    std::set<int>::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<set<int>::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;
   }
 
index 590030e386de2d0b468ed99aad64e2162f20eaa9..5207608d1a3131739907693e542e9a65ccac6af4 100644 (file)
@@ -284,7 +284,7 @@ err_close_buffer_fd:
 } // namespace ceph::logging::detail
 
 JournaldLogger::JournaldLogger(const SubsystemMap *s) :
-  m_entry_encoder(make_unique<detail::EntryEncoder>()),
+  m_entry_encoder(std::make_unique<detail::EntryEncoder>()),
   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<detail::LogEntryEncoder>())
+  m_log_entry_encoder(std::make_unique<detail::LogEntryEncoder>())
 {
   client.m_msghdr.msg_iov = m_log_entry_encoder->iovec();
   client.m_msghdr.msg_iovlen = m_log_entry_encoder->iovec_len();
index 5da6a3210552c148301ef3c8e9f9e44c7beb11d4..124a20799207046d835326eb46298fe031016dd7 100644 (file)
@@ -136,7 +136,7 @@ struct LogSummary {
 
   // ---- quincy+ ----
   LRUSet<LogEntryKey> recent_keys;
-  std::map<std::string, pair<uint64_t,uint64_t>> channel_info; // channel -> [begin, end)
+  std::map<std::string, std::pair<uint64_t,uint64_t>> channel_info; // channel -> [begin, end)
 
   LogSummary() : version(0) {}
 
index 14d31cc9a76faf062309b669d85cc48ef793b8dd..0f6ab986f5aa67212aa086ef1458fbfae957d01e 100644 (file)
@@ -9,6 +9,8 @@
 
 #define dout_subsys ceph_subsys_
 
+using namespace std;
+
 MemoryModel::MemoryModel(CephContext *cct_)
   : cct(cct_)
 {
index 7e66869097d81dd0b58bc65ff9a6c222a12697d1..368e1b726d76db615a879c0be0cdce5972009d15 100644 (file)
@@ -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".
index e94fd7c3e346c0872e3d70af1292d00ec02ebec5..32ecc9586188261a388acdd5e46a49787f8840bf 100644 (file)
 #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";
index f23e2d6354ce973458fd294f62b5202133ccd859..96589db27c3b70118376c877ee3b9c8589476d30 100644 (file)
@@ -64,7 +64,7 @@ typedef std::pair<std::string, std::string> 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<std::string, std::string> >* 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);
index c0164dc7b4137ccb3324c4b0d5cee4f4d4e60c54..bb5f27e6b26b1106b6f2070fe6ef7bd34d213573 100644 (file)
@@ -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<string> 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
index 6c9926cdb98c9415b3b7e22b184affc054559602..9bf27fc3494b0aa5dab7fed09aeeff7f2e0f6bd2 100644 (file)
@@ -15,6 +15,7 @@
 #ifndef CEPH_STRESCAPE_H
 #define CEPH_STRESCAPE_H
 
+#include <algorithm>
 #include <ostream>
 #include <string_view>
 
@@ -27,7 +28,7 @@ inline std::string binstrprint(std::string_view sv, size_t maxlen=0)
     s = std::string(sv);
   } else {
     maxlen = std::max<size_t>(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;
index 8a7c80bff04342f0bf67752ed3abf05ff3d3feac..6901399a7850133020cd35a3fd2798bb46c0d68f 100644 (file)
@@ -18,6 +18,7 @@
 
 #define dout_subsys ceph_subsys_
 
+using namespace std;
 
 namespace ceph {
 
index f5902f7f8388b1628cf4da89a3c7613e8841484b..d74a0f4d2f27a646be7a51858d751cdae75f0e31 100644 (file)
@@ -215,7 +215,7 @@ global_init(const std::map<std::string,std::string> *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