From 209db68b289f3bade9d3e762b3fe96c7c4013ec5 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Fri, 7 Jun 2019 13:58:11 -0700 Subject: [PATCH] Get rid of FMT_CONSTEXPR11 --- include/fmt/core.h | 65 +++++++++++--------------------------------- include/fmt/format.h | 7 ----- 2 files changed, 16 insertions(+), 56 deletions(-) diff --git a/include/fmt/core.h b/include/fmt/core.h index 517eb387..f67b34c9 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -70,16 +70,6 @@ # define FMT_CONSTEXPR_DECL #endif -#ifndef FMT_USE_CONSTEXPR11 -# define FMT_USE_CONSTEXPR11 \ - (FMT_USE_CONSTEXPR || FMT_GCC_VERSION >= 406 || FMT_MSC_VER >= 1900) -#endif -#if FMT_USE_CONSTEXPR11 -# define FMT_CONSTEXPR11 constexpr -#else -# define FMT_CONSTEXPR11 -#endif - #ifndef FMT_OVERRIDE # if FMT_HAS_FEATURE(cxx_override) || \ (FMT_GCC_VERSION >= 408 && FMT_HAS_GXX_CXX11) || FMT_MSC_VER >= 1900 @@ -451,7 +441,11 @@ class basic_parse_context : private ErrorHandler { } // Returns the next argument index. - FMT_CONSTEXPR unsigned next_arg_id(); + FMT_CONSTEXPR unsigned next_arg_id() { + if (next_arg_id_ >= 0) return internal::to_unsigned(next_arg_id_++); + on_error("cannot switch from manual to automatic argument indexing"); + return 0; + } FMT_CONSTEXPR bool check_arg_id(unsigned) { if (next_arg_id_ > 0) { @@ -827,7 +821,7 @@ FMT_MAKE_VALUE(cstring_type, unsigned char*, const unsigned char*) FMT_MAKE_VALUE_SAME(cstring_type, const unsigned char*) template ::value)> -FMT_CONSTEXPR11 init, string_type> +constexpr init, string_type> make_value(const S& val) { static_assert(std::is_same>::value, "mismatch between char-types of context and argument"); @@ -1056,12 +1050,12 @@ template struct get_type { static const type value = value_type::type_tag; }; -template FMT_CONSTEXPR11 unsigned long long get_types() { +template constexpr unsigned long long get_types() { return 0; } template -FMT_CONSTEXPR11 unsigned long long get_types() { +constexpr unsigned long long get_types() { return get_type::value | (get_types() << 4); } @@ -1150,53 +1144,26 @@ using wformat_context = buffer_context; */ template class format_arg_store { private: - static const size_t NUM_ARGS = sizeof...(Args); + static const size_t num_args = sizeof...(Args); + static const bool is_packed = num_args < internal::max_packed_args; - // Packed is a macro on MinGW so use IS_PACKED instead. - static const bool IS_PACKED = NUM_ARGS < internal::max_packed_args; - - using value_type = conditional_t, + using value_type = conditional_t, basic_format_arg>; // If the arguments are not packed, add one more element to mark the end. - static const size_t DATA_SIZE = - NUM_ARGS + (IS_PACKED && NUM_ARGS != 0 ? 0 : 1); - value_type data_[DATA_SIZE]; + value_type data_[num_args + (!is_packed || num_args == 0 ? 1 : 0)]; friend class basic_format_args; - static FMT_CONSTEXPR11 unsigned long long get_types() { - return IS_PACKED ? internal::get_types() - : internal::is_unpacked_bit | NUM_ARGS; - } - public: -#if FMT_USE_CONSTEXPR11 - static FMT_CONSTEXPR11 unsigned long long TYPES = get_types(); -#else - static const unsigned long long TYPES; -#endif + static constexpr unsigned long long TYPES = + is_packed ? internal::get_types() + : internal::is_unpacked_bit | num_args; -#if (FMT_GCC_VERSION && FMT_GCC_VERSION <= 405) || \ - (FMT_MSC_VER && FMT_MSC_VER <= 1800) - // Workaround array initialization issues in gcc <= 4.5 and MSVC <= 2013. - format_arg_store(const Args&... args) { - value_type init[DATA_SIZE] = { - internal::make_arg(args)...}; - std::memcpy(data_, init, sizeof(init)); - } -#else format_arg_store(const Args&... args) - : data_{internal::make_arg(args)...} {} -#endif + : data_{internal::make_arg(args)...} {} }; -#if !FMT_USE_CONSTEXPR11 -template -const unsigned long long format_arg_store::TYPES = - get_types(); -#endif - /** \rst Constructs an `~fmt::format_arg_store` object that contains references to diff --git a/include/fmt/format.h b/include/fmt/format.h index 07b14e0c..f1dedd9d 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -1112,13 +1112,6 @@ struct basic_format_specs : align_spec, core_format_specs { typedef basic_format_specs format_specs; -template -FMT_CONSTEXPR unsigned basic_parse_context::next_arg_id() { - if (next_arg_id_ >= 0) return internal::to_unsigned(next_arg_id_++); - on_error("cannot switch from manual to automatic argument indexing"); - return 0; -} - namespace internal { namespace grisu_options {