blob: db7d7d5598dd8f341c8f90ccc0f639b377e939b2 [file] [log] [blame]
Louis Dionne9bd93882021-11-17 16:25:01 -05001//===----------------------------------------------------------------------===//
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +00002//
Chandler Carruthd2012102019-01-19 10:56:40 +00003// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +00006//
7//===----------------------------------------------------------------------===//
8
Arthur O'Dwyercf9bf392022-02-11 13:00:39 -05009#include <__debug>
10#include <cerrno>
11#include <charconv>
12#include <cstdlib>
13#include <limits>
14#include <stdexcept>
Howard Hinnant84f697e2013-07-23 16:05:56 +000015#include <stdio.h>
Arthur O'Dwyercf9bf392022-02-11 13:00:39 -050016#include <string>
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +000017
Louis Dionne89258142021-08-23 15:32:36 -040018#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
Arthur O'Dwyercf9bf392022-02-11 13:00:39 -050019# include <cwchar>
Louis Dionne89258142021-08-23 15:32:36 -040020#endif
21
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +000022_LIBCPP_BEGIN_NAMESPACE_STD
23
Nikolas Klausera2453e82022-02-02 20:15:40 +010024#ifndef _LIBCPP_ABI_DO_NOT_EXPORT_BASIC_STRING_COMMON
25
26template <bool>
27struct __basic_string_common;
28
29// The struct isn't declared anymore in the headers. It's only here for ABI compatibility.
30template <>
31struct __basic_string_common<true> {
32 _LIBCPP_NORETURN _LIBCPP_EXPORTED_FROM_ABI void __throw_length_error() const;
33 _LIBCPP_NORETURN _LIBCPP_EXPORTED_FROM_ABI void __throw_out_of_range() const;
34};
35
Louis Dionneb6aabd92021-08-19 12:21:06 -040036void __basic_string_common<true>::__throw_length_error() const {
Nikolas Klausera2453e82022-02-02 20:15:40 +010037 std::__throw_length_error("basic_string");
38}
39void __basic_string_common<true>::__throw_out_of_range() const {
40 std::__throw_out_of_range("basic_string");
Louis Dionneb6aabd92021-08-19 12:21:06 -040041}
42
Nikolas Klausera2453e82022-02-02 20:15:40 +010043#endif // _LIBCPP_ABI_DO_NOT_EXPORT_BASIC_STRING_COMMON
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +000044
Louis Dionne732192e2021-06-09 09:41:27 -040045#define _LIBCPP_EXTERN_TEMPLATE_DEFINE(...) template __VA_ARGS__;
Martijn Velsb17d5802020-03-02 10:11:35 -050046#ifdef _LIBCPP_ABI_STRING_OPTIMIZED_EXTERNAL_INSTANTIATION
Louis Dionne89258142021-08-23 15:32:36 -040047 _LIBCPP_STRING_UNSTABLE_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE_DEFINE, char)
48# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
49 _LIBCPP_STRING_UNSTABLE_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE_DEFINE, wchar_t)
50# endif
Martijn Vels1e63ba02020-02-19 16:27:50 -050051#else
Louis Dionne89258142021-08-23 15:32:36 -040052 _LIBCPP_STRING_V1_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE_DEFINE, char)
53# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
54 _LIBCPP_STRING_V1_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE_DEFINE, wchar_t)
55# endif
Martijn Vels1e63ba02020-02-19 16:27:50 -050056#endif
Louis Dionne732192e2021-06-09 09:41:27 -040057#undef _LIBCPP_EXTERN_TEMPLATE_DEFINE
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +000058
Louis Dionne732192e2021-06-09 09:41:27 -040059template string operator+<char, char_traits<char>, allocator<char> >(char const*, string const&);
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +000060
Howard Hinnantae2378a2013-05-16 17:13:40 +000061namespace
62{
63
64template<typename T>
65inline
66void throw_helper( const string& msg )
67{
68#ifndef _LIBCPP_NO_EXCEPTIONS
69 throw T( msg );
70#else
Ed Schouten7a441452015-03-10 07:57:43 +000071 fprintf(stderr, "%s\n", msg.c_str());
Marshall Clow8fea1612016-08-25 15:09:01 +000072 _VSTD::abort();
Howard Hinnantae2378a2013-05-16 17:13:40 +000073#endif
74}
75
76inline
77void throw_from_string_out_of_range( const string& func )
78{
79 throw_helper<out_of_range>(func + ": out of range");
80}
81
82inline
83void throw_from_string_invalid_arg( const string& func )
84{
85 throw_helper<invalid_argument>(func + ": no conversion");
86}
87
88// as_integer
89
90template<typename V, typename S, typename F>
91inline
92V
93as_integer_helper(const string& func, const S& str, size_t* idx, int base, F f)
94{
Eric Fiselier002dc672014-11-14 22:23:57 +000095 typename S::value_type* ptr = nullptr;
Howard Hinnantae2378a2013-05-16 17:13:40 +000096 const typename S::value_type* const p = str.c_str();
97 typename remove_reference<decltype(errno)>::type errno_save = errno;
98 errno = 0;
99 V r = f(p, &ptr, base);
100 swap(errno, errno_save);
101 if (errno_save == ERANGE)
102 throw_from_string_out_of_range(func);
103 if (ptr == p)
104 throw_from_string_invalid_arg(func);
105 if (idx)
106 *idx = static_cast<size_t>(ptr - p);
107 return r;
108}
109
110template<typename V, typename S>
111inline
112V
113as_integer(const string& func, const S& s, size_t* idx, int base);
114
115// string
116template<>
117inline
118int
119as_integer(const string& func, const string& s, size_t* idx, int base )
120{
Joerg Sonnenbergere211bc02013-09-17 08:46:53 +0000121 // Use long as no Standard string to integer exists.
Howard Hinnantae2378a2013-05-16 17:13:40 +0000122 long r = as_integer_helper<long>( func, s, idx, base, strtol );
123 if (r < numeric_limits<int>::min() || numeric_limits<int>::max() < r)
124 throw_from_string_out_of_range(func);
125 return static_cast<int>(r);
126}
127
128template<>
129inline
130long
131as_integer(const string& func, const string& s, size_t* idx, int base )
132{
133 return as_integer_helper<long>( func, s, idx, base, strtol );
134}
135
136template<>
137inline
138unsigned long
139as_integer( const string& func, const string& s, size_t* idx, int base )
140{
141 return as_integer_helper<unsigned long>( func, s, idx, base, strtoul );
142}
143
144template<>
145inline
146long long
147as_integer( const string& func, const string& s, size_t* idx, int base )
148{
149 return as_integer_helper<long long>( func, s, idx, base, strtoll );
150}
151
152template<>
153inline
154unsigned long long
155as_integer( const string& func, const string& s, size_t* idx, int base )
156{
157 return as_integer_helper<unsigned long long>( func, s, idx, base, strtoull );
158}
159
Louis Dionne89258142021-08-23 15:32:36 -0400160#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
Howard Hinnantae2378a2013-05-16 17:13:40 +0000161// wstring
162template<>
163inline
164int
165as_integer( const string& func, const wstring& s, size_t* idx, int base )
166{
167 // Use long as no Stantard string to integer exists.
168 long r = as_integer_helper<long>( func, s, idx, base, wcstol );
169 if (r < numeric_limits<int>::min() || numeric_limits<int>::max() < r)
170 throw_from_string_out_of_range(func);
171 return static_cast<int>(r);
172}
173
174template<>
175inline
176long
177as_integer( const string& func, const wstring& s, size_t* idx, int base )
178{
179 return as_integer_helper<long>( func, s, idx, base, wcstol );
180}
181
182template<>
183inline
184unsigned long
185as_integer( const string& func, const wstring& s, size_t* idx, int base )
186{
187 return as_integer_helper<unsigned long>( func, s, idx, base, wcstoul );
188}
189
190template<>
191inline
192long long
193as_integer( const string& func, const wstring& s, size_t* idx, int base )
194{
195 return as_integer_helper<long long>( func, s, idx, base, wcstoll );
196}
197
198template<>
199inline
200unsigned long long
201as_integer( const string& func, const wstring& s, size_t* idx, int base )
202{
203 return as_integer_helper<unsigned long long>( func, s, idx, base, wcstoull );
204}
Louis Dionne89258142021-08-23 15:32:36 -0400205#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
Howard Hinnantae2378a2013-05-16 17:13:40 +0000206
207// as_float
208
Marshall Clow54e41492019-06-10 23:20:01 +0000209template<typename V, typename S, typename F>
Howard Hinnantae2378a2013-05-16 17:13:40 +0000210inline
211V
212as_float_helper(const string& func, const S& str, size_t* idx, F f )
213{
Eric Fiselier002dc672014-11-14 22:23:57 +0000214 typename S::value_type* ptr = nullptr;
Howard Hinnantae2378a2013-05-16 17:13:40 +0000215 const typename S::value_type* const p = str.c_str();
216 typename remove_reference<decltype(errno)>::type errno_save = errno;
217 errno = 0;
218 V r = f(p, &ptr);
219 swap(errno, errno_save);
220 if (errno_save == ERANGE)
221 throw_from_string_out_of_range(func);
222 if (ptr == p)
223 throw_from_string_invalid_arg(func);
224 if (idx)
225 *idx = static_cast<size_t>(ptr - p);
226 return r;
227}
228
229template<typename V, typename S>
230inline
231V as_float( const string& func, const S& s, size_t* idx = nullptr );
232
233template<>
234inline
235float
236as_float( const string& func, const string& s, size_t* idx )
237{
238 return as_float_helper<float>( func, s, idx, strtof );
239}
240
241template<>
242inline
243double
244as_float(const string& func, const string& s, size_t* idx )
245{
246 return as_float_helper<double>( func, s, idx, strtod );
247}
248
249template<>
250inline
251long double
252as_float( const string& func, const string& s, size_t* idx )
253{
254 return as_float_helper<long double>( func, s, idx, strtold );
255}
256
Louis Dionne89258142021-08-23 15:32:36 -0400257#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
Howard Hinnantae2378a2013-05-16 17:13:40 +0000258template<>
259inline
260float
261as_float( const string& func, const wstring& s, size_t* idx )
262{
263 return as_float_helper<float>( func, s, idx, wcstof );
264}
265
266template<>
267inline
268double
269as_float( const string& func, const wstring& s, size_t* idx )
270{
271 return as_float_helper<double>( func, s, idx, wcstod );
272}
273
274template<>
275inline
276long double
277as_float( const string& func, const wstring& s, size_t* idx )
278{
279 return as_float_helper<long double>( func, s, idx, wcstold );
280}
Louis Dionne89258142021-08-23 15:32:36 -0400281#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
Howard Hinnantae2378a2013-05-16 17:13:40 +0000282
283} // unnamed namespace
284
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +0000285int
286stoi(const string& str, size_t* idx, int base)
287{
Howard Hinnantae2378a2013-05-16 17:13:40 +0000288 return as_integer<int>( "stoi", str, idx, base );
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +0000289}
290
Louis Dionne89258142021-08-23 15:32:36 -0400291#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +0000292int
293stoi(const wstring& str, size_t* idx, int base)
294{
Howard Hinnantae2378a2013-05-16 17:13:40 +0000295 return as_integer<int>( "stoi", str, idx, base );
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +0000296}
Louis Dionne89258142021-08-23 15:32:36 -0400297#endif
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +0000298
299long
300stol(const string& str, size_t* idx, int base)
301{
Howard Hinnantae2378a2013-05-16 17:13:40 +0000302 return as_integer<long>( "stol", str, idx, base );
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +0000303}
304
Louis Dionne89258142021-08-23 15:32:36 -0400305#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +0000306long
307stol(const wstring& str, size_t* idx, int base)
308{
Howard Hinnantae2378a2013-05-16 17:13:40 +0000309 return as_integer<long>( "stol", str, idx, base );
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +0000310}
Louis Dionne89258142021-08-23 15:32:36 -0400311#endif
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +0000312
313unsigned long
314stoul(const string& str, size_t* idx, int base)
315{
Howard Hinnantae2378a2013-05-16 17:13:40 +0000316 return as_integer<unsigned long>( "stoul", str, idx, base );
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +0000317}
318
Louis Dionne89258142021-08-23 15:32:36 -0400319#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +0000320unsigned long
321stoul(const wstring& str, size_t* idx, int base)
322{
Howard Hinnantae2378a2013-05-16 17:13:40 +0000323 return as_integer<unsigned long>( "stoul", str, idx, base );
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +0000324}
Louis Dionne89258142021-08-23 15:32:36 -0400325#endif
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +0000326
327long long
328stoll(const string& str, size_t* idx, int base)
329{
Howard Hinnantae2378a2013-05-16 17:13:40 +0000330 return as_integer<long long>( "stoll", str, idx, base );
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +0000331}
332
Louis Dionne89258142021-08-23 15:32:36 -0400333#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +0000334long long
335stoll(const wstring& str, size_t* idx, int base)
336{
Howard Hinnantae2378a2013-05-16 17:13:40 +0000337 return as_integer<long long>( "stoll", str, idx, base );
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +0000338}
Louis Dionne89258142021-08-23 15:32:36 -0400339#endif
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +0000340
341unsigned long long
342stoull(const string& str, size_t* idx, int base)
343{
Howard Hinnantae2378a2013-05-16 17:13:40 +0000344 return as_integer<unsigned long long>( "stoull", str, idx, base );
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +0000345}
346
Louis Dionne89258142021-08-23 15:32:36 -0400347#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +0000348unsigned long long
349stoull(const wstring& str, size_t* idx, int base)
350{
Howard Hinnantae2378a2013-05-16 17:13:40 +0000351 return as_integer<unsigned long long>( "stoull", str, idx, base );
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +0000352}
Louis Dionne89258142021-08-23 15:32:36 -0400353#endif
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +0000354
355float
356stof(const string& str, size_t* idx)
357{
Howard Hinnantae2378a2013-05-16 17:13:40 +0000358 return as_float<float>( "stof", str, idx );
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +0000359}
360
Louis Dionne89258142021-08-23 15:32:36 -0400361#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +0000362float
363stof(const wstring& str, size_t* idx)
364{
Howard Hinnantae2378a2013-05-16 17:13:40 +0000365 return as_float<float>( "stof", str, idx );
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +0000366}
Louis Dionne89258142021-08-23 15:32:36 -0400367#endif
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +0000368
369double
370stod(const string& str, size_t* idx)
371{
Howard Hinnantae2378a2013-05-16 17:13:40 +0000372 return as_float<double>( "stod", str, idx );
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +0000373}
374
Louis Dionne89258142021-08-23 15:32:36 -0400375#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +0000376double
377stod(const wstring& str, size_t* idx)
378{
Howard Hinnantae2378a2013-05-16 17:13:40 +0000379 return as_float<double>( "stod", str, idx );
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +0000380}
Louis Dionne89258142021-08-23 15:32:36 -0400381#endif
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +0000382
383long double
384stold(const string& str, size_t* idx)
385{
Howard Hinnantae2378a2013-05-16 17:13:40 +0000386 return as_float<long double>( "stold", str, idx );
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +0000387}
388
Louis Dionne89258142021-08-23 15:32:36 -0400389#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +0000390long double
391stold(const wstring& str, size_t* idx)
392{
Howard Hinnantae2378a2013-05-16 17:13:40 +0000393 return as_float<long double>( "stold", str, idx );
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +0000394}
Louis Dionne89258142021-08-23 15:32:36 -0400395#endif
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +0000396
Howard Hinnantae2378a2013-05-16 17:13:40 +0000397// to_string
398
399namespace
400{
401
402// as_string
403
404template<typename S, typename P, typename V >
405inline
406S
407as_string(P sprintf_like, S s, const typename S::value_type* fmt, V a)
408{
409 typedef typename S::size_type size_type;
410 size_type available = s.size();
411 while (true)
412 {
413 int status = sprintf_like(&s[0], available + 1, fmt, a);
414 if ( status >= 0 )
415 {
416 size_type used = static_cast<size_type>(status);
417 if ( used <= available )
418 {
419 s.resize( used );
420 break;
421 }
422 available = used; // Assume this is advice of how much space we need.
423 }
424 else
425 available = available * 2 + 1;
426 s.resize(available);
427 }
428 return s;
429}
430
Marshall Clow54e41492019-06-10 23:20:01 +0000431template <class S>
Howard Hinnantae2378a2013-05-16 17:13:40 +0000432struct initial_string;
433
Marshall Clow54e41492019-06-10 23:20:01 +0000434template <>
435struct initial_string<string>
Howard Hinnantae2378a2013-05-16 17:13:40 +0000436{
437 string
438 operator()() const
439 {
440 string s;
441 s.resize(s.capacity());
442 return s;
443 }
444};
445
Louis Dionne89258142021-08-23 15:32:36 -0400446#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
Marshall Clow54e41492019-06-10 23:20:01 +0000447template <>
448struct initial_string<wstring>
Howard Hinnantae2378a2013-05-16 17:13:40 +0000449{
450 wstring
451 operator()() const
452 {
453 wstring s(20, wchar_t());
454 s.resize(s.capacity());
455 return s;
456 }
457};
458
459typedef int (*wide_printf)(wchar_t* __restrict, size_t, const wchar_t*__restrict, ...);
460
461inline
462wide_printf
463get_swprintf()
464{
Howard Hinnant13d8bc12013-08-01 18:17:34 +0000465#ifndef _LIBCPP_MSVCRT
Howard Hinnantae2378a2013-05-16 17:13:40 +0000466 return swprintf;
467#else
Eric Fiselier4a984f02017-05-10 20:57:45 +0000468 return static_cast<int (__cdecl*)(wchar_t* __restrict, size_t, const wchar_t*__restrict, ...)>(_snwprintf);
Howard Hinnantae2378a2013-05-16 17:13:40 +0000469#endif
470}
Louis Dionne89258142021-08-23 15:32:36 -0400471#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
Howard Hinnantae2378a2013-05-16 17:13:40 +0000472
Marshall Clow54e41492019-06-10 23:20:01 +0000473template <typename S, typename V>
Louis Dionned9f528e2021-06-29 13:52:26 -0400474S i_to_string(V v)
Marshall Clow54e41492019-06-10 23:20:01 +0000475{
476// numeric_limits::digits10 returns value less on 1 than desired for unsigned numbers.
477// For example, for 1-byte unsigned value digits10 is 2 (999 can not be represented),
478// so we need +1 here.
479 constexpr size_t bufsize = numeric_limits<V>::digits10 + 2; // +1 for minus, +1 for digits10
480 char buf[bufsize];
481 const auto res = to_chars(buf, buf + bufsize, v);
482 _LIBCPP_ASSERT(res.ec == errc(), "bufsize must be large enough to accomodate the value");
483 return S(buf, res.ptr);
484}
485
Howard Hinnantae2378a2013-05-16 17:13:40 +0000486} // unnamed namespace
487
Marshall Clow54e41492019-06-10 23:20:01 +0000488string to_string (int val) { return i_to_string< string>(val); }
489string to_string (long val) { return i_to_string< string>(val); }
490string to_string (long long val) { return i_to_string< string>(val); }
491string to_string (unsigned val) { return i_to_string< string>(val); }
492string to_string (unsigned long val) { return i_to_string< string>(val); }
493string to_string (unsigned long long val) { return i_to_string< string>(val); }
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +0000494
Louis Dionne89258142021-08-23 15:32:36 -0400495#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
Marshall Clow54e41492019-06-10 23:20:01 +0000496wstring to_wstring(int val) { return i_to_string<wstring>(val); }
497wstring to_wstring(long val) { return i_to_string<wstring>(val); }
498wstring to_wstring(long long val) { return i_to_string<wstring>(val); }
499wstring to_wstring(unsigned val) { return i_to_string<wstring>(val); }
500wstring to_wstring(unsigned long val) { return i_to_string<wstring>(val); }
501wstring to_wstring(unsigned long long val) { return i_to_string<wstring>(val); }
Louis Dionne89258142021-08-23 15:32:36 -0400502#endif
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +0000503
Marshall Clow54e41492019-06-10 23:20:01 +0000504string to_string (float val) { return as_string(snprintf, initial_string< string>()(), "%f", val); }
505string to_string (double val) { return as_string(snprintf, initial_string< string>()(), "%f", val); }
506string to_string (long double val) { return as_string(snprintf, initial_string< string>()(), "%Lf", val); }
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +0000507
Louis Dionne89258142021-08-23 15:32:36 -0400508#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
Marshall Clow54e41492019-06-10 23:20:01 +0000509wstring to_wstring(float val) { return as_string(get_swprintf(), initial_string<wstring>()(), L"%f", val); }
510wstring to_wstring(double val) { return as_string(get_swprintf(), initial_string<wstring>()(), L"%f", val); }
511wstring to_wstring(long double val) { return as_string(get_swprintf(), initial_string<wstring>()(), L"%Lf", val); }
Louis Dionne89258142021-08-23 15:32:36 -0400512#endif
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +0000513
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +0000514_LIBCPP_END_NAMESPACE_STD