From f041f128f51e2968f6c0c22e84322311a03a295b Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Sun, 10 Feb 2019 08:42:53 -0800 Subject: [PATCH] Minor cleanup --- include/fmt/core.h | 90 +++++++++++++++++++------------------------- include/fmt/printf.h | 1 - 2 files changed, 39 insertions(+), 52 deletions(-) diff --git a/include/fmt/core.h b/include/fmt/core.h index 88cb53d8..a3c84b7c 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -153,7 +153,7 @@ # elif FMT_MSC_VER # define FMT_DEPRECATED __declspec(deprecated) # else -# define FMT_DEPRECATED /*deprecated*/ +# define FMT_DEPRECATED /* deprecated */ # endif # endif #endif @@ -208,6 +208,8 @@ # include #endif +#define FMT_ENABLE_IF_T(...) typename std::enable_if<__VA_ARGS__>::type + FMT_BEGIN_NAMESPACE namespace internal { @@ -511,8 +513,8 @@ struct compile_string {}; template struct is_compile_string : std::is_base_of {}; -template ::value>::type> +template ::value)> FMT_CONSTEXPR basic_string_view to_string_view( const S& s) { return s; @@ -790,18 +792,14 @@ FMT_MAKE_VALUE(uint_type, unsigned char, unsigned) // This doesn't use FMT_MAKE_VALUE because of ambiguity in gcc 4.4. template -FMT_CONSTEXPR - typename std::enable_if::value, - init>::type - make_value(Char val) { +FMT_CONSTEXPR FMT_ENABLE_IF_T(std::is_same::value, + init) make_value(Char val) { return val; } template -FMT_CONSTEXPR - typename std::enable_if::value, - init>::type - make_value(char val) { +FMT_CONSTEXPR FMT_ENABLE_IF_T(!std::is_same::value, + init) make_value(char val) { return val; } @@ -838,39 +836,35 @@ FMT_MAKE_VALUE(pointer_type, std::nullptr_t, const void*) // formatting of "[const] volatile char *" which is printed as bool by // iostreams. template -typename std::enable_if::value>::type +FMT_ENABLE_IF_T(!std::is_same::value) make_value(const T*) { static_assert(!sizeof(T), "formatting of non-void pointers is disallowed"); } template -inline - typename std::enable_if::value && - convert_to_int::value, - init>::type - make_value(const T& val) { +inline FMT_ENABLE_IF_T( + std::is_enum::value&& convert_to_int::value, + init) make_value(const T& val) { return static_cast(val); } template -inline typename std::enable_if< - is_constructible, T>::value && - !internal::is_string::value, - init, string_type>>::type -make_value(const T& val) { +inline FMT_ENABLE_IF_T(is_constructible, T>::value && + !internal::is_string::value, + init, string_type>) + make_value(const T& val) { return basic_string_view(val); } template -inline typename std::enable_if< +inline FMT_ENABLE_IF_T( !convert_to_int::value && !std::is_same::value && !std::is_convertible>::value && !is_constructible, T>::value && !internal::is_string::value, // Implicit conversion to std::string is not handled here because it's // unsafe: https://github.com/fmtlib/fmt/issues/729 - init>::type -make_value(const T& val) { + init) make_value(const T& val) { return val; } @@ -883,10 +877,10 @@ init make_value( } template -FMT_CONSTEXPR11 typename std::enable_if< +FMT_CONSTEXPR11 FMT_ENABLE_IF_T( internal::is_string::value, - init, string_type>>::type -make_value(const S& val) { + init, string_type>) + make_value(const S& val) { // Handle adapted strings. static_assert(std::is_same::type>::value, @@ -1050,9 +1044,6 @@ class locale_ref { template Locale get() const; }; -template -class context_base {}; - template struct get_type { typedef decltype( make_value(declval::type&>())) value_type; @@ -1077,14 +1068,13 @@ FMT_CONSTEXPR basic_format_arg make_arg(const T& value) { } template -inline typename std::enable_if>::type make_arg( - const T& value) { +inline FMT_ENABLE_IF_T(IS_PACKED, value) make_arg(const T& value) { return make_value(value); } template -inline typename std::enable_if>::type -make_arg(const T& value) { +inline FMT_ENABLE_IF_T(!IS_PACKED, basic_format_arg) + make_arg(const T& value) { return make_arg(value); } } // namespace internal @@ -1317,8 +1307,6 @@ struct wformat_args : basic_format_args { : basic_format_args(std::forward(arg)...) {} }; -#define FMT_ENABLE_IF_T(B, T) typename std::enable_if::type - #ifndef FMT_USE_ALIAS_TEMPLATES # define FMT_USE_ALIAS_TEMPLATES FMT_HAS_FEATURE(cxx_alias_templates) #endif @@ -1367,11 +1355,11 @@ template struct named_arg : named_arg_base { }; template -inline typename std::enable_if::value>::type -check_format_string(const S&) {} +inline FMT_ENABLE_IF_T(!is_compile_string::value) + check_format_string(const S&) {} template -typename std::enable_if::value>::type check_format_string( - S); +FMT_ENABLE_IF_T(is_compile_string::value) +check_format_string(S); template struct checked_args @@ -1430,8 +1418,8 @@ struct is_contiguous> : std::true_type {}; /** Formats a string and writes the output to ``out``. */ template -typename std::enable_if::value, - std::back_insert_iterator>::type +FMT_ENABLE_IF_T(is_contiguous::value, + std::back_insert_iterator) vformat_to(std::back_insert_iterator out, const S& format_str, basic_format_args::type> args) { internal::container_buffer buf(internal::get_container(out)); @@ -1440,13 +1428,13 @@ vformat_to(std::back_insert_iterator out, const S& format_str, } template -inline typename std::enable_if::value && - internal::is_string::value, - std::back_insert_iterator>::type -format_to(std::back_insert_iterator out, const S& format_str, - const Args&... args) { - internal::checked_args ca(format_str, args...); - return vformat_to(out, to_string_view(format_str), *ca); +inline FMT_ENABLE_IF_T( + is_contiguous::value&& internal::is_string::value, + std::back_insert_iterator) + format_to(std::back_insert_iterator out, const S& format_str, + const Args&... args) { + return vformat_to(out, to_string_view(format_str), + {internal::checked_args(format_str, args...)}); } template @@ -1471,7 +1459,7 @@ inline std::basic_string format(const S& format_str, const Args&... args) { return internal::vformat( to_string_view(format_str), - *internal::checked_args(format_str, args...)); + {internal::checked_args(format_str, args...)}); } FMT_API void vprint(std::FILE* f, string_view format_str, format_args args); diff --git a/include/fmt/printf.h b/include/fmt/printf.h index e84dbdad..e8b3049e 100644 --- a/include/fmt/printf.h +++ b/include/fmt/printf.h @@ -350,7 +350,6 @@ class basic_printf_context { }; private: - typedef internal::context_base base; typedef basic_format_specs format_specs; OutputIt out_;