* snapshot-README: Use GCC instead of gcc, C++ front end instead of
[official-gcc.git] / libstdc++-v3 / include / std / std_iomanip.h
blob490d5ac1cfbaaf39b33625b58576c561f7d94537
1 // Standard stream manipulators -*- C++ -*-
3 // Copyright (C) 1997, 1998, 1999, 2001, 2002, 2003
4 // Free Software Foundation, Inc.
5 //
6 // This file is part of the GNU ISO C++ Library. This library is free
7 // software; you can redistribute it and/or modify it under the
8 // terms of the GNU General Public License as published by the
9 // Free Software Foundation; either version 2, or (at your option)
10 // any later version.
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License along
18 // with this library; see the file COPYING. If not, write to the Free
19 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
20 // USA.
22 // As a special exception, you may use this file as part of a free software
23 // library without restriction. Specifically, if other files instantiate
24 // templates or use macros or inline functions from this file, or you compile
25 // this file and link it with other files to produce an executable, this
26 // file does not by itself cause the resulting executable to be covered by
27 // the GNU General Public License. This exception does not however
28 // invalidate any other reasons why the executable file might be covered by
29 // the GNU General Public License.
32 // ISO C++ 14882: 27.6.3 Standard manipulators
35 /** @file iomanip
36 * This is a Standard C++ Library header. You should @c #include this header
37 * in your programs, rather than any of the "st[dl]_*.h" implementation files.
40 #ifndef _CPP_IOMANIP
41 #define _CPP_IOMANIP 1
43 #pragma GCC system_header
45 #include <bits/c++config.h>
46 #include <istream>
47 #include <functional>
49 namespace std
51 // [27.6.3] standard manipulators
52 // Also see DR 183.
54 struct _Resetiosflags { ios_base::fmtflags _M_mask; };
56 /**
57 * @brief Manipulator for @c setf.
58 * @param mask A format flags mask.
60 * Sent to a stream object, this manipulator resets the specified flags,
61 * via @e stream.setf(0,mask).
63 inline _Resetiosflags
64 resetiosflags(ios_base::fmtflags __mask)
66 _Resetiosflags __x;
67 __x._M_mask = __mask;
68 return __x;
71 template<typename _CharT, typename _Traits>
72 inline basic_istream<_CharT,_Traits>&
73 operator>>(basic_istream<_CharT,_Traits>& __is, _Resetiosflags __f)
75 __is.setf(ios_base::fmtflags(0), __f._M_mask);
76 return __is;
79 template<typename _CharT, typename _Traits>
80 inline basic_ostream<_CharT,_Traits>&
81 operator<<(basic_ostream<_CharT,_Traits>& __os, _Resetiosflags __f)
83 __os.setf(ios_base::fmtflags(0), __f._M_mask);
84 return __os;
88 struct _Setiosflags { ios_base::fmtflags _M_mask; };
90 /**
91 * @brief Manipulator for @c setf.
92 * @param mask A format flags mask.
94 * Sent to a stream object, this manipulator sets the format flags
95 * to @a mask.
97 inline _Setiosflags
98 setiosflags(ios_base::fmtflags __mask)
100 _Setiosflags __x;
101 __x._M_mask = __mask;
102 return __x;
105 template<typename _CharT, typename _Traits>
106 inline basic_istream<_CharT,_Traits>&
107 operator>>(basic_istream<_CharT,_Traits>& __is, _Setiosflags __f)
109 __is.setf(__f._M_mask);
110 return __is;
113 template<typename _CharT, typename _Traits>
114 inline basic_ostream<_CharT,_Traits>&
115 operator<<(basic_ostream<_CharT,_Traits>& __os, _Setiosflags __f)
117 __os.setf(__f._M_mask);
118 return __os;
122 struct _Setbase { int _M_base; };
125 * @brief Manipulator for @c setf.
126 * @param base A numeric base.
128 * Sent to a stream object, this manipulator changes the
129 * @c ios_base::basefield flags to @c oct, @c dec, or @c hex when @a base
130 * is 8, 10, or 16, accordingly, and to 0 if @a base is any other value.
132 inline _Setbase
133 setbase(int __base)
135 _Setbase __x;
136 __x._M_base = __base;
137 return __x;
140 template<typename _CharT, typename _Traits>
141 inline basic_istream<_CharT,_Traits>&
142 operator>>(basic_istream<_CharT,_Traits>& __is, _Setbase __f)
144 __is.setf(__f._M_base == 8 ? ios_base::oct :
145 __f._M_base == 10 ? ios_base::dec :
146 __f._M_base == 16 ? ios_base::hex :
147 ios_base::fmtflags(0), ios_base::basefield);
148 return __is;
151 template<typename _CharT, typename _Traits>
152 inline basic_ostream<_CharT,_Traits>&
153 operator<<(basic_ostream<_CharT,_Traits>& __os, _Setbase __f)
155 __os.setf(__f._M_base == 8 ? ios_base::oct :
156 __f._M_base == 10 ? ios_base::dec :
157 __f._M_base == 16 ? ios_base::hex :
158 ios_base::fmtflags(0), ios_base::basefield);
159 return __os;
163 template<typename _CharT>
164 struct _Setfill { _CharT _M_c; };
167 * @brief Manipulator for @c fill.
168 * @param c The new fill character.
170 * Sent to a stream object, this manipulator calls @c fill(c) for that
171 * object.
173 template<typename _CharT>
174 inline _Setfill<_CharT>
175 setfill(_CharT __c)
177 _Setfill<_CharT> __x;
178 __x._M_c = __c;
179 return __x;
182 template<typename _CharT, typename _Traits>
183 inline basic_istream<_CharT,_Traits>&
184 operator>>(basic_istream<_CharT,_Traits>& __is, _Setfill<_CharT> __f)
186 __is.fill(__f._M_c);
187 return __is;
190 template<typename _CharT, typename _Traits>
191 inline basic_ostream<_CharT,_Traits>&
192 operator<<(basic_ostream<_CharT,_Traits>& __os, _Setfill<_CharT> __f)
194 __os.fill(__f._M_c);
195 return __os;
199 struct _Setprecision { int _M_n; };
202 * @brief Manipulator for @c precision.
203 * @param n The new precision.
205 * Sent to a stream object, this manipulator calls @c precision(n) for
206 * that object.
208 inline _Setprecision
209 setprecision(int __n)
211 _Setprecision __x;
212 __x._M_n = __n;
213 return __x;
216 template<typename _CharT, typename _Traits>
217 inline basic_istream<_CharT,_Traits>&
218 operator>>(basic_istream<_CharT,_Traits>& __is, _Setprecision __f)
220 __is.precision(__f._M_n);
221 return __is;
224 template<typename _CharT, typename _Traits>
225 inline basic_ostream<_CharT,_Traits>&
226 operator<<(basic_ostream<_CharT,_Traits>& __os, _Setprecision __f)
228 __os.precision(__f._M_n);
229 return __os;
233 struct _Setw { int _M_n; };
236 * @brief Manipulator for @c width.
237 * @param n The new width.
239 * Sent to a stream object, this manipulator calls @c width(n) for
240 * that object.
242 inline _Setw
243 setw(int __n)
245 _Setw __x;
246 __x._M_n = __n;
247 return __x;
250 template<typename _CharT, typename _Traits>
251 inline basic_istream<_CharT,_Traits>&
252 operator>>(basic_istream<_CharT,_Traits>& __is, _Setw __f)
254 __is.width(__f._M_n);
255 return __is;
258 template<typename _CharT, typename _Traits>
259 inline basic_ostream<_CharT,_Traits>&
260 operator<<(basic_ostream<_CharT,_Traits>& __os, _Setw __f)
262 __os.width(__f._M_n);
263 return __os;
266 // Inhibit implicit instantiations for required instantiations,
267 // which are defined via explicit instantiations elsewhere.
268 // NB: This syntax is a GNU extension.
269 #if _GLIBCPP_EXTERN_TEMPLATE
270 extern template ostream& operator<<(ostream&, _Setfill<char>);
271 extern template ostream& operator<<(ostream&, _Setiosflags);
272 extern template ostream& operator<<(ostream&, _Resetiosflags);
273 extern template ostream& operator<<(ostream&, _Setbase);
274 extern template ostream& operator<<(ostream&, _Setprecision);
275 extern template ostream& operator<<(ostream&, _Setw);
276 extern template istream& operator>>(istream&, _Setfill<char>);
277 extern template istream& operator>>(istream&, _Setiosflags);
278 extern template istream& operator>>(istream&, _Resetiosflags);
279 extern template istream& operator>>(istream&, _Setbase);
280 extern template istream& operator>>(istream&, _Setprecision);
281 extern template istream& operator>>(istream&, _Setw);
283 #ifdef _GLIBCPP_USE_WCHAR_T
284 extern template wostream& operator<<(wostream&, _Setfill<wchar_t>);
285 extern template wostream& operator<<(wostream&, _Setiosflags);
286 extern template wostream& operator<<(wostream&, _Resetiosflags);
287 extern template wostream& operator<<(wostream&, _Setbase);
288 extern template wostream& operator<<(wostream&, _Setprecision);
289 extern template wostream& operator<<(wostream&, _Setw);
290 extern template wistream& operator>>(wistream&, _Setfill<wchar_t>);
291 extern template wistream& operator>>(wistream&, _Setiosflags);
292 extern template wistream& operator>>(wistream&, _Resetiosflags);
293 extern template wistream& operator>>(wistream&, _Setbase);
294 extern template wistream& operator>>(wistream&, _Setprecision);
295 extern template wistream& operator>>(wistream&, _Setw);
296 #endif
297 #endif
298 } // namespace std
300 #endif