From a921a596e7904674728b0ea8e9d2cdca3dc4cfad Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Mon, 26 Dec 2022 07:36:34 -0800 Subject: [PATCH] Cleanup core.h --- include/fmt/core.h | 47 ++++++++++++++------------------------------ include/fmt/format.h | 13 ++++++++++++ 2 files changed, 28 insertions(+), 32 deletions(-) diff --git a/include/fmt/core.h b/include/fmt/core.h index d15916d5..88486cfa 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -152,8 +152,7 @@ # endif #endif -// [[noreturn]] is disabled on MSVC and NVCC because of bogus unreachable code -// warnings. +// Disable [[noreturn]] on MSVC/NVCC because of bogus unreachable code warnings. #if FMT_EXCEPTIONS && FMT_HAS_CPP_ATTRIBUTE(noreturn) && !FMT_MSC_VERSION && \ !defined(__NVCC__) # define FMT_NORETURN [[noreturn]] @@ -308,18 +307,6 @@ template using type_identity_t = typename type_identity::type; template using underlying_t = typename std::underlying_type::type; -template struct disjunction : std::false_type {}; -template struct disjunction

: P {}; -template -struct disjunction - : conditional_t> {}; - -template struct conjunction : std::true_type {}; -template struct conjunction

: P {}; -template -struct conjunction - : conditional_t, P1> {}; - struct monostate { constexpr monostate() {} }; @@ -1682,9 +1669,8 @@ FMT_CONSTEXPR auto copy_str(R&& rng, OutputIt out) -> OutputIt { #if FMT_GCC_VERSION && FMT_GCC_VERSION < 500 // A workaround for gcc 4.8 to make void_t work in a SFINAE context. -template struct void_t_impl { using type = void; }; -template -using void_t = typename detail::void_t_impl::type; +template struct void_t_impl { using type = void; }; +template using void_t = typename void_t_impl::type; #else template using void_t = void; #endif @@ -1699,13 +1685,12 @@ struct is_output_iterator< decltype(*std::declval() = std::declval())>> : std::true_type {}; -template -struct is_back_insert_iterator : std::false_type {}; +template struct is_back_insert_iterator : std::false_type {}; template struct is_back_insert_iterator> : std::true_type {}; -template +template struct is_contiguous_back_insert_iterator : std::false_type {}; template struct is_contiguous_back_insert_iterator> @@ -1749,10 +1734,9 @@ FMT_CONSTEXPR FMT_INLINE auto make_value(T&& val) -> value { !std::is_same::value; static_assert(formattable_const, "Cannot format a const argument."); - // Formatting of arbitrary pointers is disallowed. If you want to output - // a pointer cast it to "void *" or "const void *". In particular, this - // forbids formatting of "[const] volatile char *" which is printed as bool - // by iostreams. + // Formatting of arbitrary pointers is disallowed. If you want to format a + // pointer cast it to `void*` or `const void*`. In particular, this forbids + // formatting of `[const] volatile char*` printed as bool by iostreams. constexpr bool formattable_pointer = !std::is_same::value; static_assert(formattable_pointer, @@ -1769,7 +1753,7 @@ FMT_CONSTEXPR FMT_INLINE auto make_value(T&& val) -> value { template FMT_CONSTEXPR auto make_arg(T&& value) -> basic_format_arg { - basic_format_arg arg; + auto arg = basic_format_arg(); arg.type_ = mapped_type_constant::value; arg.value_ = make_value(value); return arg; @@ -1793,10 +1777,6 @@ FMT_END_DETAIL_NAMESPACE // Formatting context. template class basic_format_context { - public: - /** The character type for the output. */ - using char_type = Char; - private: OutputIt out_; basic_format_args args_; @@ -1806,7 +1786,10 @@ template class basic_format_context { using iterator = OutputIt; using format_arg = basic_format_arg; using parse_context_type = basic_format_parse_context; - template using formatter_type = formatter; + template using formatter_type = formatter; + + /** The character type for the output. */ + using char_type = Char; basic_format_context(basic_format_context&&) = default; basic_format_context(const basic_format_context&) = delete; @@ -1821,10 +1804,10 @@ template class basic_format_context { : out_(out), args_(ctx_args), loc_(loc) {} constexpr auto arg(int id) const -> format_arg { return args_.get(id); } - FMT_CONSTEXPR auto arg(basic_string_view name) -> format_arg { + FMT_CONSTEXPR auto arg(basic_string_view name) -> format_arg { return args_.get(name); } - FMT_CONSTEXPR auto arg_id(basic_string_view name) -> int { + FMT_CONSTEXPR auto arg_id(basic_string_view name) -> int { return args_.get_id(name); } auto args() const -> const basic_format_args& { diff --git a/include/fmt/format.h b/include/fmt/format.h index 214273fa..c5212bae 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -241,6 +241,19 @@ FMT_END_NAMESPACE #endif FMT_BEGIN_NAMESPACE + +template struct disjunction : std::false_type {}; +template struct disjunction

: P {}; +template +struct disjunction + : conditional_t> {}; + +template struct conjunction : std::true_type {}; +template struct conjunction

: P {}; +template +struct conjunction + : conditional_t, P1> {}; + namespace detail { FMT_CONSTEXPR inline void abort_fuzzing_if(bool condition) {