2 //===----------------------------------------------------------------------===//
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8 //===----------------------------------------------------------------------===//
10 #ifndef _LIBCPP_IOMANIP
11 #define _LIBCPP_IOMANIP
18 // types T1, T2, ... are unspecified implementation types
19 T1 resetiosflags(ios_base::fmtflags mask);
20 T2 setiosflags (ios_base::fmtflags mask);
22 template<charT> T4 setfill(charT c);
23 T5 setprecision(int n);
25 template <class moneyT> T7 get_money(moneyT& mon, bool intl = false);
26 template <class charT, class moneyT> T8 put_money(const moneyT& mon, bool intl = false);
27 template <class charT> T9 get_time(struct tm* tmb, const charT* fmt);
28 template <class charT> T10 put_time(const struct tm* tmb, const charT* fmt);
30 template <class charT>
31 T11 quoted(const charT* s, charT delim=charT('"'), charT escape=charT('\\')); // C++14
33 template <class charT, class traits, class Allocator>
34 T12 quoted(const basic_string<charT, traits, Allocator>& s,
35 charT delim=charT('"'), charT escape=charT('\\')); // C++14
37 template <class charT, class traits, class Allocator>
38 T13 quoted(basic_string<charT, traits, Allocator>& s,
39 charT delim=charT('"'), charT escape=charT('\\')); // C++14
47 #if _LIBCPP_HAS_LOCALIZATION
49 # include <__ostream/put_character_sequence.h>
55 # if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
56 # pragma GCC system_header
59 _LIBCPP_BEGIN_NAMESPACE_STD
64 ios_base::fmtflags __mask_;
67 _LIBCPP_HIDE_FROM_ABI explicit __iom_t1(ios_base::fmtflags __m) : __mask_(__m) {}
69 template <class _CharT, class _Traits>
70 friend _LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>&
71 operator>>(basic_istream<_CharT, _Traits>& __is, const __iom_t1& __x) {
72 __is.unsetf(__x.__mask_);
76 template <class _CharT, class _Traits>
77 friend _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&
78 operator<<(basic_ostream<_CharT, _Traits>& __os, const __iom_t1& __x) {
79 __os.unsetf(__x.__mask_);
84 inline _LIBCPP_HIDE_FROM_ABI __iom_t1 resetiosflags(ios_base::fmtflags __mask) { return __iom_t1(__mask); }
89 ios_base::fmtflags __mask_;
92 _LIBCPP_HIDE_FROM_ABI explicit __iom_t2(ios_base::fmtflags __m) : __mask_(__m) {}
94 template <class _CharT, class _Traits>
95 friend _LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>&
96 operator>>(basic_istream<_CharT, _Traits>& __is, const __iom_t2& __x) {
97 __is.setf(__x.__mask_);
101 template <class _CharT, class _Traits>
102 friend _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&
103 operator<<(basic_ostream<_CharT, _Traits>& __os, const __iom_t2& __x) {
104 __os.setf(__x.__mask_);
109 inline _LIBCPP_HIDE_FROM_ABI __iom_t2 setiosflags(ios_base::fmtflags __mask) { return __iom_t2(__mask); }
117 _LIBCPP_HIDE_FROM_ABI explicit __iom_t3(int __b) : __base_(__b) {}
119 template <class _CharT, class _Traits>
120 friend _LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>&
121 operator>>(basic_istream<_CharT, _Traits>& __is, const __iom_t3& __x) {
122 __is.setf(__x.__base_ == 8 ? ios_base::oct
123 : __x.__base_ == 10 ? ios_base::dec
124 : __x.__base_ == 16 ? ios_base::hex
125 : ios_base::fmtflags(0),
126 ios_base::basefield);
130 template <class _CharT, class _Traits>
131 friend _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&
132 operator<<(basic_ostream<_CharT, _Traits>& __os, const __iom_t3& __x) {
133 __os.setf(__x.__base_ == 8 ? ios_base::oct
134 : __x.__base_ == 10 ? ios_base::dec
135 : __x.__base_ == 16 ? ios_base::hex
136 : ios_base::fmtflags(0),
137 ios_base::basefield);
142 inline _LIBCPP_HIDE_FROM_ABI __iom_t3 setbase(int __base) { return __iom_t3(__base); }
146 template <class _CharT>
151 _LIBCPP_HIDE_FROM_ABI explicit __iom_t4(_CharT __c) : __fill_(__c) {}
153 template <class _Traits>
154 friend _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&
155 operator<<(basic_ostream<_CharT, _Traits>& __os, const __iom_t4& __x) {
156 __os.fill(__x.__fill_);
161 template <class _CharT>
162 inline _LIBCPP_HIDE_FROM_ABI __iom_t4<_CharT> setfill(_CharT __c) {
163 return __iom_t4<_CharT>(__c);
172 _LIBCPP_HIDE_FROM_ABI explicit __iom_t5(int __n) : __n_(__n) {}
174 template <class _CharT, class _Traits>
175 friend _LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>&
176 operator>>(basic_istream<_CharT, _Traits>& __is, const __iom_t5& __x) {
177 __is.precision(__x.__n_);
181 template <class _CharT, class _Traits>
182 friend _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&
183 operator<<(basic_ostream<_CharT, _Traits>& __os, const __iom_t5& __x) {
184 __os.precision(__x.__n_);
189 inline _LIBCPP_HIDE_FROM_ABI __iom_t5 setprecision(int __n) { return __iom_t5(__n); }
197 _LIBCPP_HIDE_FROM_ABI explicit __iom_t6(int __n) : __n_(__n) {}
199 template <class _CharT, class _Traits>
200 friend _LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>&
201 operator>>(basic_istream<_CharT, _Traits>& __is, const __iom_t6& __x) {
202 __is.width(__x.__n_);
206 template <class _CharT, class _Traits>
207 friend _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&
208 operator<<(basic_ostream<_CharT, _Traits>& __os, const __iom_t6& __x) {
209 __os.width(__x.__n_);
214 inline _LIBCPP_HIDE_FROM_ABI __iom_t6 setw(int __n) { return __iom_t6(__n); }
218 template <class _MoneyT>
221 template <class _CharT, class _Traits, class _MoneyT>
222 _LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>&
223 operator>>(basic_istream<_CharT, _Traits>& __is, const __iom_t7<_MoneyT>& __x);
225 template <class _MoneyT>
231 _LIBCPP_HIDE_FROM_ABI __iom_t7(_MoneyT& __mon, bool __intl) : __mon_(__mon), __intl_(__intl) {}
233 template <class _CharT, class _Traits, class _Mp>
234 friend basic_istream<_CharT, _Traits>& operator>>(basic_istream<_CharT, _Traits>& __is, const __iom_t7<_Mp>& __x);
237 template <class _CharT, class _Traits, class _MoneyT>
238 _LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>&
239 operator>>(basic_istream<_CharT, _Traits>& __is, const __iom_t7<_MoneyT>& __x) {
240 # if _LIBCPP_HAS_EXCEPTIONS
242 # endif // _LIBCPP_HAS_EXCEPTIONS
243 typename basic_istream<_CharT, _Traits>::sentry __s(__is);
245 typedef istreambuf_iterator<_CharT, _Traits> _Ip;
246 typedef money_get<_CharT, _Ip> _Fp;
247 ios_base::iostate __err = ios_base::goodbit;
248 const _Fp& __mf = std::use_facet<_Fp>(__is.getloc());
249 __mf.get(_Ip(__is), _Ip(), __x.__intl_, __is, __err, __x.__mon_);
250 __is.setstate(__err);
252 # if _LIBCPP_HAS_EXCEPTIONS
254 __is.__set_badbit_and_consider_rethrow();
256 # endif // _LIBCPP_HAS_EXCEPTIONS
260 template <class _MoneyT>
261 inline _LIBCPP_HIDE_FROM_ABI __iom_t7<_MoneyT> get_money(_MoneyT& __mon, bool __intl = false) {
262 return __iom_t7<_MoneyT>(__mon, __intl);
267 template <class _MoneyT>
270 template <class _CharT, class _Traits, class _MoneyT>
271 _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&
272 operator<<(basic_ostream<_CharT, _Traits>& __os, const __iom_t8<_MoneyT>& __x);
274 template <class _MoneyT>
276 const _MoneyT& __mon_;
280 _LIBCPP_HIDE_FROM_ABI __iom_t8(const _MoneyT& __mon, bool __intl) : __mon_(__mon), __intl_(__intl) {}
282 template <class _CharT, class _Traits, class _Mp>
283 friend basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& __os, const __iom_t8<_Mp>& __x);
286 template <class _CharT, class _Traits, class _MoneyT>
287 _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&
288 operator<<(basic_ostream<_CharT, _Traits>& __os, const __iom_t8<_MoneyT>& __x) {
289 # if _LIBCPP_HAS_EXCEPTIONS
291 # endif // _LIBCPP_HAS_EXCEPTIONS
292 typename basic_ostream<_CharT, _Traits>::sentry __s(__os);
294 typedef ostreambuf_iterator<_CharT, _Traits> _Op;
295 typedef money_put<_CharT, _Op> _Fp;
296 const _Fp& __mf = std::use_facet<_Fp>(__os.getloc());
297 if (__mf.put(_Op(__os), __x.__intl_, __os, __os.fill(), __x.__mon_).failed())
298 __os.setstate(ios_base::badbit);
300 # if _LIBCPP_HAS_EXCEPTIONS
302 __os.__set_badbit_and_consider_rethrow();
304 # endif // _LIBCPP_HAS_EXCEPTIONS
308 template <class _MoneyT>
309 inline _LIBCPP_HIDE_FROM_ABI __iom_t8<_MoneyT> put_money(const _MoneyT& __mon, bool __intl = false) {
310 return __iom_t8<_MoneyT>(__mon, __intl);
315 template <class _CharT>
318 template <class _CharT, class _Traits>
319 _LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>&
320 operator>>(basic_istream<_CharT, _Traits>& __is, const __iom_t9<_CharT>& __x);
322 template <class _CharT>
325 const _CharT* __fmt_;
328 _LIBCPP_HIDE_FROM_ABI __iom_t9(tm* __tm, const _CharT* __fmt) : __tm_(__tm), __fmt_(__fmt) {}
330 template <class _Cp, class _Traits>
331 friend basic_istream<_Cp, _Traits>& operator>>(basic_istream<_Cp, _Traits>& __is, const __iom_t9<_Cp>& __x);
334 template <class _CharT, class _Traits>
335 _LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>&
336 operator>>(basic_istream<_CharT, _Traits>& __is, const __iom_t9<_CharT>& __x) {
337 # if _LIBCPP_HAS_EXCEPTIONS
339 # endif // _LIBCPP_HAS_EXCEPTIONS
340 typename basic_istream<_CharT, _Traits>::sentry __s(__is);
342 typedef istreambuf_iterator<_CharT, _Traits> _Ip;
343 typedef time_get<_CharT, _Ip> _Fp;
344 ios_base::iostate __err = ios_base::goodbit;
345 const _Fp& __tf = std::use_facet<_Fp>(__is.getloc());
346 __tf.get(_Ip(__is), _Ip(), __is, __err, __x.__tm_, __x.__fmt_, __x.__fmt_ + _Traits::length(__x.__fmt_));
347 __is.setstate(__err);
349 # if _LIBCPP_HAS_EXCEPTIONS
351 __is.__set_badbit_and_consider_rethrow();
353 # endif // _LIBCPP_HAS_EXCEPTIONS
357 template <class _CharT>
358 inline _LIBCPP_HIDE_FROM_ABI __iom_t9<_CharT> get_time(tm* __tm, const _CharT* __fmt) {
359 return __iom_t9<_CharT>(__tm, __fmt);
364 template <class _CharT>
367 template <class _CharT, class _Traits>
368 _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&
369 operator<<(basic_ostream<_CharT, _Traits>& __os, const __iom_t10<_CharT>& __x);
371 template <class _CharT>
374 const _CharT* __fmt_;
377 _LIBCPP_HIDE_FROM_ABI __iom_t10(const tm* __tm, const _CharT* __fmt) : __tm_(__tm), __fmt_(__fmt) {}
379 template <class _Cp, class _Traits>
380 friend basic_ostream<_Cp, _Traits>& operator<<(basic_ostream<_Cp, _Traits>& __os, const __iom_t10<_Cp>& __x);
383 template <class _CharT, class _Traits>
384 _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&
385 operator<<(basic_ostream<_CharT, _Traits>& __os, const __iom_t10<_CharT>& __x) {
386 # if _LIBCPP_HAS_EXCEPTIONS
388 # endif // _LIBCPP_HAS_EXCEPTIONS
389 typename basic_ostream<_CharT, _Traits>::sentry __s(__os);
391 typedef ostreambuf_iterator<_CharT, _Traits> _Op;
392 typedef time_put<_CharT, _Op> _Fp;
393 const _Fp& __tf = std::use_facet<_Fp>(__os.getloc());
394 if (__tf.put(_Op(__os), __os, __os.fill(), __x.__tm_, __x.__fmt_, __x.__fmt_ + _Traits::length(__x.__fmt_))
396 __os.setstate(ios_base::badbit);
398 # if _LIBCPP_HAS_EXCEPTIONS
400 __os.__set_badbit_and_consider_rethrow();
402 # endif // _LIBCPP_HAS_EXCEPTIONS
406 template <class _CharT>
407 inline _LIBCPP_HIDE_FROM_ABI __iom_t10<_CharT> put_time(const tm* __tm, const _CharT* __fmt) {
408 return __iom_t10<_CharT>(__tm, __fmt);
411 template <class _CharT, class _Traits>
412 _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>& __quoted_output(
413 basic_ostream<_CharT, _Traits>& __os,
414 const _CharT* __first,
415 const _CharT* __last,
418 basic_string<_CharT, _Traits> __str;
419 __str.push_back(__delim);
420 for (; __first != __last; ++__first) {
421 if (_Traits::eq(*__first, __escape) || _Traits::eq(*__first, __delim))
422 __str.push_back(__escape);
423 __str.push_back(*__first);
425 __str.push_back(__delim);
426 return std::__put_character_sequence(__os, __str.data(), __str.size());
429 template <class _CharT, class _Traits, class _String>
430 _LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>&
431 __quoted_input(basic_istream<_CharT, _Traits>& __is, _String& __string, _CharT __delim, _CharT __escape) {
438 if (!_Traits::eq(__c, __delim)) {
439 // no delimiter, read the whole string
445 __save_flags<_CharT, _Traits> __sf(__is);
451 if (_Traits::eq(__c, __escape)) {
455 } else if (_Traits::eq(__c, __delim))
457 __string.push_back(__c);
462 template <class _CharT, class _Traits>
463 struct _LIBCPP_HIDDEN __quoted_output_proxy {
464 const _CharT* __first_;
465 const _CharT* __last_;
469 _LIBCPP_HIDE_FROM_ABI explicit __quoted_output_proxy(const _CharT* __f, const _CharT* __l, _CharT __d, _CharT __e)
470 : __first_(__f), __last_(__l), __delim_(__d), __escape_(__e) {}
472 template <class _T2, __enable_if_t<_IsSame<_Traits, void>::value || _IsSame<_Traits, _T2>::value, int> = 0>
473 friend _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _T2>&
474 operator<<(basic_ostream<_CharT, _T2>& __os, const __quoted_output_proxy& __p) {
475 return std::__quoted_output(__os, __p.__first_, __p.__last_, __p.__delim_, __p.__escape_);
479 template <class _CharT, class _Traits, class _Allocator>
480 struct _LIBCPP_HIDDEN __quoted_proxy {
481 basic_string<_CharT, _Traits, _Allocator>& __string_;
485 _LIBCPP_HIDE_FROM_ABI explicit __quoted_proxy(basic_string<_CharT, _Traits, _Allocator>& __s, _CharT __d, _CharT __e)
486 : __string_(__s), __delim_(__d), __escape_(__e) {}
488 friend _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&
489 operator<<(basic_ostream<_CharT, _Traits>& __os, const __quoted_proxy& __p) {
490 return std::__quoted_output(
491 __os, __p.__string_.data(), __p.__string_.data() + __p.__string_.size(), __p.__delim_, __p.__escape_);
494 friend _LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>&
495 operator>>(basic_istream<_CharT, _Traits>& __is, const __quoted_proxy& __p) {
496 return std::__quoted_input(__is, __p.__string_, __p.__delim_, __p.__escape_);
500 template <class _CharT, class _Traits, class _Allocator>
501 _LIBCPP_HIDE_FROM_ABI __quoted_output_proxy<_CharT, _Traits>
502 __quoted(const basic_string<_CharT, _Traits, _Allocator>& __s,
503 _CharT __delim = _CharT('"'),
504 _CharT __escape = _CharT('\\')) {
505 return __quoted_output_proxy<_CharT, _Traits>(__s.data(), __s.data() + __s.size(), __delim, __escape);
508 template <class _CharT, class _Traits, class _Allocator>
509 _LIBCPP_HIDE_FROM_ABI __quoted_proxy<_CharT, _Traits, _Allocator>
510 __quoted(basic_string<_CharT, _Traits, _Allocator>& __s, _CharT __delim = _CharT('"'), _CharT __escape = _CharT('\\')) {
511 return __quoted_proxy<_CharT, _Traits, _Allocator>(__s, __delim, __escape);
514 # if _LIBCPP_STD_VER >= 14
516 template <class _CharT>
517 _LIBCPP_HIDE_FROM_ABI auto quoted(const _CharT* __s, _CharT __delim = _CharT('"'), _CharT __escape = _CharT('\\')) {
518 const _CharT* __end = __s;
521 return __quoted_output_proxy<_CharT, void>(__s, __end, __delim, __escape);
524 template <class _CharT, class _Traits, class _Allocator>
525 _LIBCPP_HIDE_FROM_ABI auto
526 quoted(const basic_string<_CharT, _Traits, _Allocator>& __s,
527 _CharT __delim = _CharT('"'),
528 _CharT __escape = _CharT('\\')) {
529 return __quoted_output_proxy<_CharT, _Traits>(__s.data(), __s.data() + __s.size(), __delim, __escape);
532 template <class _CharT, class _Traits, class _Allocator>
533 _LIBCPP_HIDE_FROM_ABI auto
534 quoted(basic_string<_CharT, _Traits, _Allocator>& __s, _CharT __delim = _CharT('"'), _CharT __escape = _CharT('\\')) {
535 return __quoted_proxy<_CharT, _Traits, _Allocator>(__s, __delim, __escape);
538 template <class _CharT, class _Traits>
539 _LIBCPP_HIDE_FROM_ABI auto
540 quoted(basic_string_view<_CharT, _Traits> __sv, _CharT __delim = _CharT('"'), _CharT __escape = _CharT('\\')) {
541 return __quoted_output_proxy<_CharT, _Traits>(__sv.data(), __sv.data() + __sv.size(), __delim, __escape);
544 # endif // _LIBCPP_STD_VER >= 14
546 _LIBCPP_END_NAMESPACE_STD
548 #endif // _LIBCPP_HAS_LOCALIZATION
550 #if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
555 # include <functional>
561 # include <unordered_map>
565 #endif // _LIBCPP_IOMANIP