Skip to content

Commit 329975f

Browse files
committed
Update included fmt library to version 7.1.3
1 parent 84d1039 commit 329975f

File tree

12 files changed

+2937
-1002
lines changed

12 files changed

+2937
-1002
lines changed

contrib/fmt/README.contrib

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
Source: https://github.com/fmtlib/fmt
2-
Revision: v7.0.1
2+
Revision: v7.1.3

contrib/fmt/include/fmt/chrono.h

Lines changed: 37 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -72,43 +72,27 @@ FMT_CONSTEXPR To lossless_integral_conversion(const From from, int& ec) {
7272
static_assert(F::is_integer, "From must be integral");
7373
static_assert(T::is_integer, "To must be integral");
7474

75-
if (F::is_signed && !T::is_signed) {
75+
if (detail::const_check(F::is_signed && !T::is_signed)) {
7676
// From may be negative, not allowed!
7777
if (fmt::detail::is_negative(from)) {
7878
ec = 1;
7979
return {};
8080
}
81-
8281
// From is positive. Can it always fit in To?
83-
if (F::digits <= T::digits) {
84-
// yes, From always fits in To.
85-
} else {
86-
// from may not fit in To, we have to do a dynamic check
87-
if (from > static_cast<From>((T::max)())) {
88-
ec = 1;
89-
return {};
90-
}
82+
if (F::digits > T::digits &&
83+
from > static_cast<From>(detail::max_value<To>())) {
84+
ec = 1;
85+
return {};
9186
}
9287
}
9388

94-
if (!F::is_signed && T::is_signed) {
95-
// can from be held in To?
96-
if (F::digits < T::digits) {
97-
// yes, From always fits in To.
98-
} else {
99-
// from may not fit in To, we have to do a dynamic check
100-
if (from > static_cast<From>((T::max)())) {
101-
// outside range.
102-
ec = 1;
103-
return {};
104-
}
105-
}
89+
if (!F::is_signed && T::is_signed && F::digits >= T::digits &&
90+
from > static_cast<From>(detail::max_value<To>())) {
91+
ec = 1;
92+
return {};
10693
}
107-
108-
// reaching here means all is ok for lossless conversion.
109-
return static_cast<To>(from);
110-
111-
} // function
94+
return static_cast<To>(from); // Lossless conversion.
95+
}
11296

11397
template <typename To, typename From,
11498
FMT_ENABLE_IF(std::is_same<From, To>::value)>
@@ -190,11 +174,9 @@ To safe_duration_cast(std::chrono::duration<FromRep, FromPeriod> from,
190174
// safe conversion to IntermediateRep
191175
IntermediateRep count =
192176
lossless_integral_conversion<IntermediateRep>(from.count(), ec);
193-
if (ec) {
194-
return {};
195-
}
177+
if (ec) return {};
196178
// multiply with Factor::num without overflow or underflow
197-
if (Factor::num != 1) {
179+
if (detail::const_check(Factor::num != 1)) {
198180
const auto max1 = detail::max_value<IntermediateRep>() / Factor::num;
199181
if (count > max1) {
200182
ec = 1;
@@ -209,17 +191,9 @@ To safe_duration_cast(std::chrono::duration<FromRep, FromPeriod> from,
209191
count *= Factor::num;
210192
}
211193

212-
// this can't go wrong, right? den>0 is checked earlier.
213-
if (Factor::den != 1) {
214-
count /= Factor::den;
215-
}
216-
// convert to the to type, safely
217-
using ToRep = typename To::rep;
218-
const ToRep tocount = lossless_integral_conversion<ToRep>(count, ec);
219-
if (ec) {
220-
return {};
221-
}
222-
return To{tocount};
194+
if (detail::const_check(Factor::den != 1)) count /= Factor::den;
195+
auto tocount = lossless_integral_conversion<typename To::rep>(count, ec);
196+
return ec ? To() : To(tocount);
223197
}
224198

225199
/**
@@ -351,6 +325,11 @@ inline std::tm localtime(std::time_t time) {
351325
return lt.tm_;
352326
}
353327

328+
inline std::tm localtime(
329+
std::chrono::time_point<std::chrono::system_clock> time_point) {
330+
return localtime(std::chrono::system_clock::to_time_t(time_point));
331+
}
332+
354333
// Thread-safe replacement for std::gmtime
355334
inline std::tm gmtime(std::time_t time) {
356335
struct dispatcher {
@@ -387,6 +366,11 @@ inline std::tm gmtime(std::time_t time) {
387366
return gt.tm_;
388367
}
389368

369+
inline std::tm gmtime(
370+
std::chrono::time_point<std::chrono::system_clock> time_point) {
371+
return gmtime(std::chrono::system_clock::to_time_t(time_point));
372+
}
373+
390374
namespace detail {
391375
inline size_t strftime(char* str, size_t count, const char* format,
392376
const std::tm* time) {
@@ -399,6 +383,17 @@ inline size_t strftime(wchar_t* str, size_t count, const wchar_t* format,
399383
}
400384
} // namespace detail
401385

386+
template <typename Char>
387+
struct formatter<std::chrono::time_point<std::chrono::system_clock>, Char>
388+
: formatter<std::tm, Char> {
389+
template <typename FormatContext>
390+
auto format(std::chrono::time_point<std::chrono::system_clock> val,
391+
FormatContext& ctx) -> decltype(ctx.out()) {
392+
std::tm time = localtime(val);
393+
return formatter<std::tm, Char>::format(time, ctx);
394+
}
395+
};
396+
402397
template <typename Char> struct formatter<std::tm, Char> {
403398
template <typename ParseContext>
404399
auto parse(ParseContext& ctx) -> decltype(ctx.begin()) {

contrib/fmt/include/fmt/color.h

Lines changed: 47 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -463,16 +463,16 @@ template <> inline void reset_color<wchar_t>(FILE* stream) FMT_NOEXCEPT {
463463
}
464464

465465
template <typename Char>
466-
inline void reset_color(basic_memory_buffer<Char>& buffer) FMT_NOEXCEPT {
466+
inline void reset_color(buffer<Char>& buffer) FMT_NOEXCEPT {
467467
const char* begin = data::reset_color;
468468
const char* end = begin + sizeof(data::reset_color) - 1;
469469
buffer.append(begin, end);
470470
}
471471

472472
template <typename Char>
473-
void vformat_to(basic_memory_buffer<Char>& buf, const text_style& ts,
473+
void vformat_to(buffer<Char>& buf, const text_style& ts,
474474
basic_string_view<Char> format_str,
475-
basic_format_args<buffer_context<Char>> args) {
475+
basic_format_args<buffer_context<type_identity_t<Char>>> args) {
476476
bool has_style = false;
477477
if (ts.has_emphasis()) {
478478
has_style = true;
@@ -496,28 +496,30 @@ void vformat_to(basic_memory_buffer<Char>& buf, const text_style& ts,
496496

497497
template <typename S, typename Char = char_t<S>>
498498
void vprint(std::FILE* f, const text_style& ts, const S& format,
499-
basic_format_args<buffer_context<Char>> args) {
499+
basic_format_args<buffer_context<type_identity_t<Char>>> args) {
500500
basic_memory_buffer<Char> buf;
501501
detail::vformat_to(buf, ts, to_string_view(format), args);
502502
buf.push_back(Char(0));
503503
detail::fputs(buf.data(), f);
504504
}
505505

506506
/**
507+
\rst
507508
Formats a string and prints it to the specified file stream using ANSI
508509
escape sequences to specify text formatting.
509-
Example:
510+
511+
**Example**::
512+
510513
fmt::print(fmt::emphasis::bold | fg(fmt::color::red),
511514
"Elapsed time: {0:.2f} seconds", 1.23);
515+
\endrst
512516
*/
513517
template <typename S, typename... Args,
514518
FMT_ENABLE_IF(detail::is_string<S>::value)>
515519
void print(std::FILE* f, const text_style& ts, const S& format_str,
516520
const Args&... args) {
517-
detail::check_format_string<Args...>(format_str);
518-
using context = buffer_context<char_t<S>>;
519-
format_arg_store<context, Args...> as{args...};
520-
vprint(f, ts, format_str, basic_format_args<context>(as));
521+
vprint(f, ts, format_str,
522+
fmt::make_args_checked<Args...>(format_str, args...));
521523
}
522524

523525
/**
@@ -558,7 +560,42 @@ template <typename S, typename... Args, typename Char = char_t<S>>
558560
inline std::basic_string<Char> format(const text_style& ts, const S& format_str,
559561
const Args&... args) {
560562
return vformat(ts, to_string_view(format_str),
561-
detail::make_args_checked<Args...>(format_str, args...));
563+
fmt::make_args_checked<Args...>(format_str, args...));
564+
}
565+
566+
/**
567+
Formats a string with the given text_style and writes the output to ``out``.
568+
*/
569+
template <typename OutputIt, typename Char,
570+
FMT_ENABLE_IF(detail::is_output_iterator<OutputIt, Char>::value)>
571+
OutputIt vformat_to(
572+
OutputIt out, const text_style& ts, basic_string_view<Char> format_str,
573+
basic_format_args<buffer_context<type_identity_t<Char>>> args) {
574+
decltype(detail::get_buffer<Char>(out)) buf(detail::get_buffer_init(out));
575+
detail::vformat_to(buf, ts, format_str, args);
576+
return detail::get_iterator(buf);
577+
}
578+
579+
/**
580+
\rst
581+
Formats arguments with the given text_style, writes the result to the output
582+
iterator ``out`` and returns the iterator past the end of the output range.
583+
584+
**Example**::
585+
586+
std::vector<char> out;
587+
fmt::format_to(std::back_inserter(out),
588+
fmt::emphasis::bold | fg(fmt::color::red), "{}", 42);
589+
\endrst
590+
*/
591+
template <typename OutputIt, typename S, typename... Args,
592+
bool enable = detail::is_output_iterator<OutputIt, char_t<S>>::value&&
593+
detail::is_string<S>::value>
594+
inline auto format_to(OutputIt out, const text_style& ts, const S& format_str,
595+
Args&&... args) ->
596+
typename std::enable_if<enable, OutputIt>::type {
597+
return vformat_to(out, ts, to_string_view(format_str),
598+
fmt::make_args_checked<Args...>(format_str, args...));
562599
}
563600

564601
FMT_END_NAMESPACE

0 commit comments

Comments
 (0)