19#if !defined(FMT_STATIC_THOUSANDS_SEPARATOR) && !defined(FMT_IMPORT_STD)
27using is_exotic_char = bool_constant<!std::is_same<T, char>::value>;
33 S, void_t<decltype(sizeof(detail::to_string_view(std::declval<S>())))>> {
34 using type = char_t<S>;
39 using type =
typename S::char_type;
47#ifndef FMT_STATIC_THOUSANDS_SEPARATOR
49 std::use_facet<std::numpunct<wchar_t>>(loc.get<std::locale>());
50 auto separator = std::wstring();
51 auto grouping = numpunct.grouping();
52 if (!grouping.empty()) separator = std::wstring(1, numpunct.thousands_sep());
63using wformat_context = buffered_context<wchar_t>;
67#if FMT_GCC_VERSION && FMT_GCC_VERSION < 409
72template <
typename... Args>
79template <>
struct is_char<wchar_t> : std::true_type {};
80template <>
struct is_char<char16_t> : std::true_type {};
81template <>
struct is_char<char32_t> : std::true_type {};
85struct is_char<char8_t> : bool_constant<detail::is_utf8_enabled()> {};
88template <
typename... T>
89constexpr auto make_wformat_args(T&... args)
90 ->
decltype(fmt::make_format_args<wformat_context>(args...)) {
91 return fmt::make_format_args<wformat_context>(args...);
94inline namespace literals {
95#if FMT_USE_USER_DEFINED_LITERALS && !FMT_USE_NONTYPE_TEMPLATE_ARGS
96constexpr auto operator""_a(
const wchar_t* s,
size_t)
97 -> detail::udl_arg<wchar_t> {
103template <
typename It,
typename Sentinel>
106 return {begin, end, sep};
109template <
typename Range>
113 return join(std::begin(range), std::end(range), sep);
117auto join(std::initializer_list<T> list,
wstring_view sep)
119 return join(std::begin(list), std::end(list), sep);
122template <
typename... T>
128template <
typename Char, FMT_ENABLE_IF(!std::is_same<Char,
char>::value)>
131 -> std::basic_string<Char> {
133 detail::vformat_to(buf, format_str, args);
134 return to_string(buf);
137template <
typename... T>
139 return vformat(fmt::wstring_view(fmt), fmt::make_wformat_args(args...));
142template <
typename OutputIt,
typename... T>
145 return vformat_to(out, fmt::wstring_view(fmt),
146 fmt::make_wformat_args(args...));
151template <
typename S,
typename... T,
152 typename Char = detail::format_string_char_t<S>,
153 FMT_ENABLE_IF(!std::is_same<Char, char>::value &&
154 !std::is_same<Char, wchar_t>::value)>
155auto format(
const S& format_str, T&&... args) -> std::basic_string<Char> {
156 return vformat(detail::to_string_view(format_str),
157 fmt::make_format_args<buffered_context<Char>>(args...));
160template <
typename Locale,
typename S,
161 typename Char = detail::format_string_char_t<S>,
162 FMT_ENABLE_IF(detail::is_locale<Locale>::value&&
163 detail::is_exotic_char<Char>::value)>
164inline auto vformat(
const Locale& loc,
const S& format_str,
166 -> std::basic_string<Char> {
167 return detail::vformat(loc, detail::to_string_view(format_str), args);
170template <
typename Locale,
typename S,
typename... T,
171 typename Char = detail::format_string_char_t<S>,
172 FMT_ENABLE_IF(detail::is_locale<Locale>::value&&
173 detail::is_exotic_char<Char>::value)>
174inline auto format(
const Locale& loc,
const S& format_str, T&&... args)
175 -> std::basic_string<Char> {
176 return detail::vformat(
177 loc, detail::to_string_view(format_str),
178 fmt::make_format_args<buffered_context<Char>>(args...));
181template <
typename OutputIt,
typename S,
182 typename Char = detail::format_string_char_t<S>,
184 detail::is_exotic_char<Char>::value)>
185auto vformat_to(OutputIt out,
const S& format_str,
187 auto&& buf = detail::get_buffer<Char>(out);
188 detail::vformat_to(buf, detail::to_string_view(format_str), args);
189 return detail::get_iterator(buf, out);
192template <
typename OutputIt,
typename S,
typename... T,
193 typename Char = detail::format_string_char_t<S>,
195 !std::is_same<Char, char>::value &&
196 !std::is_same<Char, wchar_t>::value)>
197inline auto format_to(OutputIt out,
const S& fmt, T&&... args) -> OutputIt {
198 return vformat_to(out, detail::to_string_view(fmt),
199 fmt::make_format_args<buffered_context<Char>>(args...));
202template <
typename Locale,
typename S,
typename OutputIt,
typename... Args,
203 typename Char = detail::format_string_char_t<S>,
205 detail::is_locale<Locale>::value&&
206 detail::is_exotic_char<Char>::value)>
207inline auto vformat_to(OutputIt out,
const Locale& loc,
const S& format_str,
210 auto&& buf = detail::get_buffer<Char>(out);
211 vformat_to(buf, detail::to_string_view(format_str), args,
213 return detail::get_iterator(buf, out);
216template <
typename OutputIt,
typename Locale,
typename S,
typename... T,
217 typename Char = detail::format_string_char_t<S>,
219 detail::is_locale<Locale>::value &&
220 detail::is_exotic_char<Char>::value>
221inline auto format_to(OutputIt out,
const Locale& loc,
const S& format_str,
223 typename std::enable_if<enable, OutputIt>::type {
224 return vformat_to(out, loc, detail::to_string_view(format_str),
225 fmt::make_format_args<buffered_context<Char>>(args...));
228template <
typename OutputIt,
typename Char,
typename... Args,
230 detail::is_exotic_char<Char>::value)>
231inline auto vformat_to_n(OutputIt out,
size_t n,
237 detail::vformat_to(buf, format_str, args);
238 return {buf.out(), buf.count()};
241template <
typename OutputIt,
typename S,
typename... T,
242 typename Char = detail::format_string_char_t<S>,
244 detail::is_exotic_char<Char>::value)>
245inline auto format_to_n(OutputIt out,
size_t n,
const S& fmt, T&&... args)
247 return vformat_to_n(out, n, fmt::basic_string_view<Char>(fmt),
248 fmt::make_format_args<buffered_context<Char>>(args...));
251template <
typename S,
typename... T,
252 typename Char = detail::format_string_char_t<S>,
253 FMT_ENABLE_IF(detail::is_exotic_char<Char>::value)>
254inline auto formatted_size(
const S& fmt, T&&... args) ->
size_t {
256 detail::vformat_to(buf, detail::to_string_view(fmt),
257 fmt::make_format_args<buffered_context<Char>>(args...));
263 detail::vformat_to(buf, fmt, args);
264 buf.push_back(L
'\0');
265 if (std::fputws(buf.data(), f) == -1)
266 FMT_THROW(system_error(errno, FMT_STRING(
"cannot write to file")));
270 vprint(stdout, fmt, args);
273template <
typename... T>
275 return vprint(f,
wstring_view(fmt), fmt::make_wformat_args(args...));
279 return vprint(
wstring_view(fmt), fmt::make_wformat_args(args...));
282template <
typename... T>
284 return print(f, L
"{}\n", fmt::format(fmt, std::forward<T>(args)...));
288 return print(L
"{}\n", fmt::format(fmt, std::forward<T>(args)...));
294 detail::vformat_to(buf, ts, fmt, args);
295 return fmt::to_string(buf);
298template <
typename... T>
301 return fmt::vformat(ts, fmt, fmt::make_wformat_args(args...));
304template <
typename... T>
305FMT_DEPRECATED
void print(std::FILE* f,
const text_style& ts,
307 vprint(f, ts, fmt, fmt::make_wformat_args(args...));
310template <
typename... T>
313 return print(stdout, ts, fmt, args...);
319template <
typename T>
inline auto to_wstring(
const T& value) -> std::wstring {
320 return format(FMT_STRING(L
"{}"), value);
Definition Common3D.hpp:137