From 69e9cd612febc65817b309aa328126f29c8257ec Mon Sep 17 00:00:00 2001 From: F Date: Wed, 26 Sep 2018 23:31:56 +0200 Subject: [PATCH] Prefer using std::string that using namespace std and unqualified string (#386) 'using namespace std;' in header files can conflict with custom namespace names. For example 'string' is used without 'std::' qualification. If tz.h is included in a file where string is a namespace, it cannot be compiled anymore. The same happens with date.h if ONLY_C_LOCALE=1. --- include/date/date.h | 15 ++++++--------- include/date/tz.h | 12 +++++------- 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/include/date/date.h b/include/date/date.h index b152ca1..8e1be13 100644 --- a/include/date/date.h +++ b/include/date/date.h @@ -4493,8 +4493,7 @@ inline std::pair weekday_names() { - using namespace std; - static const string nm[] = + static const std::string nm[] = { "Sunday", "Monday", @@ -4511,15 +4510,14 @@ weekday_names() "Fri", "Sat" }; - return make_pair(nm, nm+sizeof(nm)/sizeof(nm[0])); + return std::make_pair(nm, nm+sizeof(nm)/sizeof(nm[0])); } inline std::pair month_names() { - using namespace std; - static const string nm[] = + static const std::string nm[] = { "January", "February", @@ -4546,20 +4544,19 @@ month_names() "Nov", "Dec" }; - return make_pair(nm, nm+sizeof(nm)/sizeof(nm[0])); + return std::make_pair(nm, nm+sizeof(nm)/sizeof(nm[0])); } inline std::pair ampm_names() { - using namespace std; - static const string nm[] = + static const std::string nm[] = { "AM", "PM" }; - return make_pair(nm, nm+sizeof(nm)/sizeof(nm[0])); + return std::make_pair(nm, nm+sizeof(nm)/sizeof(nm[0])); } template diff --git a/include/date/tz.h b/include/date/tz.h index 71c37e6..49e4320 100644 --- a/include/date/tz.h +++ b/include/date/tz.h @@ -1963,10 +1963,9 @@ std::basic_ostream& to_stream(std::basic_ostream& os, const CharT* fmt, const utc_time& t) { - using namespace std; using namespace std::chrono; - using CT = typename common_type::type; - const string abbrev("UTC"); + using CT = typename std::common_type::type; + const std::string abbrev("UTC"); CONSTDATA seconds offset{0}; auto ls = is_leap_second(t); auto tp = sys_time{t.time_since_epoch() - ls.second}; @@ -1992,16 +1991,15 @@ from_stream(std::basic_istream& is, const CharT* fmt, utc_time& tp, std::basic_string* abbrev = nullptr, std::chrono::minutes* offset = nullptr) { - using namespace std; using namespace std::chrono; - using CT = typename common_type::type; + using CT = typename std::common_type::type; minutes offset_local{}; auto offptr = offset ? offset : &offset_local; fields fds{}; fds.has_tod = true; from_stream(is, fmt, fds, abbrev, offptr); if (!fds.ymd.ok()) - is.setstate(ios::failbit); + is.setstate(std::ios::failbit); if (!is.fail()) { bool is_60_sec = fds.tod.seconds() == seconds{60}; @@ -2012,7 +2010,7 @@ from_stream(std::basic_istream& is, const CharT* fmt, tmp += seconds{1}; if (is_60_sec != is_leap_second(tmp).first || !fds.tod.in_conventional_range()) { - is.setstate(ios::failbit); + is.setstate(std::ios::failbit); return is; } tp = time_point_cast(tmp);