Added Alloc argument to template parameters to support custom allocators in from_stream

This commit is contained in:
gaspardpetit
2017-03-08 13:03:22 -05:00
committed by Howard Hinnant
parent a811a20748
commit f4292e6aca
2 changed files with 62 additions and 59 deletions

107
date.h
View File

@@ -3395,10 +3395,10 @@ to_stream(std::basic_ostream<CharT, Traits>& os, const CharT* fmt,
const fields<Duration>& fds, const std::string* abbrev = nullptr, const fields<Duration>& fds, const std::string* abbrev = nullptr,
const std::chrono::seconds* offset_sec = nullptr); const std::chrono::seconds* offset_sec = nullptr);
template <class CharT, class Traits, class Duration> template <class CharT, class Traits, class Duration, class Alloc>
void void
from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt, from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt,
fields<Duration>& fds, std::basic_string<CharT, Traits>* abbrev = nullptr, fields<Duration>& fds, std::basic_string<CharT, Traits, Alloc>* abbrev = nullptr,
std::chrono::minutes* offset = nullptr); std::chrono::minutes* offset = nullptr);
// time_of_day // time_of_day
@@ -3914,12 +3914,12 @@ public:
const fields<Duration>& fds, const std::string* abbrev, const fields<Duration>& fds, const std::string* abbrev,
const std::chrono::seconds* offset_sec); const std::chrono::seconds* offset_sec);
template <class CharT, class Traits, class Duration> template <class CharT, class Traits, class Duration, class Alloc>
friend friend
void void
date::from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt, date::from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt,
fields<Duration>& fds, fields<Duration>& fds,
std::basic_string<CharT, Traits>* abbrev, std::chrono::minutes* offset); std::basic_string<CharT, Traits, Alloc>* abbrev, std::chrono::minutes* offset);
}; };
template <class Rep, class Period> template <class Rep, class Period>
@@ -4018,12 +4018,12 @@ public:
const fields<Duration>& fds, const std::string* abbrev, const fields<Duration>& fds, const std::string* abbrev,
const std::chrono::seconds* offset_sec); const std::chrono::seconds* offset_sec);
template <class CharT, class Traits, class Duration> template <class CharT, class Traits, class Duration, class Alloc>
friend friend
void void
date::from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt, date::from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt,
fields<Duration>& fds, fields<Duration>& fds,
std::basic_string<CharT, Traits>* abbrev, std::chrono::minutes* offset); std::basic_string<CharT, Traits, Alloc>* abbrev, std::chrono::minutes* offset);
}; };
} // namespace detail } // namespace detail
@@ -5038,12 +5038,12 @@ format(const CharT* fmt, const Streamable& tp)
return os.str(); return os.str();
} }
template <class CharT, class Traits, class Streamable> template <class CharT, class Traits, class Alloc, class Streamable>
auto auto
format(const std::locale& loc, const std::basic_string<CharT, Traits>& fmt, format(const std::locale& loc, const std::basic_string<CharT, Traits, Alloc>& fmt,
const Streamable& tp) const Streamable& tp)
-> decltype(to_stream(std::declval<std::basic_ostream<CharT, Traits>&>(), fmt, tp), -> decltype(to_stream(std::declval<std::basic_ostream<CharT, Traits>&>(), fmt, tp),
std::basic_string<CharT, Traits>{}) std::basic_string<CharT, Traits, Alloc>{})
{ {
std::basic_ostringstream<CharT, Traits> os; std::basic_ostringstream<CharT, Traits> os;
os.imbue(loc); os.imbue(loc);
@@ -5051,11 +5051,11 @@ format(const std::locale& loc, const std::basic_string<CharT, Traits>& fmt,
return os.str(); return os.str();
} }
template <class CharT, class Traits, class Streamable> template <class CharT, class Traits, class Alloc, class Streamable>
auto auto
format(const std::basic_string<CharT, Traits>& fmt, const Streamable& tp) format(const std::basic_string<CharT, Traits, Alloc>& fmt, const Streamable& tp)
-> decltype(to_stream(std::declval<std::basic_ostream<CharT, Traits>&>(), fmt, tp), -> decltype(to_stream(std::declval<std::basic_ostream<CharT, Traits>&>(), fmt, tp),
std::basic_string<CharT, Traits>{}) std::basic_string<CharT, Traits, Alloc>{})
{ {
std::basic_ostringstream<CharT, Traits> os; std::basic_ostringstream<CharT, Traits> os;
to_stream(os, fmt.c_str(), tp); to_stream(os, fmt.c_str(), tp);
@@ -5297,10 +5297,10 @@ read(std::basic_istream<CharT, Traits>& is, rld a0, Args&& ...args)
} // namespace detail; } // namespace detail;
template <class CharT, class Traits, class Duration> template <class CharT, class Traits, class Duration, class Alloc = std::allocator<CharT>>
void void
from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt, from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt,
fields<Duration>& fds, std::basic_string<CharT, Traits>* abbrev, fields<Duration>& fds, std::basic_string<CharT, Traits, Alloc>* abbrev,
std::chrono::minutes* offset) std::chrono::minutes* offset)
{ {
using namespace std; using namespace std;
@@ -5310,7 +5310,7 @@ from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt,
{ {
auto& f = use_facet<time_get<CharT>>(is.getloc()); auto& f = use_facet<time_get<CharT>>(is.getloc());
std::tm tm{}; std::tm tm{};
std::basic_string<CharT, Traits> temp_abbrev; std::basic_string<CharT, Traits, Alloc> temp_abbrev;
minutes temp_offset{}; minutes temp_offset{};
const CharT* command = nullptr; const CharT* command = nullptr;
auto modified = CharT{}; auto modified = CharT{};
@@ -6199,10 +6199,10 @@ broken:
is.setstate(ios_base::failbit); is.setstate(ios_base::failbit);
} }
template <class CharT, class Traits> template <class CharT, class Traits, class Alloc = std::allocator<CharT>>
void void
from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt, from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt,
year_month_day& ymd, std::basic_string<CharT, Traits>* abbrev = nullptr, year_month_day& ymd, std::basic_string<CharT, Traits, Alloc>* abbrev = nullptr,
std::chrono::minutes* offset = nullptr) std::chrono::minutes* offset = nullptr)
{ {
using namespace std; using namespace std;
@@ -6216,10 +6216,10 @@ from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt,
ymd = fds.ymd; ymd = fds.ymd;
} }
template <class Duration, class CharT, class Traits> template <class Duration, class CharT, class Traits, class Alloc = std::allocator<CharT>>
void void
from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt, from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt,
sys_time<Duration>& tp, std::basic_string<CharT, Traits>* abbrev = nullptr, sys_time<Duration>& tp, std::basic_string<CharT, Traits, Alloc>* abbrev = nullptr,
std::chrono::minutes* offset = nullptr) std::chrono::minutes* offset = nullptr)
{ {
using namespace std; using namespace std;
@@ -6235,10 +6235,10 @@ from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt,
tp = sys_days(fds.ymd) + duration_cast<Duration>(fds.tod.to_duration() - *offptr); tp = sys_days(fds.ymd) + duration_cast<Duration>(fds.tod.to_duration() - *offptr);
} }
template <class Duration, class CharT, class Traits> template <class Duration, class CharT, class Traits, class Alloc = std::allocator<CharT>>
void void
from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt, from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt,
local_time<Duration>& tp, std::basic_string<CharT, Traits>* abbrev = nullptr, local_time<Duration>& tp, std::basic_string<CharT, Traits, Alloc>* abbrev = nullptr,
std::chrono::minutes* offset = nullptr) std::chrono::minutes* offset = nullptr)
{ {
using namespace std; using namespace std;
@@ -6252,11 +6252,11 @@ from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt,
tp = local_days(fds.ymd) + duration_cast<Duration>(fds.tod.to_duration()); tp = local_days(fds.ymd) + duration_cast<Duration>(fds.tod.to_duration());
} }
template <class Rep, class Period, class CharT, class Traits> template <class Rep, class Period, class CharT, class Traits, class Alloc = std::allocator<CharT>>
void void
from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt, from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt,
std::chrono::duration<Rep, Period>& d, std::chrono::duration<Rep, Period>& d,
std::basic_string<CharT, Traits>* abbrev = nullptr, std::basic_string<CharT, Traits, Alloc>* abbrev = nullptr,
std::chrono::minutes* offset = nullptr) std::chrono::minutes* offset = nullptr)
{ {
using namespace std; using namespace std;
@@ -6269,18 +6269,19 @@ from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt,
d = duration_cast<Duration>(fds.tod.to_duration()); d = duration_cast<Duration>(fds.tod.to_duration());
} }
template <class Parsable, class CharT, class Traits = std::char_traits<CharT>> template <class Parsable, class CharT, class Traits = std::char_traits<CharT>,
class Alloc = std::allocator<CharT>>
struct parse_manip struct parse_manip
{ {
const std::basic_string<CharT, Traits> format_; const std::basic_string<CharT, Traits, Alloc> format_;
Parsable& tp_; Parsable& tp_;
std::basic_string<CharT, Traits>* abbrev_; std::basic_string<CharT, Traits, Alloc>* abbrev_;
std::chrono::minutes* offset_; std::chrono::minutes* offset_;
public: public:
parse_manip(std::basic_string<CharT, Traits> format, parse_manip(std::basic_string<CharT, Traits, Alloc> format, Parsable& tp,
Parsable& tp, std::basic_string<CharT, Traits>* abbrev = nullptr, std::basic_string<CharT, Traits, Alloc>* abbrev = nullptr,
std::chrono::minutes* offset = nullptr) std::chrono::minutes* offset = nullptr)
: format_(std::move(format)) : format_(std::move(format))
, tp_(tp) , tp_(tp)
, abbrev_(abbrev) , abbrev_(abbrev)
@@ -6289,58 +6290,58 @@ public:
}; };
template <class Parsable, class CharT, class Traits> template <class Parsable, class CharT, class Traits, class Alloc>
std::basic_istream<CharT, Traits>& std::basic_istream<CharT, Traits>&
operator>>(std::basic_istream<CharT, Traits>& is, operator>>(std::basic_istream<CharT, Traits>& is,
const parse_manip<Parsable, CharT, Traits>& x) const parse_manip<Parsable, CharT, Traits, Alloc>& x)
{ {
from_stream(is, x.format_.c_str(), x.tp_, x.abbrev_, x.offset_); from_stream(is, x.format_.c_str(), x.tp_, x.abbrev_, x.offset_);
return is; return is;
} }
template <class Parsable, class CharT, class Traits> template <class Parsable, class CharT, class Traits, class Alloc>
inline inline
auto auto
parse(const std::basic_string<CharT, Traits>& format, Parsable& tp) parse(const std::basic_string<CharT, Traits, Alloc>& format, Parsable& tp)
-> decltype(from_stream(std::declval<std::basic_istream<CharT, Traits>&>(), -> decltype(from_stream(std::declval<std::basic_istream<CharT, Traits>&>(),
format.c_str(), tp), format.c_str(), tp),
parse_manip<Parsable, CharT, Traits>{format, tp}) parse_manip<Parsable, CharT, Traits, Alloc>{format, tp})
{ {
return {format, tp}; return {format, tp};
} }
template <class Parsable, class CharT, class Traits> template <class Parsable, class CharT, class Traits, class Alloc>
inline inline
auto auto
parse(const std::basic_string<CharT, Traits>& format, Parsable& tp, parse(const std::basic_string<CharT, Traits, Alloc>& format, Parsable& tp,
std::basic_string<CharT, Traits>& abbrev) std::basic_string<CharT, Traits, Alloc>& abbrev)
-> decltype(from_stream(std::declval<std::basic_istream<CharT, Traits>&>(), -> decltype(from_stream(std::declval<std::basic_istream<CharT, Traits>&>(),
format.c_str(), tp, &abbrev), format.c_str(), tp, &abbrev),
parse_manip<Parsable, CharT, Traits>{format, tp, &abbrev}) parse_manip<Parsable, CharT, Traits, Alloc>{format, tp, &abbrev})
{ {
return {format, tp, &abbrev}; return {format, tp, &abbrev};
} }
template <class Parsable, class CharT, class Traits> template <class Parsable, class CharT, class Traits, class Alloc>
inline inline
auto auto
parse(const std::basic_string<CharT, Traits>& format, Parsable& tp, parse(const std::basic_string<CharT, Traits, Alloc>& format, Parsable& tp,
std::chrono::minutes& offset) std::chrono::minutes& offset)
-> decltype(from_stream(std::declval<std::basic_istream<CharT, Traits>&>(), -> decltype(from_stream(std::declval<std::basic_istream<CharT, Traits>&>(),
format.c_str(), tp, nullptr, &offset), format.c_str(), tp, nullptr, &offset),
parse_manip<Parsable, CharT, Traits>{format, tp, nullptr, &offset}) parse_manip<Parsable, CharT, Traits, Alloc>{format, tp, nullptr, &offset})
{ {
return {format, tp, nullptr, &offset}; return {format, tp, nullptr, &offset};
} }
template <class Parsable, class CharT, class Traits> template <class Parsable, class CharT, class Traits, class Alloc>
inline inline
auto auto
parse(const std::basic_string<CharT, Traits>& format, Parsable& tp, parse(const std::basic_string<CharT, Traits, Alloc>& format, Parsable& tp,
std::basic_string<CharT, Traits>& abbrev, std::chrono::minutes& offset) std::basic_string<CharT, Traits, Alloc>& abbrev, std::chrono::minutes& offset)
-> decltype(from_stream(std::declval<std::basic_istream<CharT, Traits>&>(), -> decltype(from_stream(std::declval<std::basic_istream<CharT, Traits>&>(),
format.c_str(), tp, &abbrev, &offset), format.c_str(), tp, &abbrev, &offset),
parse_manip<Parsable, CharT, Traits>{format, tp, &abbrev, &offset}) parse_manip<Parsable, CharT, Traits, Alloc>{format, tp, &abbrev, &offset})
{ {
return {format, tp, &abbrev, &offset}; return {format, tp, &abbrev, &offset};
} }
@@ -6357,13 +6358,13 @@ parse(const CharT* format, Parsable& tp)
return {format, tp}; return {format, tp};
} }
template <class Parsable, class CharT, class Traits> template <class Parsable, class CharT, class Traits, class Alloc>
inline inline
auto auto
parse(const CharT* format, Parsable& tp, std::basic_string<CharT, Traits>& abbrev) parse(const CharT* format, Parsable& tp, std::basic_string<CharT, Traits, Alloc>& abbrev)
-> decltype(from_stream(std::declval<std::basic_istream<CharT, Traits>&>(), format, -> decltype(from_stream(std::declval<std::basic_istream<CharT, Traits>&>(), format,
tp, &abbrev), tp, &abbrev),
parse_manip<Parsable, CharT, Traits>{format, tp, &abbrev}) parse_manip<Parsable, CharT, Traits, Alloc>{format, tp, &abbrev})
{ {
return {format, tp, &abbrev}; return {format, tp, &abbrev};
} }
@@ -6379,14 +6380,14 @@ parse(const CharT* format, Parsable& tp, std::chrono::minutes& offset)
return {format, tp, nullptr, &offset}; return {format, tp, nullptr, &offset};
} }
template <class Parsable, class CharT, class Traits> template <class Parsable, class CharT, class Traits, class Alloc>
inline inline
auto auto
parse(const CharT* format, Parsable& tp, parse(const CharT* format, Parsable& tp,
std::basic_string<CharT, Traits>& abbrev, std::chrono::minutes& offset) std::basic_string<CharT, Traits, Alloc>& abbrev, std::chrono::minutes& offset)
-> decltype(from_stream(std::declval<std::basic_istream<CharT, Traits>&>(), format, -> decltype(from_stream(std::declval<std::basic_istream<CharT, Traits>&>(), format,
tp, &abbrev, &offset), tp, &abbrev, &offset),
parse_manip<Parsable, CharT, Traits>{format, tp, &abbrev, &offset}) parse_manip<Parsable, CharT, Traits, Alloc>{format, tp, &abbrev, &offset})
{ {
return {format, tp, &abbrev, &offset}; return {format, tp, &abbrev, &offset};
} }

