Skip to content

Commit d02714d

Browse files
Avoid forward declaration for __basic_format_arg_value
1 parent d7b1167 commit d02714d

File tree

1 file changed

+72
-75
lines changed

1 file changed

+72
-75
lines changed

libcxx/include/__format/format_arg.h

Lines changed: 72 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,79 @@ enum class __directly_visit_i128 : bool { __no, __yes };
104104

105105
} // namespace __format
106106

107+
/// Contains the values used in basic_format_arg.
108+
///
109+
/// This is a separate type so it's possible to store the values and types in
110+
/// separate arrays.
107111
template <class _Context>
108-
class __basic_format_arg_value;
112+
class __basic_format_arg_value {
113+
using _CharT _LIBCPP_NODEBUG = typename _Context::char_type;
114+
115+
public:
116+
/// Contains the implementation for basic_format_arg::handle.
117+
struct __handle {
118+
template <class _Tp>
119+
_LIBCPP_HIDE_FROM_ABI explicit __handle(_Tp& __v) noexcept
120+
: __ptr_(std::addressof(__v)),
121+
__format_([](basic_format_parse_context<_CharT>& __parse_ctx, _Context& __ctx, const void* __ptr) {
122+
using _Dp = remove_const_t<_Tp>;
123+
using _Qp = conditional_t<__formattable_with<const _Dp, _Context>, const _Dp, _Dp>;
124+
static_assert(__formattable_with<_Qp, _Context>, "Mandated by [format.arg]/10");
125+
126+
typename _Context::template formatter_type<_Dp> __f;
127+
__parse_ctx.advance_to(__f.parse(__parse_ctx));
128+
__ctx.advance_to(__f.format(*const_cast<_Qp*>(static_cast<const _Dp*>(__ptr)), __ctx));
129+
}) {}
130+
131+
const void* __ptr_;
132+
void (*__format_)(basic_format_parse_context<_CharT>&, _Context&, const void*);
133+
};
134+
135+
union {
136+
monostate __monostate_;
137+
bool __boolean_;
138+
_CharT __char_type_;
139+
int __int_;
140+
unsigned __unsigned_;
141+
long long __long_long_;
142+
unsigned long long __unsigned_long_long_;
143+
# if _LIBCPP_HAS_INT128
144+
__int128_t __i128_;
145+
__uint128_t __u128_;
146+
# endif
147+
float __float_;
148+
double __double_;
149+
long double __long_double_;
150+
const _CharT* __const_char_type_ptr_;
151+
basic_string_view<_CharT> __string_view_;
152+
const void* __ptr_;
153+
__handle __handle_;
154+
};
155+
156+
// These constructors contain the exact storage type used. If adjustments are
157+
// required, these will be done in __create_format_arg.
158+
159+
_LIBCPP_HIDE_FROM_ABI __basic_format_arg_value() noexcept : __monostate_() {}
160+
_LIBCPP_HIDE_FROM_ABI __basic_format_arg_value(bool __value) noexcept : __boolean_(__value) {}
161+
_LIBCPP_HIDE_FROM_ABI __basic_format_arg_value(_CharT __value) noexcept : __char_type_(__value) {}
162+
_LIBCPP_HIDE_FROM_ABI __basic_format_arg_value(int __value) noexcept : __int_(__value) {}
163+
_LIBCPP_HIDE_FROM_ABI __basic_format_arg_value(unsigned __value) noexcept : __unsigned_(__value) {}
164+
_LIBCPP_HIDE_FROM_ABI __basic_format_arg_value(long long __value) noexcept : __long_long_(__value) {}
165+
_LIBCPP_HIDE_FROM_ABI __basic_format_arg_value(unsigned long long __value) noexcept
166+
: __unsigned_long_long_(__value) {}
167+
# if _LIBCPP_HAS_INT128
168+
_LIBCPP_HIDE_FROM_ABI __basic_format_arg_value(__int128_t __value) noexcept : __i128_(__value) {}
169+
_LIBCPP_HIDE_FROM_ABI __basic_format_arg_value(__uint128_t __value) noexcept : __u128_(__value) {}
170+
# endif
171+
_LIBCPP_HIDE_FROM_ABI __basic_format_arg_value(float __value) noexcept : __float_(__value) {}
172+
_LIBCPP_HIDE_FROM_ABI __basic_format_arg_value(double __value) noexcept : __double_(__value) {}
173+
_LIBCPP_HIDE_FROM_ABI __basic_format_arg_value(long double __value) noexcept : __long_double_(__value) {}
174+
_LIBCPP_HIDE_FROM_ABI __basic_format_arg_value(const _CharT* __value) noexcept : __const_char_type_ptr_(__value) {}
175+
_LIBCPP_HIDE_FROM_ABI __basic_format_arg_value(basic_string_view<_CharT> __value) noexcept
176+
: __string_view_(__value) {}
177+
_LIBCPP_HIDE_FROM_ABI __basic_format_arg_value(const void* __value) noexcept : __ptr_(__value) {}
178+
_LIBCPP_HIDE_FROM_ABI __basic_format_arg_value(__handle&& __value) noexcept : __handle_(std::move(__value)) {}
179+
};
109180

