blob: 0f1d88e378f544ce943f26a49116367f8aa162c6 [file] [log] [blame]
Howard Hinnantc51e1022010-05-11 19:42:16 +00001//===-------------------------- ios.cpp -----------------------------------===//
2//
Howard Hinnantc566dc32010-05-11 21:36:01 +00003// The LLVM Compiler Infrastructure
Howard Hinnantc51e1022010-05-11 19:42:16 +00004//
Howard Hinnantee11c312010-11-16 22:09:02 +00005// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantc51e1022010-05-11 19:42:16 +00007//
8//===----------------------------------------------------------------------===//
9
Jonathan Roelofs6552b1e2014-09-02 20:34:23 +000010#include "__config"
Dan Albertf0abdfa2015-01-06 17:34:51 +000011
Howard Hinnantc51e1022010-05-11 19:42:16 +000012#include "ios"
Dan Albertf0abdfa2015-01-06 17:34:51 +000013
14#include <stdlib.h>
15
Howard Hinnantc51e1022010-05-11 19:42:16 +000016#include "__locale"
17#include "algorithm"
Eric Fiselier1366d262015-08-18 21:08:54 +000018#include "include/config_elast.h"
Dan Albertf0abdfa2015-01-06 17:34:51 +000019#include "istream"
20#include "limits"
Howard Hinnantc51e1022010-05-11 19:42:16 +000021#include "memory"
22#include "new"
Dan Albertf0abdfa2015-01-06 17:34:51 +000023#include "streambuf"
24#include "string"
Eric Fiselierf4433a32017-05-31 22:07:49 +000025#include "__undef_macros"
Howard Hinnantc51e1022010-05-11 19:42:16 +000026
27_LIBCPP_BEGIN_NAMESPACE_STD
28
Shoaib Meenai5ac10672016-09-19 18:29:07 +000029template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS basic_ios<char>;
30template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS basic_ios<wchar_t>;
Howard Hinnantc51e1022010-05-11 19:42:16 +000031
Shoaib Meenai5ac10672016-09-19 18:29:07 +000032template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS basic_streambuf<char>;
33template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS basic_streambuf<wchar_t>;
Howard Hinnantc51e1022010-05-11 19:42:16 +000034
Shoaib Meenai5ac10672016-09-19 18:29:07 +000035template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS basic_istream<char>;
36template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS basic_istream<wchar_t>;
Howard Hinnantc51e1022010-05-11 19:42:16 +000037
Shoaib Meenai5ac10672016-09-19 18:29:07 +000038template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS basic_ostream<char>;
39template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS basic_ostream<wchar_t>;
Howard Hinnantc51e1022010-05-11 19:42:16 +000040
Shoaib Meenai5ac10672016-09-19 18:29:07 +000041template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS basic_iostream<char>;
Howard Hinnantc51e1022010-05-11 19:42:16 +000042
43class _LIBCPP_HIDDEN __iostream_category
44 : public __do_message
45{
46public:
Howard Hinnant1f098bc2011-05-26 19:48:01 +000047 virtual const char* name() const _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +000048 virtual string message(int ev) const;
49};
50
51const char*
Howard Hinnant1f098bc2011-05-26 19:48:01 +000052__iostream_category::name() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +000053{
54 return "iostream";
55}
56
57string
58__iostream_category::message(int ev) const
59{
Howard Hinnant155c2af2010-05-24 17:49:41 +000060 if (ev != static_cast<int>(io_errc::stream)
Jonathan Roelofs6552b1e2014-09-02 20:34:23 +000061#ifdef _LIBCPP_ELAST
62 && ev <= _LIBCPP_ELAST
63#endif // _LIBCPP_ELAST
Howard Hinnant155c2af2010-05-24 17:49:41 +000064 )
Howard Hinnantc51e1022010-05-11 19:42:16 +000065 return __do_message::message(ev);
66 return string("unspecified iostream_category error");
67}
68
69const error_category&
Marshall Clow3f138dc2013-10-12 22:49:56 +000070iostream_category() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +000071{
72 static __iostream_category s;
73 return s;
74}
75
76// ios_base::failure
77
78ios_base::failure::failure(const string& msg, const error_code& ec)
79 : system_error(ec, msg)
80{
81}
82
83ios_base::failure::failure(const char* msg, const error_code& ec)
84 : system_error(ec, msg)
85{
86}
87
88ios_base::failure::~failure() throw()
89{
90}
91
92// ios_base locale
93
94const ios_base::fmtflags ios_base::boolalpha;
95const ios_base::fmtflags ios_base::dec;
96const ios_base::fmtflags ios_base::fixed;
97const ios_base::fmtflags ios_base::hex;
98const ios_base::fmtflags ios_base::internal;
99const ios_base::fmtflags ios_base::left;
100const ios_base::fmtflags ios_base::oct;
101const ios_base::fmtflags ios_base::right;
102const ios_base::fmtflags ios_base::scientific;
103const ios_base::fmtflags ios_base::showbase;
104const ios_base::fmtflags ios_base::showpoint;
105const ios_base::fmtflags ios_base::showpos;
106const ios_base::fmtflags ios_base::skipws;
107const ios_base::fmtflags ios_base::unitbuf;
108const ios_base::fmtflags ios_base::uppercase;
109const ios_base::fmtflags ios_base::adjustfield;
110const ios_base::fmtflags ios_base::basefield;
111const ios_base::fmtflags ios_base::floatfield;
112
113const ios_base::iostate ios_base::badbit;
114const ios_base::iostate ios_base::eofbit;
115const ios_base::iostate ios_base::failbit;
116const ios_base::iostate ios_base::goodbit;
117
118const ios_base::openmode ios_base::app;
119const ios_base::openmode ios_base::ate;
120const ios_base::openmode ios_base::binary;
121const ios_base::openmode ios_base::in;
122const ios_base::openmode ios_base::out;
123const ios_base::openmode ios_base::trunc;
124
125void
126ios_base::__call_callbacks(event ev)
127{
128 for (size_t i = __event_size_; i;)
129 {
130 --i;
131 __fn_[i](ev, *this, __index_[i]);
132 }
133}
134
135// locale
136
137locale
138ios_base::imbue(const locale& newloc)
139{
140 static_assert(sizeof(locale) == sizeof(__loc_), "");
Joerg Sonnenbergerc7655a22014-01-04 17:43:00 +0000141 locale& loc_storage = *reinterpret_cast<locale*>(&__loc_);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000142 locale oldloc = loc_storage;
143 loc_storage = newloc;
144 __call_callbacks(imbue_event);
145 return oldloc;
146}
147
148locale
149ios_base::getloc() const
150{
Joerg Sonnenbergerc7655a22014-01-04 17:43:00 +0000151 const locale& loc_storage = *reinterpret_cast<const locale*>(&__loc_);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000152 return loc_storage;
153}
154
155// xalloc
Eric Fiselier8020b6c2015-08-19 17:21:46 +0000156#if defined(_LIBCPP_HAS_C_ATOMIC_IMP) && !defined(_LIBCPP_HAS_NO_THREADS)
Marshall Clowf9698ab2013-10-12 19:13:52 +0000157atomic<int> ios_base::__xindex_ = ATOMIC_VAR_INIT(0);
158#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000159int ios_base::__xindex_ = 0;
Marshall Clowf9698ab2013-10-12 19:13:52 +0000160#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000161
Marshall Clow6c9ddc22014-10-27 19:08:10 +0000162template <typename _Tp>
163static size_t __ios_new_cap(size_t __req_size, size_t __current_cap)
164{ // Precondition: __req_size > __current_cap
165 const size_t mx = std::numeric_limits<size_t>::max() / sizeof(_Tp);
166 if (__req_size < mx/2)
167 return _VSTD::max(2 * __current_cap, __req_size);
168 else
169 return mx;
170}
171
Howard Hinnantc51e1022010-05-11 19:42:16 +0000172int
173ios_base::xalloc()
174{
175 return __xindex_++;
176}
177
178long&
179ios_base::iword(int index)
180{
181 size_t req_size = static_cast<size_t>(index)+1;
182 if (req_size > __iarray_cap_)
183 {
Marshall Clow6c9ddc22014-10-27 19:08:10 +0000184 size_t newcap = __ios_new_cap<long>(req_size, __iarray_cap_);
185 long* iarray = static_cast<long*>(realloc(__iarray_, newcap * sizeof(long)));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000186 if (iarray == 0)
187 {
188 setstate(badbit);
189 static long error;
190 error = 0;
191 return error;
192 }
193 __iarray_ = iarray;
Marshall Clow6c9ddc22014-10-27 19:08:10 +0000194 for (long* p = __iarray_ + __iarray_size_; p < __iarray_ + newcap; ++p)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000195 *p = 0;
Marshall Clow6c9ddc22014-10-27 19:08:10 +0000196 __iarray_cap_ = newcap;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000197 }
198 __iarray_size_ = max<size_t>(__iarray_size_, req_size);
199 return __iarray_[index];
200}
201
202void*&
203ios_base::pword(int index)
204{
205 size_t req_size = static_cast<size_t>(index)+1;
206 if (req_size > __parray_cap_)
207 {
Marshall Clow6c9ddc22014-10-27 19:08:10 +0000208 size_t newcap = __ios_new_cap<void *>(req_size, __iarray_cap_);
209 void** parray = static_cast<void**>(realloc(__parray_, newcap * sizeof(void *)));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000210 if (parray == 0)
211 {
212 setstate(badbit);
213 static void* error;
214 error = 0;
215 return error;
216 }
217 __parray_ = parray;
Marshall Clow6c9ddc22014-10-27 19:08:10 +0000218 for (void** p = __parray_ + __parray_size_; p < __parray_ + newcap; ++p)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000219 *p = 0;
Marshall Clow6c9ddc22014-10-27 19:08:10 +0000220 __parray_cap_ = newcap;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000221 }
222 __parray_size_ = max<size_t>(__parray_size_, req_size);
223 return __parray_[index];
224}
225
226// register_callback
227
228void
229ios_base::register_callback(event_callback fn, int index)
230{
231 size_t req_size = __event_size_ + 1;
232 if (req_size > __event_cap_)
233 {
Marshall Clow6c9ddc22014-10-27 19:08:10 +0000234 size_t newcap = __ios_new_cap<event_callback>(req_size, __event_cap_);
235 event_callback* fns = static_cast<event_callback*>(realloc(__fn_, newcap * sizeof(event_callback)));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000236 if (fns == 0)
237 setstate(badbit);
238 __fn_ = fns;
Marshall Clow6c9ddc22014-10-27 19:08:10 +0000239 int* indxs = static_cast<int *>(realloc(__index_, newcap * sizeof(int)));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000240 if (indxs == 0)
241 setstate(badbit);
242 __index_ = indxs;
Marshall Clow6c9ddc22014-10-27 19:08:10 +0000243 __event_cap_ = newcap;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000244 }
245 __fn_[__event_size_] = fn;
246 __index_[__event_size_] = index;
247 ++__event_size_;
248}
249
250ios_base::~ios_base()
251{
252 __call_callbacks(erase_event);
Joerg Sonnenbergerc7655a22014-01-04 17:43:00 +0000253 locale& loc_storage = *reinterpret_cast<locale*>(&__loc_);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000254 loc_storage.~locale();
255 free(__fn_);
256 free(__index_);
257 free(__iarray_);
258 free(__parray_);
259}
260
261// iostate
262
263void
264ios_base::clear(iostate state)
265{
266 if (__rdbuf_)
267 __rdstate_ = state;
268 else
269 __rdstate_ = state | badbit;
Howard Hinnant72f73582010-08-11 17:04:31 +0000270#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000271 if (((state | (__rdbuf_ ? goodbit : badbit)) & __exceptions_) != 0)
272 throw failure("ios_base::clear");
Howard Hinnantffb308e2010-08-22 00:03:27 +0000273#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000274}
275
276// init
277
278void
279ios_base::init(void* sb)
280{
281 __rdbuf_ = sb;
282 __rdstate_ = __rdbuf_ ? goodbit : badbit;
283 __exceptions_ = goodbit;
284 __fmtflags_ = skipws | dec;
285 __width_ = 0;
286 __precision_ = 6;
287 __fn_ = 0;
288 __index_ = 0;
289 __event_size_ = 0;
290 __event_cap_ = 0;
291 __iarray_ = 0;
292 __iarray_size_ = 0;
293 __iarray_cap_ = 0;
294 __parray_ = 0;
295 __parray_size_ = 0;
296 __parray_cap_ = 0;
297 ::new(&__loc_) locale;
298}
299
300void
301ios_base::copyfmt(const ios_base& rhs)
302{
303 // If we can't acquire the needed resources, throw bad_alloc (can't set badbit)
Alp Tokerb8a95f52014-05-15 11:27:39 +0000304 // Don't alter *this until all needed resources are acquired
Howard Hinnantc51e1022010-05-11 19:42:16 +0000305 unique_ptr<event_callback, void (*)(void*)> new_callbacks(0, free);
306 unique_ptr<int, void (*)(void*)> new_ints(0, free);
307 unique_ptr<long, void (*)(void*)> new_longs(0, free);
308 unique_ptr<void*, void (*)(void*)> new_pointers(0, free);
309 if (__event_cap_ < rhs.__event_size_)
310 {
Joerg Sonnenbergerc7655a22014-01-04 17:43:00 +0000311 size_t newesize = sizeof(event_callback) * rhs.__event_size_;
312 new_callbacks.reset(static_cast<event_callback*>(malloc(newesize)));
Howard Hinnant72f73582010-08-11 17:04:31 +0000313#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000314 if (!new_callbacks)
315 throw bad_alloc();
Howard Hinnantffb308e2010-08-22 00:03:27 +0000316#endif // _LIBCPP_NO_EXCEPTIONS
Joerg Sonnenbergerc7655a22014-01-04 17:43:00 +0000317
318 size_t newisize = sizeof(int) * rhs.__event_size_;
319 new_ints.reset(static_cast<int *>(malloc(newisize)));
Howard Hinnant72f73582010-08-11 17:04:31 +0000320#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000321 if (!new_ints)
322 throw bad_alloc();
Howard Hinnantffb308e2010-08-22 00:03:27 +0000323#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000324 }
325 if (__iarray_cap_ < rhs.__iarray_size_)
326 {
Joerg Sonnenbergerc7655a22014-01-04 17:43:00 +0000327 size_t newsize = sizeof(long) * rhs.__iarray_size_;
328 new_longs.reset(static_cast<long*>(malloc(newsize)));
Howard Hinnant72f73582010-08-11 17:04:31 +0000329#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000330 if (!new_longs)
331 throw bad_alloc();
Howard Hinnantffb308e2010-08-22 00:03:27 +0000332#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000333 }
334 if (__parray_cap_ < rhs.__parray_size_)
335 {
Joerg Sonnenbergerc7655a22014-01-04 17:43:00 +0000336 size_t newsize = sizeof(void*) * rhs.__parray_size_;
337 new_pointers.reset(static_cast<void**>(malloc(newsize)));
Howard Hinnant72f73582010-08-11 17:04:31 +0000338#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000339 if (!new_pointers)
340 throw bad_alloc();
Howard Hinnantffb308e2010-08-22 00:03:27 +0000341#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000342 }
343 // Got everything we need. Copy everything but __rdstate_, __rdbuf_ and __exceptions_
344 __fmtflags_ = rhs.__fmtflags_;
345 __precision_ = rhs.__precision_;
346 __width_ = rhs.__width_;
Joerg Sonnenbergerc7655a22014-01-04 17:43:00 +0000347 locale& lhs_loc = *reinterpret_cast<locale*>(&__loc_);
348 const locale& rhs_loc = *reinterpret_cast<const locale*>(&rhs.__loc_);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000349 lhs_loc = rhs_loc;
350 if (__event_cap_ < rhs.__event_size_)
351 {
352 free(__fn_);
353 __fn_ = new_callbacks.release();
354 free(__index_);
355 __index_ = new_ints.release();
356 __event_cap_ = rhs.__event_size_;
357 }
358 for (__event_size_ = 0; __event_size_ < rhs.__event_size_; ++__event_size_)
359 {
360 __fn_[__event_size_] = rhs.__fn_[__event_size_];
361 __index_[__event_size_] = rhs.__index_[__event_size_];
362 }
363 if (__iarray_cap_ < rhs.__iarray_size_)
364 {
365 free(__iarray_);
366 __iarray_ = new_longs.release();
367 __iarray_cap_ = rhs.__iarray_size_;
368 }
369 for (__iarray_size_ = 0; __iarray_size_ < rhs.__iarray_size_; ++__iarray_size_)
370 __iarray_[__iarray_size_] = rhs.__iarray_[__iarray_size_];
371 if (__parray_cap_ < rhs.__parray_size_)
372 {
373 free(__parray_);
374 __parray_ = new_pointers.release();
375 __parray_cap_ = rhs.__parray_size_;
376 }
377 for (__parray_size_ = 0; __parray_size_ < rhs.__parray_size_; ++__parray_size_)
378 __parray_[__parray_size_] = rhs.__parray_[__parray_size_];
379}
380
381void
382ios_base::move(ios_base& rhs)
383{
384 // *this is uninitialized
385 __fmtflags_ = rhs.__fmtflags_;
386 __precision_ = rhs.__precision_;
387 __width_ = rhs.__width_;
388 __rdstate_ = rhs.__rdstate_;
389 __exceptions_ = rhs.__exceptions_;
390 __rdbuf_ = 0;
Joerg Sonnenbergerc7655a22014-01-04 17:43:00 +0000391 locale& rhs_loc = *reinterpret_cast<locale*>(&rhs.__loc_);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000392 ::new(&__loc_) locale(rhs_loc);
393 __fn_ = rhs.__fn_;
394 rhs.__fn_ = 0;
395 __index_ = rhs.__index_;
396 rhs.__index_ = 0;
397 __event_size_ = rhs.__event_size_;
398 rhs.__event_size_ = 0;
399 __event_cap_ = rhs.__event_cap_;
400 rhs.__event_cap_ = 0;
401 __iarray_ = rhs.__iarray_;
402 rhs.__iarray_ = 0;
403 __iarray_size_ = rhs.__iarray_size_;
404 rhs.__iarray_size_ = 0;
405 __iarray_cap_ = rhs.__iarray_cap_;
406 rhs.__iarray_cap_ = 0;
407 __parray_ = rhs.__parray_;
408 rhs.__parray_ = 0;
409 __parray_size_ = rhs.__parray_size_;
410 rhs.__parray_size_ = 0;
411 __parray_cap_ = rhs.__parray_cap_;
412 rhs.__parray_cap_ = 0;
413}
414
415void
Howard Hinnant770a3662012-07-21 01:03:40 +0000416ios_base::swap(ios_base& rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000417{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000418 _VSTD::swap(__fmtflags_, rhs.__fmtflags_);
419 _VSTD::swap(__precision_, rhs.__precision_);
420 _VSTD::swap(__width_, rhs.__width_);
421 _VSTD::swap(__rdstate_, rhs.__rdstate_);
422 _VSTD::swap(__exceptions_, rhs.__exceptions_);
Joerg Sonnenbergerc7655a22014-01-04 17:43:00 +0000423 locale& lhs_loc = *reinterpret_cast<locale*>(&__loc_);
424 locale& rhs_loc = *reinterpret_cast<locale*>(&rhs.__loc_);
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000425 _VSTD::swap(lhs_loc, rhs_loc);
426 _VSTD::swap(__fn_, rhs.__fn_);
427 _VSTD::swap(__index_, rhs.__index_);
428 _VSTD::swap(__event_size_, rhs.__event_size_);
429 _VSTD::swap(__event_cap_, rhs.__event_cap_);
430 _VSTD::swap(__iarray_, rhs.__iarray_);
431 _VSTD::swap(__iarray_size_, rhs.__iarray_size_);
432 _VSTD::swap(__iarray_cap_, rhs.__iarray_cap_);
433 _VSTD::swap(__parray_, rhs.__parray_);
434 _VSTD::swap(__parray_size_, rhs.__parray_size_);
435 _VSTD::swap(__parray_cap_, rhs.__parray_cap_);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000436}
437
438void
439ios_base::__set_badbit_and_consider_rethrow()
440{
441 __rdstate_ |= badbit;
Howard Hinnant72f73582010-08-11 17:04:31 +0000442#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000443 if (__exceptions_ & badbit)
444 throw;
Howard Hinnantffb308e2010-08-22 00:03:27 +0000445#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000446}
447
448void
449ios_base::__set_failbit_and_consider_rethrow()
450{
451 __rdstate_ |= failbit;
Howard Hinnant72f73582010-08-11 17:04:31 +0000452#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000453 if (__exceptions_ & failbit)
454 throw;
Howard Hinnantffb308e2010-08-22 00:03:27 +0000455#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000456}
457
458bool
459ios_base::sync_with_stdio(bool sync)
460{
461 static bool previous_state = true;
462 bool r = previous_state;
463 previous_state = sync;
464 return r;
465}
466
467_LIBCPP_END_NAMESPACE_STD