2002-01-28 Phil Edwards <pme@gcc.gnu.org>
[official-gcc.git] / libstdc++-v3 / include / std / std_iomanip.h
blob39ecac2c77f738c0b18346755c19a655a05e4dfb
1 // Standard stream manipulators -*- C++ -*-
3 // Copyright (C) 1997, 1998, 1999, 2001, 2002 Free Software Foundation, Inc.
4 //
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 2, or (at your option)
9 // any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING. If not, write to the Free
18 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
19 // USA.
21 // As a special exception, you may use this file as part of a free software
22 // library without restriction. Specifically, if other files instantiate
23 // templates or use macros or inline functions from this file, or you compile
24 // this file and link it with other files to produce an executable, this
25 // file does not by itself cause the resulting executable to be covered by
26 // the GNU General Public License. This exception does not however
27 // invalidate any other reasons why the executable file might be covered by
28 // the GNU General Public License.
31 // ISO C++ 14882: 27.6.3 Standard manipulators
34 /** @file iomanip
35 * This is a Standard C++ Library header. You should @c #include this header
36 * in your programs, rather than any of the "st[dl]_*.h" implementation files.
39 #ifndef _CPP_IOMANIP
40 #define _CPP_IOMANIP 1
42 #pragma GCC system_header
44 #include <bits/c++config.h>
45 #include <istream>
46 #include <functional>
48 namespace std
51 struct _Resetiosflags { ios_base::fmtflags _M_mask; };
53 inline _Resetiosflags
54 resetiosflags(ios_base::fmtflags __mask)
56 _Resetiosflags __x;
57 __x._M_mask = __mask;
58 return __x;
61 template <class _CharT, class _Traits>
62 basic_istream<_CharT,_Traits>&
63 operator>>(basic_istream<_CharT,_Traits>& __is, _Resetiosflags __f)
65 __is.setf(ios_base::fmtflags(0), __f._M_mask);
66 return __is;
69 template <class _CharT, class _Traits>
70 basic_ostream<_CharT,_Traits>&
71 operator<<(basic_ostream<_CharT,_Traits>& __os, _Resetiosflags __f)
73 __os.setf(ios_base::fmtflags(0), __f._M_mask);
74 return __os;
78 struct _Setiosflags { ios_base::fmtflags _M_mask; };
80 inline _Setiosflags
81 setiosflags(ios_base::fmtflags __mask)
83 _Setiosflags __x;
84 __x._M_mask = __mask;
85 return __x;
88 template <class _CharT, class _Traits>
89 basic_istream<_CharT,_Traits>&
90 operator>>(basic_istream<_CharT,_Traits>& __is, _Setiosflags __f)
92 __is.setf(__f._M_mask);
93 return __is;
96 template <class _CharT, class _Traits>
97 basic_ostream<_CharT,_Traits>&
98 operator<<(basic_ostream<_CharT,_Traits>& __os, _Setiosflags __f)
100 __os.setf(__f._M_mask);
101 return __os;
105 struct _Setbase { int _M_base; };
107 inline _Setbase
108 setbase(int __base)
110 _Setbase __x;
111 __x._M_base = __base;
112 return __x;
115 template <class _CharT, class _Traits>
116 basic_istream<_CharT,_Traits>&
117 operator>>(basic_istream<_CharT,_Traits>& __is, _Setbase __f)
119 __is.setf(__f._M_base == 8 ? ios_base::oct :
120 __f._M_base == 10 ? ios_base::dec :
121 __f._M_base == 16 ? ios_base::hex :
122 ios_base::fmtflags(0), ios_base::basefield);
123 return __is;
126 template <class _CharT, class _Traits>
127 basic_ostream<_CharT,_Traits>&
128 operator<<(basic_ostream<_CharT,_Traits>& __os, _Setbase __f)
130 __os.setf(__f._M_base == 8 ? ios_base::oct :
131 __f._M_base == 10 ? ios_base::dec :
132 __f._M_base == 16 ? ios_base::hex :
133 ios_base::fmtflags(0), ios_base::basefield);
134 return __os;
138 template<class _CharT>
139 struct _Setfill { _CharT _M_c; };
141 template<class _CharT>
142 _Setfill<_CharT>
143 setfill(_CharT __c)
145 _Setfill<_CharT> __x;
146 __x._M_c = __c;
147 return __x;
150 template <class _CharT, class _Traits>
151 basic_istream<_CharT,_Traits>&
152 operator>>(basic_istream<_CharT,_Traits>& __is, _Setfill<_CharT> __f)
154 __is.fill(__f._M_c);
155 return __is;
158 template <class _CharT, class _Traits>
159 basic_ostream<_CharT,_Traits>&
160 operator<<(basic_ostream<_CharT,_Traits>& __os, _Setfill<_CharT> __f)
162 __os.fill(__f._M_c);
163 return __os;
167 struct _Setprecision { int _M_n; };
169 inline _Setprecision
170 setprecision(int __n)
172 _Setprecision __x;
173 __x._M_n = __n;
174 return __x;
177 template <class _CharT, class _Traits>
178 basic_istream<_CharT,_Traits>&
179 operator>>(basic_istream<_CharT,_Traits>& __is, _Setprecision __f)
181 __is.precision(__f._M_n);
182 return __is;
185 template <class _CharT, class _Traits>
186 basic_ostream<_CharT,_Traits>&
187 operator<<(basic_ostream<_CharT,_Traits>& __os, _Setprecision __f)
189 __os.precision(__f._M_n);
190 return __os;
194 struct _Setw { int _M_n; };
196 inline _Setw
197 setw(int __n)
199 _Setw __x;
200 __x._M_n = __n;
201 return __x;
204 template <class _CharT, class _Traits>
205 basic_istream<_CharT,_Traits>&
206 operator>>(basic_istream<_CharT,_Traits>& __is, _Setw __f)
208 __is.width(__f._M_n);
209 return __is;
212 template <class _CharT, class _Traits>
213 basic_ostream<_CharT,_Traits>&
214 operator<<(basic_ostream<_CharT,_Traits>& __os, _Setw __f)
216 __os.width(__f._M_n);
217 return __os;
219 } // namespace std
221 #endif