From: Kefu Chai Date: Thu, 7 Jan 2021 07:17:45 +0000 (+0800) Subject: common/ceph_time: move operator<<(ostream&, timespan&) into std namespace X-Git-Tag: v17.0.0~102^2~3 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=75aafcba888a5753d2a4a8378637b4bb9fad5dd0;p=ceph.git common/ceph_time: move operator<<(ostream&, timespan&) into std namespace otherwise compiler is not able to find it as the "timespan" here is actually a class defined in std namespace, even it has an alias defined in ceph namespace like: typedef std::chrono::duration timespan; but this does not make it a member of "ceph" namespace. for more details on the lookup rules, see https://en.cppreference.com/w/cpp/language/adl Signed-off-by: Kefu Chai --- diff --git a/src/common/ceph_time.cc b/src/common/ceph_time.cc index aa72f65cc7023..9b85fc88224d3 100644 --- a/src/common/ceph_time.cc +++ b/src/common/ceph_time.cc @@ -106,13 +106,6 @@ std::ostream& operator<<(std::ostream& m, << 's'; } -std::ostream& operator<<(std::ostream& m, const timespan& t) { - static_assert(std::is_unsigned_v); - using seconds_t = std::chrono::duration; - fmt::print(m, "{:.9}", std::chrono::duration_cast(t)); - return m; -} - template::type*> std::ostream& operator<<(std::ostream& m, @@ -327,3 +320,12 @@ std::chrono::seconds parse_timespan(const std::string& s) } } + +namespace std { +ostream& operator<<(ostream& m, const ::ceph::timespan& t) { + static_assert(is_unsigned_v<::ceph::timespan::rep>); + using seconds_t = chrono::duration; + ::fmt::print(m, "{:.9}", chrono::duration_cast(t)); + return m; +} +} // namespace std diff --git a/src/common/ceph_time.h b/src/common/ceph_time.h index 005556cb7f79a..663d05f8feb2b 100644 --- a/src/common/ceph_time.h +++ b/src/common/ceph_time.h @@ -428,7 +428,6 @@ inline std::optional maybe_timespan(const double d) { return d ? std::make_optional(make_timespan(d)) : std::nullopt; } -std::ostream& operator<<(std::ostream& m, const timespan& t); template::type* = nullptr> std::ostream& operator<<(std::ostream& m, @@ -519,4 +518,8 @@ static Rep to_microseconds(T t) { } // namespace ceph +namespace std { +ostream& operator<<(ostream& m, const ::ceph::timespan& t); +} + #endif // COMMON_CEPH_TIME_H