Skip to content

Commit 481ed19

Browse files
committed
[libc++] Simplify the implementation of __formatter::__fill a bit
1 parent 8ea447b commit 481ed19

File tree

1 file changed

+29
-33
lines changed

1 file changed

+29
-33
lines changed

libcxx/include/__format/formatter_output.h

Lines changed: 29 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -151,45 +151,41 @@ _LIBCPP_HIDE_FROM_ABI _OutIt __fill(_OutIt __out_it, size_t __n, _CharT __value)
151151
}
152152
}
153153

154-
# if _LIBCPP_HAS_UNICODE
155154
template <__fmt_char_type _CharT, output_iterator<const _CharT&> _OutIt>
156-
requires(same_as<_CharT, char>)
157155
_LIBCPP_HIDE_FROM_ABI _OutIt __fill(_OutIt __out_it, size_t __n, __format_spec::__code_point<_CharT> __value) {
158-
std::size_t __bytes = std::countl_one(static_cast<unsigned char>(__value.__data[0]));
159-
if (__bytes == 0)
160-
return __formatter::__fill(std::move(__out_it), __n, __value.__data[0]);
161-
162-
for (size_t __i = 0; __i < __n; ++__i)
163-
__out_it = __formatter::__copy(
164-
std::addressof(__value.__data[0]), std::addressof(__value.__data[0]) + __bytes, std::move(__out_it));
165-
return __out_it;
166-
}
167-
156+
# if _LIBCPP_HAS_UNICODE
157+
if constexpr (same_as<_CharT, char>) {
158+
std::size_t __bytes = std::countl_one(static_cast<unsigned char>(__value.__data[0]));
159+
if (__bytes == 0)
160+
return __formatter::__fill(std::move(__out_it), __n, __value.__data[0]);
161+
162+
for (size_t __i = 0; __i < __n; ++__i)
163+
__out_it = __formatter::__copy(
164+
std::addressof(__value.__data[0]), std::addressof(__value.__data[0]) + __bytes, std::move(__out_it));
165+
return __out_it;
168166
# if _LIBCPP_HAS_WIDE_CHARACTERS
169-
template <__fmt_char_type _CharT, output_iterator<const _CharT&> _OutIt>
170-
requires(same_as<_CharT, wchar_t> && sizeof(wchar_t) == 2)
171-
_LIBCPP_HIDE_FROM_ABI _OutIt __fill(_OutIt __out_it, size_t __n, __format_spec::__code_point<_CharT> __value) {
172-
if (!__unicode::__is_high_surrogate(__value.__data[0]))
173-
return __formatter::__fill(std::move(__out_it), __n, __value.__data[0]);
174-
175-
for (size_t __i = 0; __i < __n; ++__i)
176-
__out_it = __formatter::__copy(
177-
std::addressof(__value.__data[0]), std::addressof(__value.__data[0]) + 2, std::move(__out_it));
178-
return __out_it;
179-
}
180-
181-
template <__fmt_char_type _CharT, output_iterator<const _CharT&> _OutIt>
182-
requires(same_as<_CharT, wchar_t> && sizeof(wchar_t) == 4)
183-
_LIBCPP_HIDE_FROM_ABI _OutIt __fill(_OutIt __out_it, size_t __n, __format_spec::__code_point<_CharT> __value) {
184-
return __formatter::__fill(std::move(__out_it), __n, __value.__data[0]);
185-
}
167+
} else if constexpr (same_as<_CharT, wchar_t>) {
168+
if constexpr (sizeof(wchar_t) == 2) {
169+
if (!__unicode::__is_high_surrogate(__value.__data[0]))
170+
return __formatter::__fill(std::move(__out_it), __n, __value.__data[0]);
171+
172+
for (size_t __i = 0; __i < __n; ++__i)
173+
__out_it = __formatter::__copy(
174+
std::addressof(__value.__data[0]), std::addressof(__value.__data[0]) + 2, std::move(__out_it));
175+
return __out_it;
176+
} else if constexpr (sizeof(wchar_t) == 4) {
177+
return __formatter::__fill(std::move(__out_it), __n, __value.__data[0]);
178+
} else {
179+
static_assert(false, "expected sizeof(wchar_t) to be 2 or 4");
180+
}
186181
# endif // _LIBCPP_HAS_WIDE_CHARACTERS
187-
# else // _LIBCPP_HAS_UNICODE
188-
template <__fmt_char_type _CharT, output_iterator<const _CharT&> _OutIt>
189-
_LIBCPP_HIDE_FROM_ABI _OutIt __fill(_OutIt __out_it, size_t __n, __format_spec::__code_point<_CharT> __value) {
182+
} else {
183+
static_assert(false, "Unexpected CharT");
184+
}
185+
# else // _LIBCPP_HAS_UNICODE
190186
return __formatter::__fill(std::move(__out_it), __n, __value.__data[0]);
187+
# endif // _LIBCPP_HAS_UNICODE
191188
}
192-
# endif // _LIBCPP_HAS_UNICODE
193189

194190
/// Writes the input to the output with the required padding.
195191
///

0 commit comments

Comments
 (0)