From 524322f78775dc14c61d33cbdb719b8330c2ad5c Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 27 Jun 2018 14:55:27 +0200 Subject: Reimplement optional not to require default-constructible value types --- libbutl/timestamp.cxx | 86 +++++++++++++++++++++++++++------------------------ 1 file changed, 46 insertions(+), 40 deletions(-) (limited to 'libbutl/timestamp.cxx') diff --git a/libbutl/timestamp.cxx b/libbutl/timestamp.cxx index 437ea52..b0bb9ad 100644 --- a/libbutl/timestamp.cxx +++ b/libbutl/timestamp.cxx @@ -89,33 +89,36 @@ using namespace std; // of the std::tm argument. // #ifdef __GLIBCXX__ -namespace details +namespace butl { - struct put_time_data + namespace details { - const std::tm* tm; - const char* fmt; - }; + struct put_time_data + { + const std::tm* tm; + const char* fmt; + }; - inline put_time_data - put_time (const std::tm* tm, const char* fmt) - { - return put_time_data {tm, fmt}; - } + inline put_time_data + put_time (const std::tm* tm, const char* fmt) + { + return put_time_data {tm, fmt}; + } - inline ostream& - operator<< (ostream& os, const put_time_data& d) - { - char buf[256]; - if (strftime (buf, sizeof (buf), d.fmt, d.tm) != 0) - os << buf; - else - os.setstate (ostream::badbit); - return os; + inline ostream& + operator<< (ostream& os, const put_time_data& d) + { + char buf[256]; + if (strftime (buf, sizeof (buf), d.fmt, d.tm) != 0) + os << buf; + else + os.setstate (ostream::badbit); + return os; + } } } -using namespace details; +using namespace butl::details; #endif // Thread-safe implementations of gmtime() and localtime(). @@ -133,36 +136,39 @@ using namespace details; // one common tm structure per thread for the conversion", which mean that they // are thread-safe. // -namespace details +namespace butl { - static tm* - gmtime (const time_t* t, tm* r) + namespace details { + static tm* + gmtime (const time_t* t, tm* r) + { #ifdef _WIN32 - const tm* gt (::gmtime (t)); - if (gt == nullptr) - return nullptr; + const tm* gt (::gmtime (t)); + if (gt == nullptr) + return nullptr; - *r = *gt; - return r; + *r = *gt; + return r; #else - return gmtime_r (t, r); + return gmtime_r (t, r); #endif - } + } - static tm* - localtime (const time_t* t, tm* r) - { + static tm* + localtime (const time_t* t, tm* r) + { #ifdef _WIN32 - const tm* lt (::localtime (t)); - if (lt == nullptr) - return nullptr; + const tm* lt (::localtime (t)); + if (lt == nullptr) + return nullptr; - *r = *lt; - return r; + *r = *lt; + return r; #else - return localtime_r (t, r); + return localtime_r (t, r); #endif + } } } @@ -219,7 +225,7 @@ timegm (tm* ctm) // offset is effectively the time difference between MSK and GMT time zones. // tm gtm; - if (details::gmtime (&t, >m) == nullptr) + if (butl::details::gmtime (&t, >m) == nullptr) return e; // gmtime() being called for the timepoint t returns 6 AM. So now we have -- cgit v1.1