From 806c29fddceb46e9e8a15b8239dcf69a753d1f46 Mon Sep 17 00:00:00 2001 From: Howard Hinnant Date: Sat, 15 Oct 2016 17:31:08 -0400 Subject: [PATCH] Lots of minor changes motivated by reviews of the draft proposal --- date.h | 16 ++++---- tz.cpp | 27 -------------- tz.h | 116 +++++++++++++++++++++++++++++++++++---------------------- 3 files changed, 80 insertions(+), 79 deletions(-) diff --git a/date.h b/date.h index f68012f..8b79b07 100644 --- a/date.h +++ b/date.h @@ -3873,7 +3873,7 @@ template > -make_time(std::chrono::duration d) NOEXCEPT +make_time(const std::chrono::duration& d) { return time_of_day>(d); } @@ -3881,7 +3881,7 @@ make_time(std::chrono::duration d) NOEXCEPT CONSTCD11 inline time_of_day -make_time(std::chrono::hours h, unsigned md) NOEXCEPT +make_time(const std::chrono::hours& h, unsigned md) { return time_of_day(h, md); } @@ -3889,7 +3889,8 @@ make_time(std::chrono::hours h, unsigned md) NOEXCEPT CONSTCD11 inline time_of_day -make_time(std::chrono::hours h, std::chrono::minutes m, unsigned md) NOEXCEPT +make_time(const std::chrono::hours& h, const std::chrono::minutes& m, + unsigned md) { return time_of_day(h, m, md); } @@ -3897,8 +3898,8 @@ make_time(std::chrono::hours h, std::chrono::minutes m, unsigned md) NOEXCEPT CONSTCD11 inline time_of_day -make_time(std::chrono::hours h, std::chrono::minutes m, std::chrono::seconds s, - unsigned md) NOEXCEPT +make_time(const std::chrono::hours& h, const std::chrono::minutes& m, + const std::chrono::seconds& s, unsigned md) { return time_of_day(h, m, s, md); } @@ -3909,8 +3910,9 @@ template > -make_time(std::chrono::hours h, std::chrono::minutes m, std::chrono::seconds s, - std::chrono::duration sub_s, unsigned md) NOEXCEPT +make_time(const std::chrono::hours& h, const std::chrono::minutes& m, + const std::chrono::seconds& s, const std::chrono::duration& sub_s, + unsigned md) { return time_of_day>(h, m, s, sub_s, md); } diff --git a/tz.cpp b/tz.cpp index 50220bd..e3c4da7 100644 --- a/tz.cpp +++ b/tz.cpp @@ -2977,33 +2977,6 @@ operator<<(std::ostream& os, const TZ_DB& db) // ----------------------- -std::ostream& -operator<<(std::ostream& os, const sys_info& r) -{ - os << r.begin << '\n'; - os << r.end << '\n'; - os << make_time(r.offset) << "\n"; - os << make_time(r.save) << "\n"; - os << r.abbrev << '\n'; - return os; -} - -std::ostream& -operator<<(std::ostream& os, const local_info& r) -{ - if (r.result == local_info::nonexistent) - os << "nonexistent between\n"; - else if (r.result == local_info::ambiguous) - os << "ambiguous between\n"; - os << r.first; - if (r.result != local_info::unique) - { - os << "and\n"; - os << r.second; - } - return os; -} - #ifdef _WIN32 const time_zone* diff --git a/tz.h b/tz.h index ccb639f..4796fcb 100644 --- a/tz.h +++ b/tz.h @@ -212,7 +212,17 @@ struct sys_info std::string abbrev; }; -std::ostream& operator<<(std::ostream& os, const sys_info& r); +template +std::basic_ostream& +operator<<(std::basic_ostream& os, const sys_info& r) +{ + os << r.begin << '\n'; + os << r.end << '\n'; + os << make_time(r.offset) << "\n"; + os << make_time(r.save) << "\n"; + os << r.abbrev << '\n'; + return os; +} struct local_info { @@ -221,7 +231,22 @@ struct local_info sys_info second; }; -std::ostream& operator<<(std::ostream& os, const local_info& r); +template +std::basic_ostream& +operator<<(std::basic_ostream& os, const local_info& r) +{ + if (r.result == local_info::nonexistent) + os << "nonexistent between\n"; + else if (r.result == local_info::ambiguous) + os << "ambiguous between\n"; + os << r.first; + if (r.result != local_info::unique) + { + os << "and\n"; + os << r.second; + } + return os; +} class time_zone; @@ -232,7 +257,7 @@ class zoned_time sys_time tp_; public: - zoned_time(sys_time st); + zoned_time(const sys_time& st); explicit zoned_time(const time_zone* z); explicit zoned_time(const std::string& name); @@ -244,10 +269,10 @@ public: >::type> zoned_time(const zoned_time& zt) NOEXCEPT; - zoned_time(const time_zone* z, local_time tp); - zoned_time(const std::string& name, local_time tp); - zoned_time(const time_zone* z, local_time tp, choose c); - zoned_time(const std::string& name, local_time tp, choose c); + zoned_time(const time_zone* z, const local_time& tp); + zoned_time(const std::string& name, const local_time& tp); + zoned_time(const time_zone* z, const local_time& tp, choose c); + zoned_time(const std::string& name, const local_time& tp, choose c); zoned_time(const time_zone* z, const zoned_time& zt); zoned_time(const std::string& name, const zoned_time& zt); @@ -257,8 +282,8 @@ public: zoned_time(const time_zone* z, const sys_time& st); zoned_time(const std::string& name, const sys_time& st); - zoned_time& operator=(sys_time st); - zoned_time& operator=(local_time ut); + zoned_time& operator=(const sys_time& st); + zoned_time& operator=(const local_time& ut); operator sys_time() const; explicit operator local_time() const; @@ -328,7 +353,7 @@ public: explicit time_zone(const std::string& s, detail::undocumented); - const std::string& name() const; + const std::string& name() const NOEXCEPT; template sys_info get_info(sys_time st) const; template local_info get_info(local_time tp) const; @@ -345,8 +370,8 @@ public: local_time::type> to_local(sys_time tp) const; - friend bool operator==(const time_zone& x, const time_zone& y); - friend bool operator< (const time_zone& x, const time_zone& y); + friend bool operator==(const time_zone& x, const time_zone& y) NOEXCEPT; + friend bool operator< (const time_zone& x, const time_zone& y) NOEXCEPT; friend std::ostream& operator<<(std::ostream& os, const time_zone& z); void add(const std::string& s); @@ -394,7 +419,7 @@ time_zone::operator=(time_zone&& src) inline const std::string& -time_zone::name() const +time_zone::name() const NOEXCEPT { return name_; } @@ -443,13 +468,13 @@ time_zone::to_local(sys_time tp) const return LT{(tp + i.offset).time_since_epoch()}; } -inline bool operator==(const time_zone& x, const time_zone& y) {return x.name_ == y.name_;} -inline bool operator< (const time_zone& x, const time_zone& y) {return x.name_ < y.name_;} +inline bool operator==(const time_zone& x, const time_zone& y) NOEXCEPT {return x.name_ == y.name_;} +inline bool operator< (const time_zone& x, const time_zone& y) NOEXCEPT {return x.name_ < y.name_;} -inline bool operator!=(const time_zone& x, const time_zone& y) {return !(x == y);} -inline bool operator> (const time_zone& x, const time_zone& y) {return y < x;} -inline bool operator<=(const time_zone& x, const time_zone& y) {return !(y < x);} -inline bool operator>=(const time_zone& x, const time_zone& y) {return !(x < y);} +inline bool operator!=(const time_zone& x, const time_zone& y) NOEXCEPT {return !(x == y);} +inline bool operator> (const time_zone& x, const time_zone& y) NOEXCEPT {return y < x;} +inline bool operator<=(const time_zone& x, const time_zone& y) NOEXCEPT {return !(y < x);} +inline bool operator>=(const time_zone& x, const time_zone& y) NOEXCEPT {return !(x < y);} template sys_time::type> @@ -750,7 +775,7 @@ const time_zone* current_zone(); template inline -zoned_time::zoned_time(sys_time st) +zoned_time::zoned_time(const sys_time& st) : zone_(locate_zone("UTC")) , tp_(st) {} @@ -769,27 +794,28 @@ zoned_time::zoned_time(const std::string& name) template inline -zoned_time::zoned_time(const time_zone* z, local_time t) +zoned_time::zoned_time(const time_zone* z, const local_time& t) : zone_(z) , tp_(z->to_sys(t)) {} template inline -zoned_time::zoned_time(const std::string& name, local_time t) +zoned_time::zoned_time(const std::string& name, const local_time& t) : zoned_time(locate_zone(name), t) {} template inline -zoned_time::zoned_time(const time_zone* z, local_time t, choose c) +zoned_time::zoned_time(const time_zone* z, const local_time& t, + choose c) : zone_(z) , tp_(z->to_sys(t, c)) {} template inline -zoned_time::zoned_time(const std::string& name, local_time t, +zoned_time::zoned_time(const std::string& name, const local_time& t, choose c) : zoned_time(locate_zone(name), t, c) {} @@ -845,7 +871,7 @@ zoned_time::zoned_time(const std::string& name, const sys_time inline zoned_time& -zoned_time::operator=(sys_time st) +zoned_time::operator=(const sys_time& st) { tp_ = st; return *this; @@ -854,7 +880,7 @@ zoned_time::operator=(sys_time st) template inline zoned_time& -zoned_time::operator=(local_time ut) +zoned_time::operator=(const local_time& ut) { tp_ = zone_->to_sys(ut); return *this; @@ -911,7 +937,7 @@ zoned_time::get_info() const template inline zoned_time::type> -make_zoned(sys_time tp) +make_zoned(const sys_time& tp) { return {tp}; } @@ -919,7 +945,7 @@ make_zoned(sys_time tp) template inline zoned_time::type> -make_zoned(const time_zone* zone, local_time tp) +make_zoned(const time_zone* zone, const local_time& tp) { return {zone, tp}; } @@ -927,7 +953,7 @@ make_zoned(const time_zone* zone, local_time tp) template inline zoned_time::type> -make_zoned(const std::string& name, local_time tp) +make_zoned(const std::string& name, const local_time& tp) { return {name, tp}; } @@ -935,7 +961,7 @@ make_zoned(const std::string& name, local_time tp) template inline zoned_time::type> -make_zoned(const time_zone* zone, local_time tp, choose c) +make_zoned(const time_zone* zone, const local_time& tp, choose c) { return {zone, tp, c}; } @@ -943,7 +969,7 @@ make_zoned(const time_zone* zone, local_time tp, choose c) template inline zoned_time::type> -make_zoned(const std::string& name, local_time tp, choose c) +make_zoned(const std::string& name, const local_time& tp, choose c) { return {name, tp, c}; } @@ -1015,7 +1041,7 @@ public: using time_point = std::chrono::time_point; static CONSTDATA bool is_steady = false; - static time_point now() NOEXCEPT; + static time_point now(); }; template @@ -1026,7 +1052,7 @@ using utc_seconds = utc_time; template inline utc_time::type> -to_utc_time(sys_time st) +to_utc_time(const sys_time& st) { using namespace std::chrono; using duration = typename std::common_type::type; @@ -1038,7 +1064,7 @@ to_utc_time(sys_time st) template inline sys_time::type> -to_sys_time(utc_time ut) +to_sys_time(const utc_time& ut) { using namespace std::chrono; using duration = typename std::common_type::type; @@ -1061,7 +1087,7 @@ to_sys_time(utc_time ut) inline utc_clock::time_point -utc_clock::now() NOEXCEPT +utc_clock::now() { using namespace std::chrono; return to_utc_time(system_clock::now()); @@ -1117,7 +1143,7 @@ using tai_seconds = tai_time; template inline utc_time::type> -to_utc_time(tai_time t) NOEXCEPT +to_utc_time(const tai_time& t) NOEXCEPT { using namespace std::chrono; using duration = typename std::common_type::type; @@ -1128,7 +1154,7 @@ to_utc_time(tai_time t) NOEXCEPT template inline tai_time::type> -to_tai_time(utc_time t) NOEXCEPT +to_tai_time(const utc_time& t) NOEXCEPT { using namespace std::chrono; using duration = typename std::common_type::type; @@ -1139,7 +1165,7 @@ to_tai_time(utc_time t) NOEXCEPT template inline tai_time::type> -to_tai_time(sys_time t) +to_tai_time(const sys_time& t) { return to_tai_time(to_utc_time(t)); } @@ -1185,7 +1211,7 @@ using gps_seconds = gps_time; template inline utc_time::type> -to_utc_time(gps_time t) NOEXCEPT +to_utc_time(const gps_time& t) NOEXCEPT { using namespace std::chrono; using duration = typename std::common_type::type; @@ -1196,7 +1222,7 @@ to_utc_time(gps_time t) NOEXCEPT template inline gps_time::type> -to_gps_time(utc_time t) +to_gps_time(const utc_time& t) { using namespace std::chrono; using duration = typename std::common_type::type; @@ -1207,7 +1233,7 @@ to_gps_time(utc_time t) template inline gps_time::type> -to_gps_time(sys_time t) +to_gps_time(const sys_time& t) { return to_gps_time(to_utc_time(t)); } @@ -1234,7 +1260,7 @@ operator<<(std::basic_ostream& os, const gps_time& t) template inline sys_time::type> -to_sys_time(tai_time t) +to_sys_time(const tai_time& t) { return to_sys_time(to_utc_time(t)); } @@ -1242,7 +1268,7 @@ to_sys_time(tai_time t) template inline sys_time::type> -to_sys_time(gps_time t) +to_sys_time(const gps_time& t) { return to_sys_time(to_utc_time(t)); } @@ -1250,7 +1276,7 @@ to_sys_time(gps_time t) template inline tai_time::type> -to_tai_time(gps_time t) NOEXCEPT +to_tai_time(const gps_time& t) NOEXCEPT { using namespace std::chrono; using duration = typename std::common_type::type; @@ -1261,7 +1287,7 @@ to_tai_time(gps_time t) NOEXCEPT template inline gps_time::type> -to_gps_time(tai_time t) NOEXCEPT +to_gps_time(const tai_time& t) NOEXCEPT { using namespace std::chrono; using duration = typename std::common_type::type;