14
tz.h
View File

@@ -1158,10 +1158,10 @@ operator<<(std::basic_ostream<CharT, Traits>& os, const utc_time<Duration>& t)
return os; return os;
} }
template <class Duration, class CharT, class Traits> template <class Duration, class CharT, class Traits, class Alloc = std::allocator<CharT>>
void void
from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt, from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt,
utc_time<Duration>& tp, std::basic_string<CharT, Traits>* abbrev = nullptr, utc_time<Duration>& tp, std::basic_string<CharT, Traits, Alloc>* abbrev = nullptr,
std::chrono::minutes* offset = nullptr) std::chrono::minutes* offset = nullptr)
{ {
using namespace std; using namespace std;
@@ -1269,10 +1269,11 @@ operator<<(std::basic_ostream<CharT, Traits>& os, const tai_time<Duration>& t)
return os; return os;
} }
template <class Duration, class CharT, class Traits> template <class Duration, class CharT, class Traits, class Alloc = std::allocator<CharT>>
void void
from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt, from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt,
tai_time<Duration>& tp, std::basic_string<CharT, Traits>* abbrev = nullptr, tai_time<Duration>& tp,
std::basic_string<CharT, Traits, Alloc>* abbrev = nullptr,
std::chrono::minutes* offset = nullptr) std::chrono::minutes* offset = nullptr)
{ {
using namespace std; using namespace std;
@@ -1374,10 +1375,11 @@ operator<<(std::basic_ostream<CharT, Traits>& os, const gps_time<Duration>& t)
return os; return os;
} }
template <class Duration, class CharT, class Traits> template <class Duration, class CharT, class Traits, class Alloc = std::allocator<CharT>>
void void
from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt, from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt,
gps_time<Duration>& tp, std::basic_string<CharT, Traits>* abbrev = nullptr, gps_time<Duration>& tp,
std::basic_string<CharT, Traits, Alloc>* abbrev = nullptr,
std::chrono::minutes* offset = nullptr) std::chrono::minutes* offset = nullptr)
{ {
using namespace std; using namespace std;