110181
// This function is not user observable, so it can directly use the non-standard
111182
// types of the "variant". See __arg_t for more details.
@@ -227,80 +298,6 @@ _LIBCPP_HIDE_FROM_ABI _Rp __visit_format_arg(_Visitor&& __vis, basic_format_arg<
227298

228299
# endif // _LIBCPP_STD_VER >= 26 && _LIBCPP_HAS_EXPLICIT_THIS_PARAMETER
229300

230-
/// Contains the values used in basic_format_arg.
231-
///
232-
/// This is a separate type so it's possible to store the values and types in
233-
/// separate arrays.
234-
template <class _Context>
235-
class __basic_format_arg_value {
236-
using _CharT _LIBCPP_NODEBUG = typename _Context::char_type;
237-
238-
public:
239-
/// Contains the implementation for basic_format_arg::handle.
240-
struct __handle {
241-
template <class _Tp>
242-
_LIBCPP_HIDE_FROM_ABI explicit __handle(_Tp& __v) noexcept
243-
: __ptr_(std::addressof(__v)),
244-
__format_([](basic_format_parse_context<_CharT>& __parse_ctx, _Context& __ctx, const void* __ptr) {
245-
using _Dp = remove_const_t<_Tp>;
246-
using _Qp = conditional_t<__formattable_with<const _Dp, _Context>, const _Dp, _Dp>;
247-
static_assert(__formattable_with<_Qp, _Context>, "Mandated by [format.arg]/10");
248-
249-
typename _Context::template formatter_type<_Dp> __f;
250-
__parse_ctx.advance_to(__f.parse(__parse_ctx));
251-
__ctx.advance_to(__f.format(*const_cast<_Qp*>(static_cast<const _Dp*>(__ptr)), __ctx));
252-
}) {}
253-
254-
const void* __ptr_;
255-
void (*__format_)(basic_format_parse_context<_CharT>&, _Context&, const void*);
256-
};
257-
258-
union {
259-
monostate __monostate_;
260-
bool __boolean_;
261-
_CharT __char_type_;
262-
int __int_;
263-
unsigned __unsigned_;
264-
long long __long_long_;
265-
unsigned long long __unsigned_long_long_;
266-
# if _LIBCPP_HAS_INT128
267-
__int128_t __i128_;
268-
__uint128_t __u128_;
269-
# endif
270-
float __float_;
271-
double __double_;
272-
long double __long_double_;
273-
const _CharT* __const_char_type_ptr_;
274-
basic_string_view<_CharT> __string_view_;
275-
const void* __ptr_;
276-
__handle __handle_;
277-
};
278-
279-
// These constructors contain the exact storage type used. If adjustments are
280-
// required, these will be done in __create_format_arg.
281-
282-
_LIBCPP_HIDE_FROM_ABI __basic_format_arg_value() noexcept : __monostate_() {}
283-
_LIBCPP_HIDE_FROM_ABI __basic_format_arg_value(bool __value) noexcept : __boolean_(__value) {}
284-
_LIBCPP_HIDE_FROM_ABI __basic_format_arg_value(_CharT __value) noexcept : __char_type_(__value) {}
285-
_LIBCPP_HIDE_FROM_ABI __basic_format_arg_value(int __value) noexcept : __int_(__value) {}
286-
_LIBCPP_HIDE_FROM_ABI __basic_format_arg_value(unsigned __value) noexcept : __unsigned_(__value) {}
287-
_LIBCPP_HIDE_FROM_ABI __basic_format_arg_value(long long __value) noexcept : __long_long_(__value) {}
288-
_LIBCPP_HIDE_FROM_ABI __basic_format_arg_value(unsigned long long __value) noexcept
289-
: __unsigned_long_long_(__value) {}
290-
# if _LIBCPP_HAS_INT128
291-
_LIBCPP_HIDE_FROM_ABI __basic_format_arg_value(__int128_t __value) noexcept : __i128_(__value) {}
292-
_LIBCPP_HIDE_FROM_ABI __basic_format_arg_value(__uint128_t __value) noexcept : __u128_(__value) {}
293-
# endif
294-
_LIBCPP_HIDE_FROM_ABI __basic_format_arg_value(float __value) noexcept : __float_(__value) {}
295-
_LIBCPP_HIDE_FROM_ABI __basic_format_arg_value(double __value) noexcept : __double_(__value) {}
296-
_LIBCPP_HIDE_FROM_ABI __basic_format_arg_value(long double __value) noexcept : __long_double_(__value) {}
297-
_LIBCPP_HIDE_FROM_ABI __basic_format_arg_value(const _CharT* __value) noexcept : __const_char_type_ptr_(__value) {}
298-
_LIBCPP_HIDE_FROM_ABI __basic_format_arg_value(basic_string_view<_CharT> __value) noexcept
299-
: __string_view_(__value) {}
300-
_LIBCPP_HIDE_FROM_ABI __basic_format_arg_value(const void* __value) noexcept : __ptr_(__value) {}
301-
_LIBCPP_HIDE_FROM_ABI __basic_format_arg_value(__handle&& __value) noexcept : __handle_(std::move(__value)) {}
302-
};
303-
304301
template <class _Context>
305302
class _LIBCPP_NO_SPECIALIZATIONS basic_format_arg {
306303
public:

0 commit comments

Comments
 (0)