From 5f6f93b7e511811e7d52159583a4a874b3dcd6b4 Mon Sep 17 00:00:00 2001 From: vsol Date: Thu, 7 May 2020 21:46:52 +0300 Subject: [PATCH] Minor fixes. --- include/fmt/core.h | 43 ++++++++----------------------------------- 1 file changed, 8 insertions(+), 35 deletions(-) diff --git a/include/fmt/core.h b/include/fmt/core.h index f2613d91..ef1534b7 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -1454,33 +1454,6 @@ struct named_arg : view, named_arg_base { : named_arg_base(name), value(val) {} }; -// scope_exit is proposed in TS v3. This implementation is slightly different -// because without deduction guide there's no easy way to construct from lambda. -// Factory template function is needed (see make_scope_exit). -// Move assignment is disabled because of unclear semantic: whether to call -// currently assigned functor or not... -template class scope_exit { - bool passive_{false}; - F func_; - - public: - explicit scope_exit(F&& f) noexcept : func_(std::forward(f)) {} - ~scope_exit() { - if (!passive_) func_(); - } - scope_exit(const F&) = delete; - scope_exit(scope_exit&& rhs) noexcept : func_{std::move(rhs.func_)} { - rhs.release(); - } - const scope_exit& operator=(const scope_exit&) = delete; - const scope_exit& operator=(scope_exit&&) = delete; - void release() noexcept { passive_ = true; } -}; - -template scope_exit make_scope_exit(F&& f) { - return scope_exit{std::forward(f)}; -} - } // namespace internal /** @@ -1565,16 +1538,16 @@ class dynamic_format_arg_store template void emplace_arg(const internal::named_arg& arg) { if (named_info_.empty()) { - data_.insert( - data_.begin(), - {static_cast*>(nullptr), - 0}); + constexpr const internal::named_arg_info* zero_ptr{nullptr}; + data_.insert(data_.begin(), {zero_ptr, 0}); } data_.emplace_back(internal::make_arg( static_cast&>(arg.value))); - - auto guard = - internal::make_scope_exit([this]() { this->data_.pop_back(); }); + auto pop_one = [](std::vector>* data) { + data->pop_back(); + }; + std::unique_ptr>, decltype(pop_one)> + guard{&data_, pop_one}; named_info_.push_back({arg.name, static_cast(data_.size() - 2u)}); data_[0].value_.named_args = {named_info_.data(), named_info_.size()}; guard.release(); @@ -1631,7 +1604,7 @@ class dynamic_format_arg_store */ template void push_back(std::reference_wrapper arg) { static_assert( - internal::is_named_arg::type>::value || + internal::is_named_arg::type>::value || need_copy::value, "objects of built-in types and string views are always copied"); emplace_arg(arg.get());