16
16
#include < type_traits>
17
17
18
18
// The fmt library version in the form major * 10000 + minor * 100 + patch.
19
- #define FMT_VERSION 80000
19
+ #define FMT_VERSION 80001
20
20
21
21
#ifdef __clang__
22
22
# define FMT_CLANG_VERSION (__clang_major__ * 100 + __clang_minor__)
23
23
#else
24
24
# define FMT_CLANG_VERSION 0
25
25
#endif
26
26
27
- #if defined(__GNUC__) && !defined(__clang__)
27
+ #if defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER)
28
28
# define FMT_GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__)
29
29
# define FMT_GCC_PRAGMA (arg ) _Pragma (arg)
30
30
#else
64
64
# define FMT_HAS_FEATURE (x ) 0
65
65
#endif
66
66
67
- #if defined(__has_include) && !defined(__INTELLISENSE__) && \
67
+ #if defined(__has_include) && \
68
+ (!defined(__INTELLISENSE__) || FMT_MSC_VER > 1900 ) && \
68
69
(!FMT_ICC_VERSION || FMT_ICC_VERSION >= 1600 )
69
70
# define FMT_HAS_INCLUDE (x ) __has_include(x)
70
71
#else
228
229
# define FMT_INLINE_NAMESPACE namespace
229
230
# define FMT_END_NAMESPACE \
230
231
} \
231
- using namespace v7 ; \
232
+ using namespace v8 ; \
232
233
}
233
234
# endif
234
235
# define FMT_BEGIN_NAMESPACE \
235
236
namespace fmt { \
236
- FMT_INLINE_NAMESPACE v7 {
237
+ FMT_INLINE_NAMESPACE v8 {
237
238
#endif
238
239
239
240
#ifndef FMT_MODULE_EXPORT
@@ -316,9 +317,9 @@ FMT_BEGIN_NAMESPACE
316
317
FMT_MODULE_EXPORT_BEGIN
317
318
318
319
// Implementations of enable_if_t and other metafunctions for older systems.
319
- template <bool B, class T = void >
320
+ template <bool B, typename T = void >
320
321
using enable_if_t = typename std::enable_if<B, T>::type;
321
- template <bool B, class T , class F >
322
+ template <bool B, typename T, typename F>
322
323
using conditional_t = typename std::conditional<B, T, F>::type;
323
324
template <bool B> using bool_constant = std::integral_constant<bool , B>;
324
325
template <typename T>
@@ -332,6 +333,11 @@ struct monostate {
332
333
constexpr monostate () {}
333
334
};
334
335
336
+ // Suppress "unused variable" warnings with the method described in
337
+ // https://herbsutter.com/2009/10/18/mailbag-shutting-up-compiler-warnings/.
338
+ // (void)var does not work on many Intel compilers.
339
+ template <typename ... T> FMT_CONSTEXPR void ignore_unused (const T&...) {}
340
+
335
341
// An enable_if helper to be used in template parameters which results in much
336
342
// shorter symbols: https://godbolt.org/z/sWw4vP. Extra parentheses are needed
337
343
// to workaround a bug in MSVC 2019 (see #1140 and #1186).
@@ -360,7 +366,8 @@ FMT_NORETURN FMT_API void assert_fail(const char* file, int line,
360
366
#ifndef FMT_ASSERT
361
367
# ifdef NDEBUG
362
368
// FMT_ASSERT is not empty to avoid -Werror=empty-body.
363
- # define FMT_ASSERT (condition, message ) ((void )0 )
369
+ # define FMT_ASSERT (condition, message ) \
370
+ ::fmt::ignore_unused ((condition), (message))
364
371
# else
365
372
# define FMT_ASSERT (condition, message ) \
366
373
((condition) /* void() fails with -Winvalid-constexpr on clang 4.0.1 */ \
@@ -525,39 +532,21 @@ using string_view = basic_string_view<char>;
525
532
template <typename T> struct is_char : std::false_type {};
526
533
template <> struct is_char <char > : std::true_type {};
527
534
528
- /* *
529
- \rst
530
- Returns a string view of `s`. In order to add custom string type support to
531
- {fmt} provide an overload of `to_string_view` for it in the same namespace as
532
- the type for the argument-dependent lookup to work.
533
-
534
- **Example**::
535
-
536
- namespace my_ns {
537
- inline string_view to_string_view(const my_string& s) {
538
- return {s.data(), s.length()};
539
- }
540
- }
541
- std::string message = fmt::format(my_string("The answer is {}"), 42);
542
- \endrst
543
- */
535
+ // Returns a string view of `s`.
544
536
template <typename Char, FMT_ENABLE_IF(is_char<Char>::value)>
545
537
FMT_INLINE auto to_string_view (const Char* s) -> basic_string_view<Char> {
546
538
return s;
547
539
}
548
-
549
540
template <typename Char, typename Traits, typename Alloc>
550
541
inline auto to_string_view (const std::basic_string<Char, Traits, Alloc>& s)
551
542
-> basic_string_view<Char> {
552
543
return s;
553
544
}
554
-
555
545
template <typename Char>
556
546
constexpr auto to_string_view (basic_string_view<Char> s)
557
547
-> basic_string_view<Char> {
558
548
return s;
559
549
}
560
-
561
550
template <typename Char,
562
551
FMT_ENABLE_IF (!std::is_empty<detail::std_string_view<Char>>::value)>
563
552
inline auto to_string_view(detail::std_string_view<Char> s)
@@ -581,7 +570,7 @@ constexpr auto to_string_view(const S& s)
581
570
FMT_BEGIN_DETAIL_NAMESPACE
582
571
583
572
void to_string_view (...);
584
- using fmt::v7 ::to_string_view;
573
+ using fmt::v8 ::to_string_view;
585
574
586
575
// Specifies whether S is a string type convertible to fmt::basic_string_view.
587
576
// It should be a constexpr function but MSVC 2017 fails to compile it in
@@ -624,7 +613,7 @@ template <typename S> using char_t = typename detail::char_t_impl<S>::type;
624
613
\rst
625
614
Parsing context consisting of a format string range being parsed and an
626
615
argument counter for automatic indexing.
627
- You can use the ``` format_parse_context`` type alias for ``char`` instead.
616
+ You can use the ``format_parse_context`` type alias for ``char`` instead.
628
617
\endrst
629
618
*/
630
619
template <typename Char, typename ErrorHandler = detail::error_handler>
@@ -2420,7 +2409,7 @@ FMT_CONSTEXPR FMT_INLINE void parse_format_string(
2420
2409
if (pbegin == pend) return ;
2421
2410
for (;;) {
2422
2411
const Char* p = nullptr ;
2423
- if (!find<IS_CONSTEXPR>(pbegin, pend, ' }' , p))
2412
+ if (!find<IS_CONSTEXPR>(pbegin, pend, Char ( ' }' ) , p))
2424
2413
return handler_.on_text (pbegin, pend);
2425
2414
++p;
2426
2415
if (p == pend || *p != ' }' )
@@ -2435,7 +2424,7 @@ FMT_CONSTEXPR FMT_INLINE void parse_format_string(
2435
2424
// Doing two passes with memchr (one for '{' and another for '}') is up to
2436
2425
// 2.5x faster than the naive one-pass implementation on big format strings.
2437
2426
const Char* p = begin;
2438
- if (*begin != ' {' && !find<IS_CONSTEXPR>(begin + 1 , end, ' {' , p))
2427
+ if (*begin != ' {' && !find<IS_CONSTEXPR>(begin + 1 , end, Char ( ' {' ) , p))
2439
2428
return write (begin, end);
2440
2429
write (begin, p);
2441
2430
begin = parse_replacement_field (p, end, handler);
@@ -2588,8 +2577,8 @@ FMT_CONSTEXPR auto check_cstring_type_spec(Char spec, ErrorHandler&& eh = {})
2588
2577
return false ;
2589
2578
}
2590
2579
2591
- template <typename Char, typename ErrorHandler>
2592
- FMT_CONSTEXPR void check_string_type_spec (Char spec, ErrorHandler&& eh) {
2580
+ template <typename Char, typename ErrorHandler = error_handler >
2581
+ FMT_CONSTEXPR void check_string_type_spec (Char spec, ErrorHandler&& eh = {} ) {
2593
2582
if (spec != 0 && spec != ' s' ) eh.on_error (" invalid type specifier" );
2594
2583
}
2595
2584
@@ -2656,21 +2645,28 @@ constexpr auto get_arg_index_by_name(basic_string_view<Char> name) -> int {
2656
2645
if constexpr (detail::is_statically_named_arg<T>()) {
2657
2646
if (name == T::name) return N;
2658
2647
}
2659
- if constexpr (sizeof ...(Args) > 0 )
2648
+ if constexpr (sizeof ...(Args) > 0 ) {
2660
2649
return get_arg_index_by_name<N + 1 , Args...>(name);
2661
- (void )name; // Workaround an MSVC bug about "unused" parameter.
2662
- return invalid_arg_index;
2650
+ } else {
2651
+ (void )name; // Workaround an MSVC bug about "unused" parameter.
2652
+ return invalid_arg_index;
2653
+ }
2663
2654
}
2664
2655
#endif
2665
2656
2666
2657
template <typename ... Args, typename Char>
2667
2658
FMT_CONSTEXPR auto get_arg_index_by_name (basic_string_view<Char> name) -> int {
2668
2659
#if FMT_USE_NONTYPE_TEMPLATE_PARAMETERS
2669
- if constexpr (sizeof ...(Args) > 0 )
2660
+ if constexpr (sizeof ...(Args) > 0 ) {
2670
2661
return get_arg_index_by_name<0 , Args...>(name);
2671
- #endif
2662
+ } else {
2663
+ (void )name;
2664
+ return invalid_arg_index;
2665
+ }
2666
+ #else
2672
2667
(void )name;
2673
2668
return invalid_arg_index;
2669
+ #endif
2674
2670
}
2675
2671
2676
2672
template <typename Char, typename ErrorHandler, typename ... Args>
@@ -2731,14 +2727,14 @@ void check_format_string(S format_str) {
2731
2727
remove_cvref_t <Args>...>;
2732
2728
FMT_CONSTEXPR bool invalid_format =
2733
2729
(parse_format_string<true >(s, checker (s, {})), true );
2734
- ( void ) invalid_format;
2730
+ ignore_unused ( invalid_format) ;
2735
2731
}
2736
2732
2737
2733
template <typename Char>
2738
2734
void vformat_to (
2739
2735
buffer<Char>& buf, basic_string_view<Char> fmt,
2740
2736
basic_format_args<FMT_BUFFER_CONTEXT(type_identity_t <Char>)> args,
2741
- detail:: locale_ref loc = {});
2737
+ locale_ref loc = {});
2742
2738
2743
2739
FMT_API void vprint_mojibake (std::FILE*, string_view, format_args);
2744
2740
#ifndef _WIN32
@@ -2896,7 +2892,7 @@ template <typename OutputIt,
2896
2892
auto vformat_to(OutputIt out, string_view fmt, format_args args) -> OutputIt {
2897
2893
using detail::get_buffer;
2898
2894
auto && buf = get_buffer<char >(out);
2899
- detail::vformat_to (buf, string_view (fmt), args);
2895
+ detail::vformat_to (buf, string_view (fmt), args, {} );
2900
2896
return detail::get_iterator (buf);
2901
2897
}
2902
2898
@@ -2933,7 +2929,7 @@ auto vformat_to_n(OutputIt out, size_t n, string_view fmt, format_args args)
2933
2929
using buffer =
2934
2930
detail::iterator_buffer<OutputIt, char , detail::fixed_buffer_traits>;
2935
2931
auto buf = buffer (out, n);
2936
- detail::vformat_to (buf, fmt, args);
2932
+ detail::vformat_to (buf, fmt, args, {} );
2937
2933
return {buf.out (), buf.count ()};
2938
2934
}
2939
2935
@@ -2955,7 +2951,7 @@ FMT_INLINE auto format_to_n(OutputIt out, size_t n, format_string<T...> fmt,
2955
2951
template <typename ... T>
2956
2952
FMT_INLINE auto formatted_size (format_string<T...> fmt, T&&... args) -> size_t {
2957
2953
auto buf = detail::counting_buffer<>();
2958
- detail::vformat_to (buf, string_view (fmt), fmt::make_format_args (args...));
2954
+ detail::vformat_to (buf, string_view (fmt), fmt::make_format_args (args...), {} );
2959
2955
return buf.count ();
2960
2956
}
2961
2957
0 commit comments