From: Kefu Chai Date: Thu, 23 Aug 2018 11:59:55 +0000 (+0800) Subject: mon/MonMap: add more const'ness to its methods X-Git-Tag: v14.0.1~494^2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=157e29cb0eacf2fd0cfe012a96c9806e70de9616;p=ceph.git mon/MonMap: add more const'ness to its methods Signed-off-by: Kefu Chai --- diff --git a/src/mon/MonMap.h b/src/mon/MonMap.h index d7e902fcd37e8..5e91a7d860a39 100644 --- a/src/mon/MonMap.h +++ b/src/mon/MonMap.h @@ -268,13 +268,15 @@ public: return p->second; } - int get_rank(const string& n) { - for (unsigned i = 0; i < ranks.size(); i++) - if (ranks[i] == n) - return i; - return -1; + int get_rank(const string& n) const { + if (auto found = std::find(ranks.begin(), ranks.end(), n); + found != ranks.end()) { + return std::distance(ranks.begin(), found); + } else { + return -1; + } } - int get_rank(const entity_addr_t& a) { + int get_rank(const entity_addr_t& a) const { string n = get_name(a); if (n.empty()) return -1;