mirror of
https://github.com/HowardHinnant/date.git
synced 2024-12-27 08:31:03 +08:00
Added Alloc argument to template parameters to support custom allocators in from_stream
This commit is contained in:
parent
a811a20748
commit
f4292e6aca
107
date.h
107
date.h
@ -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 std::chrono::seconds* offset_sec = nullptr);
|
||||
|
||||
template <class CharT, class Traits, class Duration>
|
||||
template <class CharT, class Traits, class Duration, class Alloc>
|
||||
void
|
||||
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);
|
||||
|
||||
// time_of_day
|
||||
@ -3914,12 +3914,12 @@ public:
|
||||
const fields<Duration>& fds, const std::string* abbrev,
|
||||
const std::chrono::seconds* offset_sec);
|
||||
|
||||
template <class CharT, class Traits, class Duration>
|
||||
template <class CharT, class Traits, class Duration, class Alloc>
|
||||
friend
|
||||
void
|
||||
date::from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt,
|
||||
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>
|
||||
@ -4018,12 +4018,12 @@ public:
|
||||
const fields<Duration>& fds, const std::string* abbrev,
|
||||
const std::chrono::seconds* offset_sec);
|
||||
|
||||
template <class CharT, class Traits, class Duration>
|
||||
template <class CharT, class Traits, class Duration, class Alloc>
|
||||
friend
|
||||
void
|
||||
date::from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt,
|
||||
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
|
||||
@ -5038,12 +5038,12 @@ format(const CharT* fmt, const Streamable& tp)
|
||||
return os.str();
|
||||
}
|
||||
|
||||
template <class CharT, class Traits, class Streamable>
|
||||
template <class CharT, class Traits, class Alloc, class Streamable>
|
||||
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)
|
||||
-> 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;
|
||||
os.imbue(loc);
|
||||
@ -5051,11 +5051,11 @@ format(const std::locale& loc, const std::basic_string<CharT, Traits>& fmt,
|
||||
return os.str();
|
||||
}
|
||||
|
||||
template <class CharT, class Traits, class Streamable>
|
||||
template <class CharT, class Traits, class Alloc, class Streamable>
|
||||
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),
|
||||
std::basic_string<CharT, Traits>{})
|
||||
std::basic_string<CharT, Traits, Alloc>{})
|
||||
{
|
||||
std::basic_ostringstream<CharT, Traits> os;
|
||||
to_stream(os, fmt.c_str(), tp);
|
||||
@ -5297,10 +5297,10 @@ read(std::basic_istream<CharT, Traits>& is, rld a0, Args&& ...args)
|
||||
|
||||
} // namespace detail;
|
||||
|
||||
template <class CharT, class Traits, class Duration>
|
||||
template <class CharT, class Traits, class Duration, class Alloc = std::allocator<CharT>>
|
||||
void
|
||||
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)
|
||||
{
|
||||
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());
|
||||
std::tm tm{};
|
||||
std::basic_string<CharT, Traits> temp_abbrev;
|
||||
std::basic_string<CharT, Traits, Alloc> temp_abbrev;
|
||||
minutes temp_offset{};
|
||||
const CharT* command = nullptr;
|
||||
auto modified = CharT{};
|
||||
@ -6199,10 +6199,10 @@ broken:
|
||||
is.setstate(ios_base::failbit);
|
||||
}
|
||||
|
||||
template <class CharT, class Traits>
|
||||
template <class CharT, class Traits, class Alloc = std::allocator<CharT>>
|
||||
void
|
||||
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)
|
||||
{
|
||||
using namespace std;
|
||||
@ -6216,10 +6216,10 @@ from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt,
|
||||
ymd = fds.ymd;
|
||||
}
|
||||
|
||||
template <class Duration, class CharT, class Traits>
|
||||
template <class Duration, class CharT, class Traits, class Alloc = std::allocator<CharT>>
|
||||
void
|
||||
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)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
template <class Duration, class CharT, class Traits>
|
||||
template <class Duration, class CharT, class Traits, class Alloc = std::allocator<CharT>>
|
||||
void
|
||||
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)
|
||||
{
|
||||
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());
|
||||
}
|
||||
|
||||
template <class Rep, class Period, class CharT, class Traits>
|
||||
template <class Rep, class Period, class CharT, class Traits, class Alloc = std::allocator<CharT>>
|
||||
void
|
||||
from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt,
|
||||
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)
|
||||
{
|
||||
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());
|
||||
}
|
||||
|
||||
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
|
||||
{
|
||||
const std::basic_string<CharT, Traits> format_;
|
||||
Parsable& tp_;
|
||||
std::basic_string<CharT, Traits>* abbrev_;
|
||||
std::chrono::minutes* offset_;
|
||||
const std::basic_string<CharT, Traits, Alloc> format_;
|
||||
Parsable& tp_;
|
||||
std::basic_string<CharT, Traits, Alloc>* abbrev_;
|
||||
std::chrono::minutes* offset_;
|
||||
|
||||
public:
|
||||
parse_manip(std::basic_string<CharT, Traits> format,
|
||||
Parsable& tp, std::basic_string<CharT, Traits>* abbrev = nullptr,
|
||||
std::chrono::minutes* offset = nullptr)
|
||||
parse_manip(std::basic_string<CharT, Traits, Alloc> format, Parsable& tp,
|
||||
std::basic_string<CharT, Traits, Alloc>* abbrev = nullptr,
|
||||
std::chrono::minutes* offset = nullptr)
|
||||
: format_(std::move(format))
|
||||
, tp_(tp)
|
||||
, 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>&
|
||||
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_);
|
||||
return is;
|
||||
}
|
||||
|
||||
template <class Parsable, class CharT, class Traits>
|
||||
template <class Parsable, class CharT, class Traits, class Alloc>
|
||||
inline
|
||||
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>&>(),
|
||||
format.c_str(), tp),
|
||||
parse_manip<Parsable, CharT, Traits>{format, tp})
|
||||
parse_manip<Parsable, CharT, Traits, Alloc>{format, tp})
|
||||
{
|
||||
return {format, tp};
|
||||
}
|
||||
|
||||
template <class Parsable, class CharT, class Traits>
|
||||
template <class Parsable, class CharT, class Traits, class Alloc>
|
||||
inline
|
||||
auto
|
||||
parse(const std::basic_string<CharT, Traits>& format, Parsable& tp,
|
||||
std::basic_string<CharT, Traits>& abbrev)
|
||||
parse(const std::basic_string<CharT, Traits, Alloc>& format, Parsable& tp,
|
||||
std::basic_string<CharT, Traits, Alloc>& abbrev)
|
||||
-> decltype(from_stream(std::declval<std::basic_istream<CharT, Traits>&>(),
|
||||
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};
|
||||
}
|
||||
|
||||
template <class Parsable, class CharT, class Traits>
|
||||
template <class Parsable, class CharT, class Traits, class Alloc>
|
||||
inline
|
||||
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)
|
||||
-> decltype(from_stream(std::declval<std::basic_istream<CharT, Traits>&>(),
|
||||
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};
|
||||
}
|
||||
|
||||
template <class Parsable, class CharT, class Traits>
|
||||
template <class Parsable, class CharT, class Traits, class Alloc>
|
||||
inline
|
||||
auto
|
||||
parse(const std::basic_string<CharT, Traits>& format, Parsable& tp,
|
||||
std::basic_string<CharT, Traits>& abbrev, std::chrono::minutes& offset)
|
||||
parse(const std::basic_string<CharT, Traits, Alloc>& format, Parsable& tp,
|
||||
std::basic_string<CharT, Traits, Alloc>& abbrev, std::chrono::minutes& offset)
|
||||
-> decltype(from_stream(std::declval<std::basic_istream<CharT, Traits>&>(),
|
||||
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};
|
||||
}
|
||||
@ -6357,13 +6358,13 @@ parse(const CharT* format, Parsable& tp)
|
||||
return {format, tp};
|
||||
}
|
||||
|
||||
template <class Parsable, class CharT, class Traits>
|
||||
template <class Parsable, class CharT, class Traits, class Alloc>
|
||||
inline
|
||||
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,
|
||||
tp, &abbrev),
|
||||
parse_manip<Parsable, CharT, Traits>{format, tp, &abbrev})
|
||||
parse_manip<Parsable, CharT, Traits, Alloc>{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};
|
||||
}
|
||||
|
||||
template <class Parsable, class CharT, class Traits>
|
||||
template <class Parsable, class CharT, class Traits, class Alloc>
|
||||
inline
|
||||
auto
|
||||
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,
|
||||
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};
|
||||
}
|
||||
|
14
tz.h
14
tz.h
@ -1158,10 +1158,10 @@ operator<<(std::basic_ostream<CharT, Traits>& os, const utc_time<Duration>& t)
|
||||
return os;
|
||||
}
|
||||
|
||||
template <class Duration, class CharT, class Traits>
|
||||
template <class Duration, class CharT, class Traits, class Alloc = std::allocator<CharT>>
|
||||
void
|
||||
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)
|
||||
{
|
||||
using namespace std;
|
||||
@ -1269,10 +1269,11 @@ operator<<(std::basic_ostream<CharT, Traits>& os, const tai_time<Duration>& t)
|
||||
return os;
|
||||
}
|
||||
|
||||
template <class Duration, class CharT, class Traits>
|
||||
template <class Duration, class CharT, class Traits, class Alloc = std::allocator<CharT>>
|
||||
void
|
||||
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)
|
||||
{
|
||||
using namespace std;
|
||||
@ -1374,10 +1375,11 @@ operator<<(std::basic_ostream<CharT, Traits>& os, const gps_time<Duration>& t)
|
||||
return os;
|
||||
}
|
||||
|
||||
template <class Duration, class CharT, class Traits>
|
||||
template <class Duration, class CharT, class Traits, class Alloc = std::allocator<CharT>>
|
||||
void
|
||||
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)
|
||||
{
|
||||
using namespace std;
|
||||
|
Loading…
x
Reference in New Issue
Block a user