Adding guards around if constexpr
This commit is contained in:
parent
b5bd6323fc
commit
805e84f679
@ -1539,8 +1539,10 @@ constexpr auto encode_types() -> unsigned long long {
|
|||||||
(encode_types<Context, Args...>() << packed_arg_bits);
|
(encode_types<Context, Args...>() << packed_arg_bits);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(__cpp_if_constexpr)
|
||||||
// This type is intentionally undefined, only used for errors
|
// This type is intentionally undefined, only used for errors
|
||||||
template <typename T, typename Char> struct type_is_unformattable_for;
|
template <typename T, typename Char> struct type_is_unformattable_for;
|
||||||
|
#endif
|
||||||
|
|
||||||
template <bool PACKED, typename Context, typename T, FMT_ENABLE_IF(PACKED)>
|
template <bool PACKED, typename Context, typename T, FMT_ENABLE_IF(PACKED)>
|
||||||
FMT_CONSTEXPR FMT_INLINE auto make_arg(T& val) -> value<Context> {
|
FMT_CONSTEXPR FMT_INLINE auto make_arg(T& val) -> value<Context> {
|
||||||
@ -1548,9 +1550,11 @@ FMT_CONSTEXPR FMT_INLINE auto make_arg(T& val) -> value<Context> {
|
|||||||
|
|
||||||
constexpr bool formattable_char =
|
constexpr bool formattable_char =
|
||||||
!std::is_same<arg_type, unformattable_char>::value;
|
!std::is_same<arg_type, unformattable_char>::value;
|
||||||
|
#if defined(__cpp_if_constexpr)
|
||||||
if constexpr (not formattable_char) {
|
if constexpr (not formattable_char) {
|
||||||
type_is_unformattable_for<T, typename Context::char_type> _;
|
type_is_unformattable_for<T, typename Context::char_type> _;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
static_assert(formattable_char, "Mixing character types is disallowed.");
|
static_assert(formattable_char, "Mixing character types is disallowed.");
|
||||||
|
|
||||||
// Formatting of arbitrary pointers is disallowed. If you want to format a
|
// Formatting of arbitrary pointers is disallowed. If you want to format a
|
||||||
@ -1558,16 +1562,20 @@ FMT_CONSTEXPR FMT_INLINE auto make_arg(T& val) -> value<Context> {
|
|||||||
// formatting of `[const] volatile char*` printed as bool by iostreams.
|
// formatting of `[const] volatile char*` printed as bool by iostreams.
|
||||||
constexpr bool formattable_pointer =
|
constexpr bool formattable_pointer =
|
||||||
!std::is_same<arg_type, unformattable_pointer>::value;
|
!std::is_same<arg_type, unformattable_pointer>::value;
|
||||||
|
#if defined(__cpp_if_constexpr)
|
||||||
if constexpr (not formattable_pointer) {
|
if constexpr (not formattable_pointer) {
|
||||||
type_is_unformattable_for<T, typename Context::char_type> _;
|
type_is_unformattable_for<T, typename Context::char_type> _;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
static_assert(formattable_pointer,
|
static_assert(formattable_pointer,
|
||||||
"Formatting of non-void pointers is disallowed.");
|
"Formatting of non-void pointers is disallowed.");
|
||||||
|
|
||||||
constexpr bool formattable = !std::is_same<arg_type, unformattable>::value;
|
constexpr bool formattable = !std::is_same<arg_type, unformattable>::value;
|
||||||
|
#if defined(__cpp_if_constexpr)
|
||||||
if constexpr (not formattable) {
|
if constexpr (not formattable) {
|
||||||
type_is_unformattable_for<T, typename Context::char_type> _;
|
type_is_unformattable_for<T, typename Context::char_type> _;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
static_assert(
|
static_assert(
|
||||||
formattable,
|
formattable,
|
||||||
"Cannot format an argument. To make type T formattable provide a "
|
"Cannot format an argument. To make type T formattable provide a "
|
||||||
@ -2532,6 +2540,7 @@ FMT_CONSTEXPR auto parse_format_specs(ParseContext& ctx)
|
|||||||
mapped_type_constant<T, context>::value != type::custom_type,
|
mapped_type_constant<T, context>::value != type::custom_type,
|
||||||
decltype(arg_mapper<context>().map(std::declval<const T&>())),
|
decltype(arg_mapper<context>().map(std::declval<const T&>())),
|
||||||
typename strip_named_arg<T>::type>;
|
typename strip_named_arg<T>::type>;
|
||||||
|
#if defined(__cpp_if_constexpr)
|
||||||
if constexpr (std::is_default_constructible_v<
|
if constexpr (std::is_default_constructible_v<
|
||||||
formatter<mapped_type, char_type>>) {
|
formatter<mapped_type, char_type>>) {
|
||||||
return formatter<mapped_type, char_type>().parse(ctx);
|
return formatter<mapped_type, char_type>().parse(ctx);
|
||||||
@ -2539,6 +2548,9 @@ FMT_CONSTEXPR auto parse_format_specs(ParseContext& ctx)
|
|||||||
type_is_unformattable_for<T, char_type> _;
|
type_is_unformattable_for<T, char_type> _;
|
||||||
return ctx.begin();
|
return ctx.begin();
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
return formatter<mapped_type, char_type>().parse(ctx);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// Checks char specs and returns true iff the presentation type is char-like.
|
// Checks char specs and returns true iff the presentation type is char-like.
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user