From 473ba57fcfb355984dc79c7da29f8c347625fc05 Mon Sep 17 00:00:00 2001 From: vsol Date: Sat, 14 Mar 2020 20:51:41 +0300 Subject: [PATCH] Fixed comments Changed dispatching from tag to explicit `if`. However I would prefer tag-based dispatching if `if constexpr`, but the later is not available in older standards. --- include/fmt/core.h | 36 +++++++++++++++++++----------------- include/fmt/format.h | 4 ---- 2 files changed, 19 insertions(+), 21 deletions(-) diff --git a/include/fmt/core.h b/include/fmt/core.h index e4230347..388e7b97 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -272,6 +272,10 @@ struct monostate {}; namespace internal { +// A helper function to suppress bogus "conditional expression is constant" +// warnings. +template FMT_CONSTEXPR T const_check(T value) { return value; } + // A workaround for gcc 4.8 to make void_t work in a SFINAE context. template struct void_t_impl { using type = void; }; @@ -1674,11 +1678,20 @@ class dyn_arg_storage { template struct storage_node : storage_node_base<> { T value_; - FMT_CONSTEXPR explicit storage_node(const T& arg, owning_ptr&& next) + template + FMT_CONSTEXPR storage_node(const Arg& arg, owning_ptr&& next) : value_{arg} { // Must be initialised after value_ next_ = std::move(next); } + + template + FMT_CONSTEXPR storage_node(const basic_string_view& arg, + owning_ptr&& next) + : value_{arg.data(), arg.size()} { + // Must be initialised after value_ + next_ = std::move(next); + } }; owning_ptr head_{nullptr}; @@ -1739,20 +1752,6 @@ class dynamic_format_arg_store return internal::is_unpacked_bit | data_.size(); } - template const T& stored_value(const T& arg, std::false_type) { - return arg; - } - - template - const T& stored_value(const std::reference_wrapper& arg, std::false_type) { - return arg.get(); - } - - template - const stored_type& stored_value(const T& arg, std::true_type) { - return storage_.push>(arg); - } - template void emplace_arg(const T& arg) { data_.emplace_back(internal::make_arg(arg)); } @@ -1789,8 +1788,11 @@ class dynamic_format_arg_store static_assert( !std::is_base_of, T>::value, "Named arguments are not supported yet"); - emplace_arg(stored_value( - arg, typename internal::need_dyn_copy::type{})); + using need_copy_t = typename internal::need_dyn_copy::type; + if (internal::const_check(need_copy_t::value)) + emplace_arg(storage_.push>(arg)); + else + emplace_arg(arg); } /** diff --git a/include/fmt/format.h b/include/fmt/format.h index 07d4f5f8..5a479732 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -213,10 +213,6 @@ FMT_END_NAMESPACE FMT_BEGIN_NAMESPACE namespace internal { -// A helper function to suppress bogus "conditional expression is constant" -// warnings. -template FMT_CONSTEXPR T const_check(T value) { return value; } - // An equivalent of `*reinterpret_cast(&source)` that doesn't have // undefined behavior (e.g. due to type aliasing). // Example: uint64_t d = bit_cast(2.718);