25 template <
typename T>
const T& unwrap(
const T& v) {
return v; }
26 template <
typename T>
const T& unwrap(
const std::reference_wrapper<T>& v) {
27 return static_cast<const T&
>(v);
34 template <
typename =
void>
struct node {
35 virtual ~node() =
default;
36 std::unique_ptr<node<>> next;
39 template <
typename T>
struct typed_node : node<> {
42 template <
typename Arg>
43 FMT_CONSTEXPR typed_node(
const Arg& arg) : value(arg) {}
45 template <
typename Char>
50 std::unique_ptr<node<>> head_;
53 template <
typename T,
typename Arg>
const T& push(
const Arg& arg) {
54 auto new_node = std::unique_ptr<typed_node<T>>(
new typed_node<T>(arg));
55 auto&
value = new_node->value;
56 new_node->next = std::move(head_);
57 head_ = std::move(new_node);
73 template <
typename Context>
75 #if FMT_GCC_VERSION && FMT_GCC_VERSION < 409
81 using char_type =
typename Context::char_type;
83 template <
typename T>
struct need_copy {
84 static constexpr detail::type mapped_type =
85 detail::mapped_type_constant<T, Context>::value;
89 std::is_same<T, basic_string_view<char_type>>
::value ||
90 std::is_same<T, detail::std_string_view<char_type>>
::value ||
91 (mapped_type != detail::type::cstring_type &&
92 mapped_type != detail::type::string_type &&
93 mapped_type != detail::type::custom_type))
98 using stored_type = conditional_t<detail::is_string<T>::value &&
99 !has_formatter<T, Context>::value &&
101 std::basic_string<char_type>, T>;
104 std::vector<basic_format_arg<Context>> data_;
105 std::vector<detail::named_arg_info<char_type>> named_info_;
113 unsigned long long get_types()
const {
114 return detail::is_unpacked_bit | data_.size() |
117 :
static_cast<unsigned long long>(detail::has_named_args_bit));
121 return named_info_.empty() ? data_.data() : data_.data() + 1;
124 template <
typename T>
void emplace_arg(
const T& arg) {
125 data_.emplace_back(detail::make_arg<Context>(arg));
128 template <
typename T>
129 void emplace_arg(
const detail::named_arg<char_type, T>& arg) {
130 if (named_info_.empty()) {
131 constexpr
const detail::named_arg_info<char_type>* zero_ptr{
nullptr};
132 data_.insert(data_.begin(), {zero_ptr, 0});
134 data_.emplace_back(detail::make_arg<Context>(detail::unwrap(arg.value)));
135 auto pop_one = [](std::vector<basic_format_arg<Context>>* data) {
138 std::unique_ptr<std::vector<basic_format_arg<Context>>, decltype(pop_one)>
139 guard{&data_, pop_one};
140 named_info_.push_back({arg.name,
static_cast<int>(data_.size() - 2u)});
141 data_[0].value_.named_args = {named_info_.data(), named_info_.size()};
166 if (detail::const_check(need_copy<T>::value))
167 emplace_arg(dynamic_args_.push<stored_type<T>>(arg));
169 emplace_arg(detail::unwrap(arg));
187 template <
typename T>
void push_back(std::reference_wrapper<T> arg) {
190 "objects of built-in types and string views are always copied");
191 emplace_arg(arg.get());
199 template <
typename T>
200 void push_back(
const detail::named_arg<char_type, T>& arg) {
201 const char_type* arg_name =
202 dynamic_args_.push<std::basic_string<char_type>>(arg.name).c_str();
203 if (detail::const_check(need_copy<T>::value)) {
205 fmt::arg(arg_name, dynamic_args_.push<stored_type<T>>(arg.value)));
207 emplace_arg(fmt::arg(arg_name, arg.value));
224 void reserve(
size_t new_cap,
size_t new_cap_named) {
225 FMT_ASSERT(new_cap >= new_cap_named,
226 "Set of arguments includes set of named arguments");
227 data_.reserve(new_cap);
228 named_info_.reserve(new_cap_named);
234 #endif // FMT_ARGS_H_
constexpr auto data() const FMT_NOEXCEPT -> const Char *
Returns a pointer to the string data.
Definition: core.h:492
constexpr auto size() const FMT_NOEXCEPT -> size_t
Returns the string size.
Definition: core.h:495
Definition: sc_data.cpp:17
An implementation of std::basic_string_view for pre-C++17.
Definition: core.h:448