OSDN Git Service

9fb234b03b21841f587f5d7de51aa7f21ce58691
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / include / bits / locale_facets.tcc
1 // Locale support -*- C++ -*-
2
3 // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004
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.
11
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.
16
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.
21
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.
30
31 // Warning: this file is not meant for user inclusion. Use <locale>.
32
33 #ifndef _LOCALE_FACETS_TCC
34 #define _LOCALE_FACETS_TCC 1
35
36 #pragma GCC system_header
37
38 #include <limits>               // For numeric_limits
39 #include <typeinfo>             // For bad_cast.
40 #include <bits/streambuf_iterator.h>
41
42 namespace std
43 {
44   template<typename _Facet>
45     locale
46     locale::combine(const locale& __other) const
47     {
48       _Impl* __tmp = new _Impl(*_M_impl, 1);
49       try
50         {
51           __tmp->_M_replace_facet(__other._M_impl, &_Facet::id);
52         }
53       catch(...)
54         {
55           __tmp->_M_remove_reference();
56           __throw_exception_again;
57         }
58       return locale(__tmp);
59     }
60
61   template<typename _CharT, typename _Traits, typename _Alloc>
62     bool
63     locale::operator()(const basic_string<_CharT, _Traits, _Alloc>& __s1,
64                        const basic_string<_CharT, _Traits, _Alloc>& __s2) const
65     {
66       typedef std::collate<_CharT> __collate_type;
67       const __collate_type& __collate = use_facet<__collate_type>(*this);
68       return (__collate.compare(__s1.data(), __s1.data() + __s1.length(),
69                                 __s2.data(), __s2.data() + __s2.length()) < 0);
70     }
71
72   /**
73    *  @brief  Test for the presence of a facet.
74    *
75    *  has_facet tests the locale argument for the presence of the facet type
76    *  provided as the template parameter.  Facets derived from the facet
77    *  parameter will also return true.
78    *
79    *  @param  Facet  The facet type to test the presence of.
80    *  @param  locale  The locale to test.
81    *  @return  true if locale contains a facet of type Facet, else false.
82    *  @throw  std::bad_cast if locale doesn't contain the facet.
83   */
84   template<typename _Facet>
85     inline bool
86     has_facet(const locale& __loc) throw()
87     {
88       const size_t __i = _Facet::id._M_id();
89       const locale::facet** __facets = __loc._M_impl->_M_facets;
90       return (__i < __loc._M_impl->_M_facets_size && __facets[__i]);
91     }
92
93   /**
94    *  @brief  Return a facet.
95    *
96    *  use_facet looks for and returns a reference to a facet of type Facet
97    *  where Facet is the template parameter.  If has_facet(locale) is true,
98    *  there is a suitable facet to return.  It throws std::bad_cast if the
99    *  locale doesn't contain a facet of type Facet.
100    *
101    *  @param  Facet  The facet type to access.
102    *  @param  locale  The locale to use.
103    *  @return  Reference to facet of type Facet.
104    *  @throw  std::bad_cast if locale doesn't contain a facet of type Facet.
105   */
106   template<typename _Facet>
107     inline const _Facet&
108     use_facet(const locale& __loc)
109     {
110       const size_t __i = _Facet::id._M_id();
111       const locale::facet** __facets = __loc._M_impl->_M_facets;
112       if (!(__i < __loc._M_impl->_M_facets_size && __facets[__i]))
113         __throw_bad_cast();
114       return static_cast<const _Facet&>(*__facets[__i]);
115     }
116
117   // Routine to access a cache for the facet.  If the cache didn't
118   // exist before, it gets constructed on the fly.
119   template<typename _Facet>
120     struct __use_cache
121     {
122       const _Facet*
123       operator() (const locale& __loc) const;
124     };
125
126   template<typename _CharT>
127     struct __use_cache<__numpunct_cache<_CharT> >
128     {
129       const __numpunct_cache<_CharT>*
130       operator() (const locale& __loc) const
131       {
132         const size_t __i = numpunct<_CharT>::id._M_id();
133         const locale::facet** __caches = __loc._M_impl->_M_caches;
134         if (!__caches[__i])
135           {
136             __numpunct_cache<_CharT>* __tmp = NULL;
137             try
138               {
139                 __tmp = new __numpunct_cache<_CharT>;
140                 __tmp->_M_cache(__loc);
141               }
142             catch(...)
143               {
144                 delete __tmp;
145                 __throw_exception_again;
146               }
147             __loc._M_impl->_M_install_cache(__tmp, __i);
148           }
149         return static_cast<const __numpunct_cache<_CharT>*>(__caches[__i]);
150       }
151     };
152
153   // Used by both numeric and monetary facets.
154   // Check to make sure that the __grouping_tmp string constructed in
155   // money_get or num_get matches the canonical grouping for a given
156   // locale.
157   // __grouping_tmp is parsed L to R
158   // 1,222,444 == __grouping_tmp of "\1\3\3"
159   // __grouping is parsed R to L
160   // 1,222,444 == __grouping of "\3" == "\3\3\3"
161   static bool
162   __verify_grouping(const char* __grouping, size_t __grouping_size,
163                     const string& __grouping_tmp);
164
165   template<typename _CharT, typename _InIter>
166     _InIter
167     num_get<_CharT, _InIter>::
168     _M_extract_float(_InIter __beg, _InIter __end, ios_base& __io,
169                      ios_base::iostate& __err, string& __xtrc) const
170     {
171       typedef char_traits<_CharT>                       __traits_type;
172       typedef typename numpunct<_CharT>::__cache_type   __cache_type;
173       __use_cache<__cache_type> __uc;
174       const locale& __loc = __io._M_getloc();
175       const __cache_type* __lc = __uc(__loc);
176       const _CharT* __lit = __lc->_M_atoms_in;
177
178       // True if a mantissa is found.
179       bool __found_mantissa = false;
180
181       // First check for sign.
182       if (__beg != __end)
183         {
184           const char_type __c = *__beg;
185           const bool __plus = __traits_type::eq(__c, __lit[_S_iplus]);
186           if ((__plus || __traits_type::eq(__c, __lit[_S_iminus]))
187               && (!__lc->_M_use_grouping
188                   || !__traits_type::eq(__c, __lc->_M_thousands_sep))
189               && !__traits_type::eq(__c, __lc->_M_decimal_point))
190             {
191               __xtrc += __plus ? '+' : '-';
192               ++__beg;
193             }
194         }
195
196       // Next, look for leading zeros.
197       while (__beg != __end)
198         {
199           const char_type __c = *__beg;
200           if (__lc->_M_use_grouping
201               && __traits_type::eq(__c, __lc->_M_thousands_sep)
202               || __traits_type::eq(__c, __lc->_M_decimal_point))
203             break;
204           else if (__traits_type::eq(__c, __lit[_S_izero]))
205             {
206               if (!__found_mantissa)
207                 {
208                   __xtrc += '0';
209                   __found_mantissa = true;
210                 }
211               ++__beg;
212             }
213           else
214             break;
215         }
216
217       // Only need acceptable digits for floating point numbers.
218       bool __found_dec = false;
219       bool __found_sci = false;
220       string __found_grouping;
221       if (__lc->_M_use_grouping)
222         __found_grouping.reserve(32);
223       int __sep_pos = 0;
224       const char_type* __lit_zero = __lit + _S_izero;
225       const char_type* __q;
226       while (__beg != __end)
227         {
228           // According to 22.2.2.1.2, p8-9, first look for thousands_sep
229           // and decimal_point.
230           const char_type __c = *__beg;
231           if (__lc->_M_use_grouping
232               && __traits_type::eq(__c, __lc->_M_thousands_sep))
233             {
234               if (!__found_dec && !__found_sci)
235                 {
236                   // NB: Thousands separator at the beginning of a string
237                   // is a no-no, as is two consecutive thousands separators.
238                   if (__sep_pos)
239                     {
240                       __found_grouping += static_cast<char>(__sep_pos);
241                       __sep_pos = 0;
242                       ++__beg;
243                     }
244                   else
245                     {
246                       __err |= ios_base::failbit;
247                       break;
248                     }
249                 }
250               else
251                 break;
252             }
253           else if (__traits_type::eq(__c, __lc->_M_decimal_point))
254             {
255               if (!__found_dec && !__found_sci)
256                 {
257                   // If no grouping chars are seen, no grouping check
258                   // is applied. Therefore __found_grouping is adjusted
259                   // only if decimal_point comes after some thousands_sep.
260                   if (__found_grouping.size())
261                     __found_grouping += static_cast<char>(__sep_pos);
262                   __xtrc += '.';
263                   __found_dec = true;
264                   ++__beg;
265                 }
266               else
267                 break;
268             }
269           else if (__q = __traits_type::find(__lit_zero, 10, __c))
270             {
271               __xtrc += _S_atoms_in[__q - __lit];
272               __found_mantissa = true;
273               ++__sep_pos;
274               ++__beg;
275             }
276           else if ((__traits_type::eq(__c, __lit[_S_ie])
277                     || __traits_type::eq(__c, __lit[_S_iE]))
278                    && __found_mantissa && !__found_sci)
279             {
280               // Scientific notation.
281               if (__found_grouping.size() && !__found_dec)
282                 __found_grouping += static_cast<char>(__sep_pos);
283               __xtrc += 'e';
284               __found_sci = true;
285
286               // Remove optional plus or minus sign, if they exist.
287               if (++__beg != __end)
288                 {
289                   const bool __plus = __traits_type::eq(*__beg,
290                                                         __lit[_S_iplus]);
291                   if ((__plus || __traits_type::eq(*__beg, __lit[_S_iminus]))
292                       && (!__lc->_M_use_grouping
293                           || !__traits_type::eq(*__beg, __lc->_M_thousands_sep))
294                       && !__traits_type::eq(*__beg, __lc->_M_decimal_point))
295                     {
296                       __xtrc += __plus ? '+' : '-';
297                       ++__beg;
298                     }
299                 }
300             }
301           else
302             // Not a valid input item.
303             break;
304         }
305
306       // Digit grouping is checked. If grouping and found_grouping don't
307       // match, then get very very upset, and set failbit.
308       if (__found_grouping.size())
309         {
310           // Add the ending grouping if a decimal or 'e'/'E' wasn't found.
311           if (!__found_dec && !__found_sci)
312             __found_grouping += static_cast<char>(__sep_pos);
313
314           if (!std::__verify_grouping(__lc->_M_grouping, __lc->_M_grouping_size,
315                                       __found_grouping))
316             __err |= ios_base::failbit;
317         }
318
319       // Finish up.
320       if (__beg == __end)
321         __err |= ios_base::eofbit;
322       return __beg;
323     }
324
325   template<typename _CharT, typename _InIter>
326     template<typename _ValueT>
327       _InIter
328       num_get<_CharT, _InIter>::
329       _M_extract_int(_InIter __beg, _InIter __end, ios_base& __io,
330                      ios_base::iostate& __err, _ValueT& __v) const
331       {
332         typedef char_traits<_CharT>                     __traits_type;
333         typedef typename numpunct<_CharT>::__cache_type __cache_type;
334         __use_cache<__cache_type> __uc;
335         const locale& __loc = __io._M_getloc();
336         const __cache_type* __lc = __uc(__loc);
337         const _CharT* __lit = __lc->_M_atoms_in;
338
339         // NB: Iff __basefield == 0, __base can change based on contents.
340         const ios_base::fmtflags __basefield = __io.flags()
341                                                & ios_base::basefield;
342         const bool __oct = __basefield == ios_base::oct;
343         int __base = __oct ? 8 : (__basefield == ios_base::hex ? 16 : 10);
344
345         // True if numeric digits are found.
346         bool __found_num = false;
347
348         // First check for sign.
349         bool __negative = false;
350         if (__beg != __end)
351           {
352             const char_type __c = *__beg;
353             if (numeric_limits<_ValueT>::is_signed)
354               __negative = __traits_type::eq(__c, __lit[_S_iminus]);
355             if ((__negative || __traits_type::eq(__c, __lit[_S_iplus]))
356                 && (!__lc->_M_use_grouping
357                     || !__traits_type::eq(__c, __lc->_M_thousands_sep))
358                 && !__traits_type::eq(__c, __lc->_M_decimal_point))
359               ++__beg;
360           }
361
362         // Next, look for leading zeros and check required digits
363         // for base formats.
364         while (__beg != __end)
365           {
366             const char_type __c = *__beg;
367             if (__lc->_M_use_grouping
368                 && __traits_type::eq(__c, __lc->_M_thousands_sep)
369                 || __traits_type::eq(__c, __lc->_M_decimal_point))
370               break;
371             else if (__traits_type::eq(__c, __lit[_S_izero])
372                      && (!__found_num || __base == 10))
373               {
374                 __found_num = true;
375                 ++__beg;
376               }
377             else if (__found_num)
378               {
379                 if (__traits_type::eq(__c, __lit[_S_ix])
380                     || __traits_type::eq(__c, __lit[_S_iX]))
381                   {
382                     if (__basefield == 0)
383                       __base = 16;
384                     if (__base == 16)
385                       {
386                         __found_num = false;
387                         ++__beg;
388                       }
389                   }
390                 else if (__basefield == 0)
391                   __base = 8;
392                 break;
393               }
394             else
395               break;
396           }
397
398         // At this point, base is determined. If not hex, only allow
399         // base digits as valid input.
400         const size_t __len = __base == 16 ? _S_iend - _S_izero : __base;
401
402         // Extract.
403         string __found_grouping;
404         if (__lc->_M_use_grouping)
405           __found_grouping.reserve(32);
406         int __sep_pos = 0;
407         bool __overflow = false;
408         _ValueT __result = 0;
409         const char_type* __lit_zero = __lit + _S_izero;
410         const char_type* __q;
411         if (__negative)
412           {
413             const _ValueT __min = numeric_limits<_ValueT>::min() / __base;
414             for (; __beg != __end; ++__beg)
415               {
416                 // According to 22.2.2.1.2, p8-9, first look for thousands_sep
417                 // and decimal_point.
418                 const char_type __c = *__beg;
419                 if (__lc->_M_use_grouping
420                     && __traits_type::eq(__c, __lc->_M_thousands_sep))
421                   {
422                     // NB: Thousands separator at the beginning of a string
423                     // is a no-no, as is two consecutive thousands separators.
424                     if (__sep_pos)
425                       {
426                         __found_grouping += static_cast<char>(__sep_pos);
427                         __sep_pos = 0;
428                       }
429                     else
430                       {
431                         __err |= ios_base::failbit;
432                         break;
433                       }
434                   }
435                 else if (__traits_type::eq(__c, __lc->_M_decimal_point))
436                   break;
437                 else if (__q = __traits_type::find(__lit_zero, __len, __c))
438                   {
439                     int __digit = __q - __lit_zero;
440                     if (__digit > 15)
441                       __digit -= 6;
442                     if (__result < __min)
443                       __overflow = true;
444                     else
445                       {
446                         const _ValueT __new_result = __result * __base
447                                                      - __digit;
448                         __overflow |= __new_result > __result;
449                         __result = __new_result;
450                         ++__sep_pos;
451                         __found_num = true;
452                       }
453                   }
454                 else
455                   // Not a valid input item.
456                   break;
457               }
458           }
459         else
460           {
461             const _ValueT __max = numeric_limits<_ValueT>::max() / __base;
462             for (; __beg != __end; ++__beg)
463               {
464                 const char_type __c = *__beg;
465                 if (__lc->_M_use_grouping
466                     && __traits_type::eq(__c, __lc->_M_thousands_sep))
467                   {
468                     if (__sep_pos)
469                       {
470                         __found_grouping += static_cast<char>(__sep_pos);
471                         __sep_pos = 0;
472                       }
473                     else
474                       {
475                         __err |= ios_base::failbit;
476                         break;
477                       }
478                   }
479                 else if (__traits_type::eq(__c, __lc->_M_decimal_point))
480                   break;
481                 else if (__q = __traits_type::find(__lit_zero, __len, __c))
482                   {
483                     int __digit = __q - __lit_zero;
484                     if (__digit > 15)
485                       __digit -= 6;
486                     if (__result > __max)
487                       __overflow = true;
488                     else
489                       {
490                         const _ValueT __new_result = __result * __base
491                                                      + __digit;
492                         __overflow |= __new_result < __result;
493                         __result = __new_result;
494                         ++__sep_pos;
495                         __found_num = true;
496                       }
497                   }
498                 else
499                   break;
500               }
501           }
502
503         // Digit grouping is checked. If grouping and found_grouping don't
504         // match, then get very very upset, and set failbit.
505         if (__found_grouping.size())
506           {
507             // Add the ending grouping.
508             __found_grouping += static_cast<char>(__sep_pos);
509
510             if (!std::__verify_grouping(__lc->_M_grouping,
511                                         __lc->_M_grouping_size,
512                                         __found_grouping))
513               __err |= ios_base::failbit;
514           }
515
516         if (!(__err & ios_base::failbit) && !__overflow
517             && __found_num)
518           __v = __result;
519         else
520           __err |= ios_base::failbit;
521
522         if (__beg == __end)
523           __err |= ios_base::eofbit;
524         return __beg;
525       }
526
527   // _GLIBCXX_RESOLVE_LIB_DEFECTS
528   // 17.  Bad bool parsing
529   template<typename _CharT, typename _InIter>
530     _InIter
531     num_get<_CharT, _InIter>::
532     do_get(iter_type __beg, iter_type __end, ios_base& __io,
533            ios_base::iostate& __err, bool& __v) const
534     {
535       if (!(__io.flags() & ios_base::boolalpha))
536         {
537           // Parse bool values as long.
538           // NB: We can't just call do_get(long) here, as it might
539           // refer to a derived class.
540           long __l = -1;
541           __beg = _M_extract_int(__beg, __end, __io, __err, __l);
542           if (__l == 0 || __l == 1)
543             __v = __l;
544           else
545             __err |= ios_base::failbit;
546         }
547       else
548         {
549           // Parse bool values as alphanumeric.
550           typedef char_traits<_CharT>                     __traits_type;
551           typedef typename numpunct<_CharT>::__cache_type __cache_type;
552           __use_cache<__cache_type> __uc;
553           const locale& __loc = __io._M_getloc();
554           const __cache_type* __lc = __uc(__loc);
555
556           bool __testf = true;
557           bool __testt = true;
558           size_t __n;
559           for (__n = 0; __beg != __end; ++__n, ++__beg)
560             {
561               if (__testf)
562                 if (__n < __lc->_M_falsename_size)
563                   __testf = __traits_type::eq(*__beg, __lc->_M_falsename[__n]);
564                 else
565                   break;
566
567               if (__testt)
568                 if (__n < __lc->_M_truename_size)
569                   __testt = __traits_type::eq(*__beg, __lc->_M_truename[__n]);
570                 else
571                   break;
572
573               if (!__testf && !__testt)
574                 break;
575             }
576           if (__testf && __n == __lc->_M_falsename_size)
577             __v = 0;
578           else if (__testt && __n == __lc->_M_truename_size)
579             __v = 1;
580           else
581             __err |= ios_base::failbit;
582
583           if (__beg == __end)
584             __err |= ios_base::eofbit;
585         }
586       return __beg;
587     }
588
589   template<typename _CharT, typename _InIter>
590     _InIter
591     num_get<_CharT, _InIter>::
592     do_get(iter_type __beg, iter_type __end, ios_base& __io,
593            ios_base::iostate& __err, long& __v) const
594     { return _M_extract_int(__beg, __end, __io, __err, __v); }
595
596   template<typename _CharT, typename _InIter>
597     _InIter
598     num_get<_CharT, _InIter>::
599     do_get(iter_type __beg, iter_type __end, ios_base& __io,
600            ios_base::iostate& __err, unsigned short& __v) const
601     { return _M_extract_int(__beg, __end, __io, __err, __v); }
602
603   template<typename _CharT, typename _InIter>
604     _InIter
605     num_get<_CharT, _InIter>::
606     do_get(iter_type __beg, iter_type __end, ios_base& __io,
607            ios_base::iostate& __err, unsigned int& __v) const
608     { return _M_extract_int(__beg, __end, __io, __err, __v); }
609
610   template<typename _CharT, typename _InIter>
611     _InIter
612     num_get<_CharT, _InIter>::
613     do_get(iter_type __beg, iter_type __end, ios_base& __io,
614            ios_base::iostate& __err, unsigned long& __v) const
615     { return _M_extract_int(__beg, __end, __io, __err, __v); }
616
617 #ifdef _GLIBCXX_USE_LONG_LONG
618   template<typename _CharT, typename _InIter>
619     _InIter
620     num_get<_CharT, _InIter>::
621     do_get(iter_type __beg, iter_type __end, ios_base& __io,
622            ios_base::iostate& __err, long long& __v) const
623     { return _M_extract_int(__beg, __end, __io, __err, __v); }
624
625   template<typename _CharT, typename _InIter>
626     _InIter
627     num_get<_CharT, _InIter>::
628     do_get(iter_type __beg, iter_type __end, ios_base& __io,
629            ios_base::iostate& __err, unsigned long long& __v) const
630     { return _M_extract_int(__beg, __end, __io, __err, __v); }
631 #endif
632
633   template<typename _CharT, typename _InIter>
634     _InIter
635     num_get<_CharT, _InIter>::
636     do_get(iter_type __beg, iter_type __end, ios_base& __io,
637            ios_base::iostate& __err, float& __v) const
638     {
639       string __xtrc;
640       __xtrc.reserve(32);
641       __beg = _M_extract_float(__beg, __end, __io, __err, __xtrc);
642       std::__convert_to_v(__xtrc.c_str(), __v, __err, _S_get_c_locale());
643       return __beg;
644     }
645
646   template<typename _CharT, typename _InIter>
647     _InIter
648     num_get<_CharT, _InIter>::
649     do_get(iter_type __beg, iter_type __end, ios_base& __io,
650            ios_base::iostate& __err, double& __v) const
651     {
652       string __xtrc;
653       __xtrc.reserve(32);
654       __beg = _M_extract_float(__beg, __end, __io, __err, __xtrc);
655       std::__convert_to_v(__xtrc.c_str(), __v, __err, _S_get_c_locale());
656       return __beg;
657     }
658
659   template<typename _CharT, typename _InIter>
660     _InIter
661     num_get<_CharT, _InIter>::
662     do_get(iter_type __beg, iter_type __end, ios_base& __io,
663            ios_base::iostate& __err, long double& __v) const
664     {
665       string __xtrc;
666       __xtrc.reserve(32);
667       __beg = _M_extract_float(__beg, __end, __io, __err, __xtrc);
668       std::__convert_to_v(__xtrc.c_str(), __v, __err, _S_get_c_locale());
669       return __beg;
670     }
671
672   template<typename _CharT, typename _InIter>
673     _InIter
674     num_get<_CharT, _InIter>::
675     do_get(iter_type __beg, iter_type __end, ios_base& __io,
676            ios_base::iostate& __err, void*& __v) const
677     {
678       // Prepare for hex formatted input.
679       typedef ios_base::fmtflags        fmtflags;
680       const fmtflags __fmt = __io.flags();
681       __io.flags(__fmt & ~ios_base::basefield | ios_base::hex);
682
683       unsigned long __ul;
684       __beg = _M_extract_int(__beg, __end, __io, __err, __ul);
685
686       // Reset from hex formatted input.
687       __io.flags(__fmt);
688
689       if (!(__err & ios_base::failbit))
690         __v = reinterpret_cast<void*>(__ul);
691       else
692         __err |= ios_base::failbit;
693       return __beg;
694     }
695
696   // For use by integer and floating-point types after they have been
697   // converted into a char_type string.
698   template<typename _CharT, typename _OutIter>
699     void
700     num_put<_CharT, _OutIter>::
701     _M_pad(_CharT __fill, streamsize __w, ios_base& __io,
702            _CharT* __new, const _CharT* __cs, int& __len) const
703     {
704       // [22.2.2.2.2] Stage 3.
705       // If necessary, pad.
706       __pad<_CharT, char_traits<_CharT> >::_S_pad(__io, __fill, __new, __cs,
707                                                   __w, __len, true);
708       __len = static_cast<int>(__w);
709     }
710
711   // Forwarding functions to peel signed from unsigned integer types.
712   template<typename _CharT>
713     inline int
714     __int_to_char(_CharT* __bufend, long __v, const _CharT* __lit,
715                   ios_base::fmtflags __flags)
716     {
717       unsigned long __ul = static_cast<unsigned long>(__v);
718       bool __neg = false;
719       if (__v < 0)
720         {
721           __ul = -__ul;
722           __neg = true;
723         }
724       return __int_to_char(__bufend, __ul, __lit, __flags, __neg);
725     }
726
727   template<typename _CharT>
728     inline int
729     __int_to_char(_CharT* __bufend, unsigned long __v, const _CharT* __lit,
730                   ios_base::fmtflags __flags)
731     { return __int_to_char(__bufend, __v, __lit, __flags, false); }
732
733 #ifdef _GLIBCXX_USE_LONG_LONG
734   template<typename _CharT>
735     inline int
736     __int_to_char(_CharT* __bufend, long long __v, const _CharT* __lit,
737                   ios_base::fmtflags __flags)
738     {
739       unsigned long long __ull = static_cast<unsigned long long>(__v);
740       bool __neg = false;
741       if (__v < 0)
742         {
743           __ull = -__ull;
744           __neg = true;
745         }
746       return __int_to_char(__bufend, __ull, __lit, __flags, __neg);
747     }
748
749   template<typename _CharT>
750     inline int
751     __int_to_char(_CharT* __bufend, unsigned long long __v, const _CharT* __lit,
752                   ios_base::fmtflags __flags)
753     { return __int_to_char(__bufend, __v, __lit, __flags, false); }
754 #endif
755
756   template<typename _CharT, typename _ValueT>
757     int
758     __int_to_char(_CharT* __bufend, _ValueT __v, const _CharT* __lit,
759                   ios_base::fmtflags __flags, bool __neg)
760     {
761       // Don't write base if already 0.
762       const bool __showbase = (__flags & ios_base::showbase) && __v;
763       const ios_base::fmtflags __basefield = __flags & ios_base::basefield;
764       _CharT* __buf = __bufend - 1;
765
766       if (__builtin_expect(__basefield != ios_base::oct &&
767                            __basefield != ios_base::hex, true))
768         {
769           // Decimal.
770           do
771             {
772               *__buf-- = __lit[(__v % 10) + __num_base::_S_odigits];
773               __v /= 10;
774             }
775           while (__v != 0);
776           if (__neg)
777             *__buf-- = __lit[__num_base::_S_ominus];
778           else if (__flags & ios_base::showpos)
779             *__buf-- = __lit[__num_base::_S_oplus];
780         }
781       else if (__basefield == ios_base::oct)
782         {
783           // Octal.
784           do
785             {
786               *__buf-- = __lit[(__v & 0x7) + __num_base::_S_odigits];
787               __v >>= 3;
788             }
789           while (__v != 0);
790           if (__showbase)
791             *__buf-- = __lit[__num_base::_S_odigits];
792         }
793       else
794         {
795           // Hex.
796           const bool __uppercase = __flags & ios_base::uppercase;
797           const int __case_offset = __uppercase ? __num_base::_S_oudigits
798                                                 : __num_base::_S_odigits;
799           do
800             {
801               *__buf-- = __lit[(__v & 0xf) + __case_offset];
802               __v >>= 4;
803             }
804           while (__v != 0);
805           if (__showbase)
806             {
807               // 'x' or 'X'
808               *__buf-- = __lit[__num_base::_S_ox + __uppercase];
809               // '0'
810               *__buf-- = __lit[__num_base::_S_odigits];
811             }
812         }
813       return __bufend - __buf - 1;
814     }
815
816   template<typename _CharT, typename _OutIter>
817     void
818     num_put<_CharT, _OutIter>::
819     _M_group_int(const char* __grouping, size_t __grouping_size, _CharT __sep,
820                  ios_base& __io, _CharT* __new, _CharT* __cs, int& __len) const
821     {
822       // By itself __add_grouping cannot deal correctly with __cs when
823       // ios::showbase is set and ios_base::oct || ios_base::hex.
824       // Therefore we take care "by hand" of the initial 0, 0x or 0X.
825       // However, remember that the latter do not occur if the number
826       // printed is '0' (__len == 1).
827       streamsize __off = 0;
828       const ios_base::fmtflags __basefield = __io.flags()
829                                              & ios_base::basefield;
830       if ((__io.flags() & ios_base::showbase) && __len > 1)
831         if (__basefield == ios_base::oct)
832           {
833             __off = 1;
834             __new[0] = __cs[0];
835           }
836         else if (__basefield == ios_base::hex)
837           {
838             __off = 2;
839             __new[0] = __cs[0];
840             __new[1] = __cs[1];
841           }
842       _CharT* __p;
843       __p = std::__add_grouping(__new + __off, __sep, __grouping,
844                                 __grouping_size, __cs + __off,
845                                 __cs + __len);
846       __len = __p - __new;
847     }
848
849   template<typename _CharT, typename _OutIter>
850     template<typename _ValueT>
851       _OutIter
852       num_put<_CharT, _OutIter>::
853       _M_insert_int(_OutIter __s, ios_base& __io, _CharT __fill,
854                     _ValueT __v) const
855       {
856         typedef typename numpunct<_CharT>::__cache_type __cache_type;
857         __use_cache<__cache_type> __uc;
858         const locale& __loc = __io._M_getloc();
859         const __cache_type* __lc = __uc(__loc);
860         const _CharT* __lit = __lc->_M_atoms_out;
861
862         // Long enough to hold hex, dec, and octal representations.
863         const int __ilen = 4 * sizeof(_ValueT);
864         _CharT* __cs = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT)
865                                                              * __ilen));
866
867         // [22.2.2.2.2] Stage 1, numeric conversion to character.
868         // Result is returned right-justified in the buffer.
869         int __len;
870         __len = __int_to_char(__cs + __ilen, __v, __lit, __io.flags());
871         __cs += __ilen - __len;
872
873         // Add grouping, if necessary.
874         if (__lc->_M_use_grouping)
875           {
876             // Grouping can add (almost) as many separators as the
877             // number of digits, but no more.
878             _CharT* __cs2 = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT)
879                                                                   * __len * 2));
880             _M_group_int(__lc->_M_grouping, __lc->_M_grouping_size,
881                          __lc->_M_thousands_sep, __io, __cs2, __cs, __len);
882             __cs = __cs2;
883           }
884
885         // Pad.
886         const streamsize __w = __io.width();
887         if (__w > static_cast<streamsize>(__len))
888           {
889             _CharT* __cs3 = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT)
890                                                                   * __w));
891             _M_pad(__fill, __w, __io, __cs3, __cs, __len);
892             __cs = __cs3;
893           }
894         __io.width(0);
895
896         // [22.2.2.2.2] Stage 4.
897         // Write resulting, fully-formatted string to output iterator.
898         return std::__write(__s, __cs, __len);
899       }
900
901   template<typename _CharT, typename _OutIter>
902     void
903     num_put<_CharT, _OutIter>::
904     _M_group_float(const char* __grouping, size_t __grouping_size,
905                    _CharT __sep, const _CharT* __p, _CharT* __new,
906                    _CharT* __cs, int& __len) const
907     {
908       // _GLIBCXX_RESOLVE_LIB_DEFECTS
909       // 282. What types does numpunct grouping refer to?
910       // Add grouping, if necessary.
911       _CharT* __p2;
912       const int __declen = __p ? __p - __cs : __len;
913       __p2 = std::__add_grouping(__new, __sep, __grouping, __grouping_size,
914                                  __cs, __cs + __declen);
915
916       // Tack on decimal part.
917       int __newlen = __p2 - __new;
918       if (__p)
919         {
920           char_traits<_CharT>::copy(__p2, __p, __len - __declen);
921           __newlen += __len - __declen;
922         }
923       __len = __newlen;
924     }
925
926   // The following code uses snprintf (or sprintf(), when
927   // _GLIBCXX_USE_C99 is not defined) to convert floating point values
928   // for insertion into a stream.  An optimization would be to replace
929   // them with code that works directly on a wide buffer and then use
930   // __pad to do the padding.  It would be good to replace them anyway
931   // to gain back the efficiency that C++ provides by knowing up front
932   // the type of the values to insert.  Also, sprintf is dangerous
933   // since may lead to accidental buffer overruns.  This
934   // implementation follows the C++ standard fairly directly as
935   // outlined in 22.2.2.2 [lib.locale.num.put]
936   template<typename _CharT, typename _OutIter>
937     template<typename _ValueT>
938       _OutIter
939       num_put<_CharT, _OutIter>::
940       _M_insert_float(_OutIter __s, ios_base& __io, _CharT __fill, char __mod,
941                        _ValueT __v) const
942       {
943         typedef typename numpunct<_CharT>::__cache_type __cache_type;
944         __use_cache<__cache_type> __uc;
945         const locale& __loc = __io._M_getloc();
946         const __cache_type* __lc = __uc(__loc);
947
948         // Note: digits10 is rounded down: add 1 to ensure the maximum
949         // available precision.  Then, in general, one more 1 needs to
950         // be added since, when the %{g,G} conversion specifiers are
951         // chosen inside _S_format_float, the precision field is "the
952         // maximum number of significant digits", *not* the "number of
953         // digits to appear after the decimal point", as happens for
954         // %{e,E,f,F} (C99, 7.19.6.1,4).
955         const int __max_digits = numeric_limits<_ValueT>::digits10 + 2;
956
957         // Use default precision if out of range.
958         streamsize __prec = __io.precision();
959         if (__prec > static_cast<streamsize>(__max_digits))
960           __prec = static_cast<streamsize>(__max_digits);
961         else if (__prec < static_cast<streamsize>(0))
962           __prec = static_cast<streamsize>(6);
963
964         // [22.2.2.2.2] Stage 1, numeric conversion to character.
965         int __len;
966         // Long enough for the max format spec.
967         char __fbuf[16];
968
969 #ifdef _GLIBCXX_USE_C99
970         // First try a buffer perhaps big enough (for sure sufficient
971         // for non-ios_base::fixed outputs)
972         int __cs_size = __max_digits * 3;
973         char* __cs = static_cast<char*>(__builtin_alloca(__cs_size));
974
975         _S_format_float(__io, __fbuf, __mod);
976         __len = std::__convert_from_v(__cs, __cs_size, __fbuf, __v,
977                                       _S_get_c_locale(), __prec);
978
979         // If the buffer was not large enough, try again with the correct size.
980         if (__len >= __cs_size)
981           {
982             __cs_size = __len + 1;
983             __cs = static_cast<char*>(__builtin_alloca(__cs_size));
984             __len = std::__convert_from_v(__cs, __cs_size, __fbuf, __v,
985                                           _S_get_c_locale(), __prec);
986           }
987 #else
988         // Consider the possibility of long ios_base::fixed outputs
989         const bool __fixed = __io.flags() & ios_base::fixed;
990         const int __max_exp = numeric_limits<_ValueT>::max_exponent10;
991
992         // The size of the output string is computed as follows.
993         // ios_base::fixed outputs may need up to __max_exp+1 chars
994         // for the integer part + up to __max_digits chars for the
995         // fractional part + 3 chars for sign, decimal point, '\0'. On
996         // the other hand, for non-fixed outputs __max_digits*3 chars
997         // are largely sufficient.
998         const int __cs_size = __fixed ? __max_exp + __max_digits + 4
999                                       : __max_digits * 3;
1000         char* __cs = static_cast<char*>(__builtin_alloca(__cs_size));
1001
1002         _S_format_float(__io, __fbuf, __mod);
1003         __len = std::__convert_from_v(__cs, 0, __fbuf, __v,
1004                                       _S_get_c_locale(), __prec);
1005 #endif
1006
1007       // [22.2.2.2.2] Stage 2, convert to char_type, using correct
1008       // numpunct.decimal_point() values for '.' and adding grouping.
1009       const ctype<_CharT>& __ctype = use_facet<ctype<_CharT> >(__loc);
1010
1011       _CharT* __ws = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT)
1012                                                            * __len));
1013       __ctype.widen(__cs, __cs + __len, __ws);
1014
1015       // Replace decimal point.
1016       const _CharT __cdec = __ctype.widen('.');
1017       const _CharT __dec = __lc->_M_decimal_point;
1018       const _CharT* __p;
1019       if (__p = char_traits<_CharT>::find(__ws, __len, __cdec))
1020         __ws[__p - __ws] = __dec;
1021
1022       // Add grouping, if necessary.
1023       if (__lc->_M_use_grouping)
1024         {
1025           // Grouping can add (almost) as many separators as the
1026           // number of digits, but no more.
1027           _CharT* __ws2 = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT)
1028                                                                 * __len * 2));
1029           _M_group_float(__lc->_M_grouping, __lc->_M_grouping_size,
1030                          __lc->_M_thousands_sep, __p, __ws2, __ws, __len);
1031           __ws = __ws2;
1032         }
1033
1034       // Pad.
1035       const streamsize __w = __io.width();
1036       if (__w > static_cast<streamsize>(__len))
1037         {
1038           _CharT* __ws3 = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT)
1039                                                                 * __w));
1040           _M_pad(__fill, __w, __io, __ws3, __ws, __len);
1041           __ws = __ws3;
1042         }
1043       __io.width(0);
1044
1045       // [22.2.2.2.2] Stage 4.
1046       // Write resulting, fully-formatted string to output iterator.
1047       return std::__write(__s, __ws, __len);
1048       }
1049
1050   template<typename _CharT, typename _OutIter>
1051     _OutIter
1052     num_put<_CharT, _OutIter>::
1053     do_put(iter_type __s, ios_base& __io, char_type __fill, bool __v) const
1054     {
1055       const ios_base::fmtflags __flags = __io.flags();
1056       if ((__flags & ios_base::boolalpha) == 0)
1057         {
1058           unsigned long __uv = __v;
1059           __s = _M_insert_int(__s, __io, __fill, __uv);
1060         }
1061       else
1062         {
1063           typedef typename numpunct<_CharT>::__cache_type __cache_type;
1064           __use_cache<__cache_type> __uc;
1065           const locale& __loc = __io._M_getloc();
1066           const __cache_type* __lc = __uc(__loc);
1067
1068           const _CharT* __name = __v ? __lc->_M_truename
1069                                      : __lc->_M_falsename;
1070           int __len = __v ? __lc->_M_truename_size
1071                           : __lc->_M_falsename_size;
1072
1073           const streamsize __w = __io.width();
1074           if (__w > static_cast<streamsize>(__len))
1075             {
1076               _CharT* __cs
1077                 = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT)
1078                                                         * __w));
1079               _M_pad(__fill, __w, __io, __cs, __name, __len);
1080               __name = __cs;
1081             }
1082           __io.width(0);
1083           __s = std::__write(__s, __name, __len);
1084         }
1085       return __s;
1086     }
1087
1088   template<typename _CharT, typename _OutIter>
1089     _OutIter
1090     num_put<_CharT, _OutIter>::
1091     do_put(iter_type __s, ios_base& __io, char_type __fill, long __v) const
1092     { return _M_insert_int(__s, __io, __fill, __v); }
1093
1094   template<typename _CharT, typename _OutIter>
1095     _OutIter
1096     num_put<_CharT, _OutIter>::
1097     do_put(iter_type __s, ios_base& __io, char_type __fill,
1098            unsigned long __v) const
1099     { return _M_insert_int(__s, __io, __fill, __v); }
1100
1101 #ifdef _GLIBCXX_USE_LONG_LONG
1102   template<typename _CharT, typename _OutIter>
1103     _OutIter
1104     num_put<_CharT, _OutIter>::
1105     do_put(iter_type __s, ios_base& __b, char_type __fill, long long __v) const
1106     { return _M_insert_int(__s, __b, __fill, __v); }
1107
1108   template<typename _CharT, typename _OutIter>
1109     _OutIter
1110     num_put<_CharT, _OutIter>::
1111     do_put(iter_type __s, ios_base& __io, char_type __fill,
1112            unsigned long long __v) const
1113     { return _M_insert_int(__s, __io, __fill, __v); }
1114 #endif
1115
1116   template<typename _CharT, typename _OutIter>
1117     _OutIter
1118     num_put<_CharT, _OutIter>::
1119     do_put(iter_type __s, ios_base& __io, char_type __fill, double __v) const
1120     { return _M_insert_float(__s, __io, __fill, char(), __v); }
1121
1122   template<typename _CharT, typename _OutIter>
1123     _OutIter
1124     num_put<_CharT, _OutIter>::
1125     do_put(iter_type __s, ios_base& __io, char_type __fill,
1126            long double __v) const
1127     { return _M_insert_float(__s, __io, __fill, 'L', __v); }
1128
1129   template<typename _CharT, typename _OutIter>
1130     _OutIter
1131     num_put<_CharT, _OutIter>::
1132     do_put(iter_type __s, ios_base& __io, char_type __fill,
1133            const void* __v) const
1134     {
1135       const ios_base::fmtflags __flags = __io.flags();
1136       const ios_base::fmtflags __fmt = ~(ios_base::showpos
1137                                          | ios_base::basefield
1138                                          | ios_base::uppercase
1139                                          | ios_base::internal);
1140       __io.flags(__flags & __fmt | (ios_base::hex | ios_base::showbase));
1141
1142       __s = _M_insert_int(__s, __io, __fill,
1143                           reinterpret_cast<unsigned long>(__v));
1144       __io.flags(__flags);
1145       return __s;
1146     }
1147
1148   template<typename _CharT, bool _Intl>
1149     struct __use_cache<__moneypunct_cache<_CharT, _Intl> >
1150     {
1151       const __moneypunct_cache<_CharT, _Intl>*
1152       operator() (const locale& __loc) const
1153       {
1154         const size_t __i = moneypunct<_CharT, _Intl>::id._M_id();
1155         const locale::facet** __caches = __loc._M_impl->_M_caches;
1156         if (!__caches[__i])
1157           {
1158             __moneypunct_cache<_CharT, _Intl>* __tmp = NULL;
1159             try
1160               {
1161                 __tmp = new __moneypunct_cache<_CharT, _Intl>;
1162                 __tmp->_M_cache(__loc);
1163               }
1164             catch(...)
1165               {
1166                 delete __tmp;
1167                 __throw_exception_again;
1168               }
1169             __loc._M_impl->_M_install_cache(__tmp, __i);
1170           }
1171         return static_cast<
1172           const __moneypunct_cache<_CharT, _Intl>*>(__caches[__i]);
1173       }
1174     };
1175
1176   template<typename _CharT, typename _InIter>
1177     template<bool _Intl>
1178       _InIter
1179       money_get<_CharT, _InIter>::
1180       _M_extract(iter_type __beg, iter_type __end, ios_base& __io,
1181                  ios_base::iostate& __err, string& __units) const
1182       {
1183         typedef char_traits<_CharT>                       __traits_type;
1184         typedef typename string_type::size_type           size_type;    
1185         typedef money_base::part                          part;
1186         typedef moneypunct<_CharT, _Intl>                 __moneypunct_type;
1187         typedef typename __moneypunct_type::__cache_type  __cache_type;
1188         
1189         const locale& __loc = __io._M_getloc();
1190         const ctype<_CharT>& __ctype = use_facet<ctype<_CharT> >(__loc);
1191
1192         __use_cache<__cache_type> __uc;
1193         const __cache_type* __lc = __uc(__loc);
1194         const char_type* __lit = __lc->_M_atoms;
1195
1196         const money_base::pattern __p = __lc->_M_neg_format;
1197
1198         // Deduced sign.
1199         bool __negative = false;
1200         // True for more than one character long sign.
1201         bool __long_sign = false;
1202         // String of grouping info from thousands_sep plucked from __units.
1203         string __grouping_tmp;
1204         if (__lc->_M_use_grouping)
1205           __grouping_tmp.reserve(32);
1206         // Last position before the decimal point.
1207         int __last_pos = 0;
1208         // Separator positions, then, possibly, fractional digits.
1209         int __n = 0;
1210         // If input iterator is in a valid state.
1211         bool __testvalid = true;
1212         // Flag marking when a decimal point is found.
1213         bool __testdecfound = false;
1214
1215         // The tentative returned string is stored here.
1216         string __res;
1217         __res.reserve(32);
1218
1219         const char_type* __lit_zero = __lit + _S_zero;
1220         const char_type* __q;
1221         for (int __i = 0; __beg != __end && __i < 4 && __testvalid; ++__i)
1222           {
1223             const part __which = static_cast<part>(__p.field[__i]);
1224             switch (__which)
1225               {
1226               case money_base::symbol:
1227                 if (__io.flags() & ios_base::showbase
1228                     || __i < 2 || __long_sign
1229                     || ((static_cast<part>(__p.field[3]) != money_base::none)
1230                         && __i == 2))
1231                   {
1232                     // According to 22.2.6.1.2, p2, symbol is required
1233                     // if (__io.flags() & ios_base::showbase),
1234                     // otherwise is optional and consumed only if
1235                     // other characters are needed to complete the
1236                     // format.
1237                     const size_type __len = __lc->_M_curr_symbol_size;
1238                     size_type __j = 0;
1239                     for (; __beg != __end && __j < __len
1240                            && *__beg == __lc->_M_curr_symbol[__j];
1241                          ++__beg, ++__j);
1242                     // When (__io.flags() & ios_base::showbase)
1243                     // symbol is required.
1244                     if (__j != __len && (__io.flags() & ios_base::showbase))
1245                       __testvalid = false;
1246                   }
1247                 break;
1248               case money_base::sign:
1249                 // Sign might not exist, or be more than one character long.
1250                 if (__lc->_M_positive_sign_size
1251                     && *__beg == __lc->_M_positive_sign[0])
1252                   {
1253                     if (__lc->_M_positive_sign_size > 1)
1254                       __long_sign = true;
1255                     ++__beg;
1256                   }
1257                 else if (__lc->_M_negative_sign_size
1258                          && *__beg == __lc->_M_negative_sign[0])
1259                   {
1260                     __negative = true;
1261                     if (__lc->_M_negative_sign_size > 1)
1262                       __long_sign = true;                   
1263                     ++__beg;
1264                   }
1265                 else if (__lc->_M_positive_sign_size
1266                          && !__lc->_M_negative_sign_size)
1267                   // "... if no sign is detected, the result is given the sign
1268                   // that corresponds to the source of the empty string"
1269                   __negative = true;
1270                 else if (__lc->_M_positive_sign_size
1271                          && __lc->_M_negative_sign_size)
1272                   {
1273                     // Sign is mandatory.
1274                     __testvalid = false;
1275                   }
1276                 break;
1277               case money_base::value:
1278                 // Extract digits, remove and stash away the
1279                 // grouping of found thousands separators.
1280                 for (; __beg != __end; ++__beg)
1281                   if (__q = __traits_type::find(__lit_zero, 10, *__beg))
1282                     {
1283                       __res += _S_atoms[__q - __lit];
1284                       ++__n;
1285                     }
1286                   else if (*__beg == __lc->_M_decimal_point && !__testdecfound)
1287                     {
1288                       __last_pos = __n;
1289                       __n = 0;
1290                       __testdecfound = true;
1291                     }
1292                   else if (__lc->_M_use_grouping
1293                            && *__beg == __lc->_M_thousands_sep
1294                            && !__testdecfound)
1295                     {
1296                       if (__n)
1297                         {
1298                           // Mark position for later analysis.
1299                           __grouping_tmp += static_cast<char>(__n);
1300                           __n = 0;
1301                         }
1302                       else
1303                         {
1304                           __testvalid = false;
1305                           break;
1306                         }
1307                     }
1308                   else
1309                     break;
1310                 break;
1311               case money_base::space:
1312               case money_base::none:
1313                 // Only if not at the end of the pattern.
1314                 if (__i != 3)
1315                   for (; __beg != __end
1316                          && __ctype.is(ctype_base::space, *__beg); ++__beg);
1317                 break;
1318               }
1319           }
1320
1321         // Need to get the rest of the sign characters, if they exist.
1322         if (__long_sign)
1323           {
1324             const char_type* __sign = __negative ? __lc->_M_negative_sign
1325                                                  : __lc->_M_positive_sign;
1326             const size_type __len = __negative ? __lc->_M_negative_sign_size
1327                                                : __lc->_M_positive_sign_size;
1328             size_type __i = 1;
1329             for (; __beg != __end && __i < __len
1330                    && *__beg == __sign[__i]; ++__beg, ++__i);
1331             
1332             if (__i != __len)
1333               __testvalid = false;
1334           }
1335
1336         if (__testvalid && __res.size())
1337           {
1338             // Strip leading zeros.
1339             if (__res.size() > 1)
1340               {
1341                 size_type __first = __res.find_first_not_of(__lit[_S_zero]);
1342                 const bool __only_zeros = __first == string_type::npos;
1343                 if (__first)
1344                   __res.erase(0, __only_zeros ? __res.size() - 1 : __first);
1345               }
1346
1347             // 22.2.6.1.2, p4
1348             if (__negative && __res[0] != __lit[_S_zero])
1349               __res.insert(__res.begin(), __lit[_S_minus]);
1350             
1351             // Test for grouping fidelity.
1352             if (__grouping_tmp.size())
1353               {
1354                 // Add the ending grouping.
1355                 __grouping_tmp += static_cast<char>(__testdecfound ? __last_pos
1356                                                                    : __n);
1357                 if (!std::__verify_grouping(__lc->_M_grouping,
1358                                             __lc->_M_grouping_size,
1359                                             __grouping_tmp))
1360                   __testvalid = false;
1361               }
1362             
1363             // Iff not enough digits were supplied after the decimal-point.
1364             if (__testdecfound && __lc->_M_frac_digits > 0
1365                 && __n != __lc->_M_frac_digits)
1366               __testvalid = false;
1367           }
1368         else
1369           __testvalid = false;
1370         
1371         // Iff no more characters are available.
1372         if (__beg == __end)
1373           __err |= ios_base::eofbit;
1374         
1375         // Iff valid sequence is not recognized.
1376         if (!__testvalid)
1377           __err |= ios_base::failbit;
1378         else
1379           __units.swap(__res);
1380         
1381         return __beg;
1382       }
1383
1384   template<typename _CharT, typename _InIter>
1385     _InIter
1386     money_get<_CharT, _InIter>::
1387     do_get(iter_type __beg, iter_type __end, bool __intl, ios_base& __io,
1388            ios_base::iostate& __err, long double& __units) const
1389     {
1390       string __str;
1391       if (__intl)
1392         __beg = _M_extract<true>(__beg, __end, __io, __err, __str);
1393       else
1394         __beg = _M_extract<false>(__beg, __end, __io, __err, __str);
1395
1396       if (__str.size())
1397         std::__convert_to_v(__str.c_str(), __units, __err, _S_get_c_locale());
1398
1399       return __beg;
1400     }
1401
1402   template<typename _CharT, typename _InIter>
1403     _InIter
1404     money_get<_CharT, _InIter>::
1405     do_get(iter_type __beg, iter_type __end, bool __intl, ios_base& __io,
1406            ios_base::iostate& __err, string_type& __units) const
1407     {
1408       typedef typename string_type::size_type             size_type;
1409
1410       const locale& __loc = __io._M_getloc();
1411       const ctype<_CharT>& __ctype = use_facet<ctype<_CharT> >(__loc);
1412
1413       string __str;
1414       const iter_type __ret = __intl ? _M_extract<true>(__beg, __end, __io,
1415                                                         __err, __str)
1416                                      : _M_extract<false>(__beg, __end, __io,
1417                                                          __err, __str);
1418       const size_type __len = __str.size();
1419       if (__len)
1420         {
1421           _CharT* __ws = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT)
1422                                                                * __len));
1423           __ctype.widen(__str.data(), __str.data() + __len, __ws);
1424           __units.assign(__ws, __len);
1425         }
1426
1427       return __ret;
1428     }
1429
1430   template<typename _CharT, typename _OutIter>
1431     template<bool _Intl>
1432       _OutIter
1433       money_put<_CharT, _OutIter>::
1434       _M_insert(iter_type __s, ios_base& __io, char_type __fill,
1435                 const string_type& __digits) const
1436       {
1437         typedef typename string_type::size_type           size_type;
1438         typedef money_base::part                          part;
1439         typedef moneypunct<_CharT, _Intl>                 __moneypunct_type;
1440         typedef typename __moneypunct_type::__cache_type  __cache_type;
1441       
1442         const locale& __loc = __io._M_getloc();
1443         const ctype<_CharT>& __ctype = use_facet<ctype<_CharT> >(__loc);
1444
1445         __use_cache<__cache_type> __uc;
1446         const __cache_type* __lc = __uc(__loc);
1447         const char_type* __lit = __lc->_M_atoms;
1448
1449         // Determine if negative or positive formats are to be used, and
1450         // discard leading negative_sign if it is present.
1451         const char_type* __beg = __digits.data();
1452         const char_type* __end = __beg + __digits.size();
1453
1454         money_base::pattern __p;
1455         const char_type* __sign;
1456         size_type __sign_size;
1457         if (*__beg != __lit[_S_minus])
1458           {
1459             __p = __lc->_M_pos_format;
1460             __sign = __lc->_M_positive_sign;
1461             __sign_size = __lc->_M_positive_sign_size;
1462           }
1463         else
1464           {
1465             __p = __lc->_M_neg_format;
1466             __sign = __lc->_M_negative_sign;
1467             __sign_size = __lc->_M_negative_sign_size;
1468             ++__beg;
1469           }
1470        
1471         // Look for valid numbers in the ctype facet within input digits.
1472         __end = __ctype.scan_not(ctype_base::digit, __beg, __end);
1473         if (__beg != __end)
1474           {
1475             // Assume valid input, and attempt to format.
1476             // Break down input numbers into base components, as follows:
1477             //   final_value = grouped units + (decimal point) + (digits)
1478             string_type __value;
1479             size_type __len = __end - __beg;
1480             __value.reserve(2 * __len);
1481
1482             // Add thousands separators to non-decimal digits, per
1483             // grouping rules.
1484             const int __paddec = __lc->_M_frac_digits - __len;      
1485             if (__paddec < 0)
1486               {
1487                 if (__lc->_M_grouping_size)
1488                   {
1489                     _CharT* __ws =
1490                       static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT)
1491                                                             * 2 * __len));
1492                     _CharT* __ws_end =
1493                       std::__add_grouping(__ws, __lc->_M_thousands_sep,
1494                                           __lc->_M_grouping,
1495                                           __lc->_M_grouping_size,
1496                                           __beg, __end - __lc->_M_frac_digits);
1497                     __value.assign(__ws, __ws_end - __ws);
1498                   }
1499                 else
1500                   __value.assign(__beg, -__paddec);
1501               }
1502
1503             // Deal with decimal point, decimal digits.
1504             if (__lc->_M_frac_digits > 0)
1505               {
1506                 __value += __lc->_M_decimal_point;
1507                 if (__paddec <= 0)
1508                   __value.append(__end - __lc->_M_frac_digits,
1509                                  __lc->_M_frac_digits);
1510                 else
1511                   {
1512                     // Have to pad zeros in the decimal position.
1513                     __value.append(__paddec, __lit[_S_zero]);
1514                     __value.append(__beg, __len);
1515                   }
1516               }
1517   
1518             // Calculate length of resulting string.
1519             const ios_base::fmtflags __f = __io.flags() & ios_base::adjustfield;
1520             __len = __value.size() + __sign_size;
1521             __len += ((__io.flags() & ios_base::showbase)
1522                       ? __lc->_M_curr_symbol_size : 0);
1523
1524             string_type __res;
1525             __res.reserve(2 * __len);
1526             
1527             const size_type __width = static_cast<size_type>(__io.width());       
1528             const bool __testipad = (__f == ios_base::internal
1529                                      && __len < __width);
1530             // Fit formatted digits into the required pattern.
1531             for (int __i = 0; __i < 4; ++__i)
1532               {
1533                 const part __which = static_cast<part>(__p.field[__i]);
1534                 switch (__which)
1535                   {
1536                   case money_base::symbol:
1537                     if (__io.flags() & ios_base::showbase)
1538                       __res.append(__lc->_M_curr_symbol,
1539                                    __lc->_M_curr_symbol_size);
1540                     break;
1541                   case money_base::sign:
1542                     // Sign might not exist, or be more than one
1543                     // charater long. In that case, add in the rest
1544                     // below.
1545                     if (__sign_size)
1546                       __res += __sign[0];
1547                     break;
1548                   case money_base::value:
1549                     __res += __value;
1550                     break;
1551                   case money_base::space:
1552                     // At least one space is required, but if internal
1553                     // formatting is required, an arbitrary number of
1554                     // fill spaces will be necessary.
1555                     if (__testipad)
1556                       __res.append(__width - __len, __fill);
1557                     else
1558                       __res += __fill;
1559                     break;
1560                   case money_base::none:
1561                     if (__testipad)
1562                       __res.append(__width - __len, __fill);
1563                     break;
1564                   }
1565               }
1566             
1567             // Special case of multi-part sign parts.
1568             if (__sign_size > 1)
1569               __res.append(__sign + 1, __sign_size - 1);
1570             
1571             // Pad, if still necessary.
1572             __len = __res.size();
1573             if (__width > __len)
1574               {
1575                 if (__f == ios_base::left)
1576                   // After.
1577                   __res.append(__width - __len, __fill);
1578                 else
1579                   // Before.
1580                   __res.insert(0, __width - __len, __fill);
1581                 __len = __width;
1582               }
1583             
1584             // Write resulting, fully-formatted string to output iterator.
1585             __s = std::__write(__s, __res.data(), __len);
1586           }
1587         __io.width(0);
1588         return __s;    
1589       }
1590   
1591   template<typename _CharT, typename _OutIter>
1592     _OutIter
1593     money_put<_CharT, _OutIter>::
1594     do_put(iter_type __s, bool __intl, ios_base& __io, char_type __fill,
1595            long double __units) const
1596     {
1597       const locale __loc = __io.getloc();
1598       const ctype<_CharT>& __ctype = use_facet<ctype<_CharT> >(__loc);
1599 #ifdef _GLIBCXX_USE_C99
1600       // First try a buffer perhaps big enough.
1601       int __cs_size = 64;
1602       char* __cs = static_cast<char*>(__builtin_alloca(__cs_size));
1603       // _GLIBCXX_RESOLVE_LIB_DEFECTS
1604       // 328. Bad sprintf format modifier in money_put<>::do_put()
1605       int __len = std::__convert_from_v(__cs, __cs_size, "%.0Lf", __units,
1606                                         _S_get_c_locale());
1607       // If the buffer was not large enough, try again with the correct size.
1608       if (__len >= __cs_size)
1609         {
1610           __cs_size = __len + 1;
1611           __cs = static_cast<char*>(__builtin_alloca(__cs_size));
1612           __len = std::__convert_from_v(__cs, __cs_size, "%.0Lf", __units,
1613                                         _S_get_c_locale());
1614         }
1615 #else
1616       // max_exponent10 + 1 for the integer part, + 2 for sign and '\0'.
1617       const int __cs_size = numeric_limits<long double>::max_exponent10 + 3;
1618       char* __cs = static_cast<char*>(__builtin_alloca(__cs_size));
1619       int __len = std::__convert_from_v(__cs, 0, "%.0Lf", __units,
1620                                         _S_get_c_locale());
1621 #endif
1622       _CharT* __ws = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT)
1623                                                            * __cs_size));
1624       __ctype.widen(__cs, __cs + __len, __ws);
1625       const string_type __digits(__ws, __len);
1626       return __intl ? _M_insert<true>(__s, __io, __fill, __digits)
1627                     : _M_insert<false>(__s, __io, __fill, __digits);
1628     }
1629
1630   template<typename _CharT, typename _OutIter>
1631     _OutIter
1632     money_put<_CharT, _OutIter>::
1633     do_put(iter_type __s, bool __intl, ios_base& __io, char_type __fill,
1634            const string_type& __digits) const
1635     { return __intl ? _M_insert<true>(__s, __io, __fill, __digits)
1636                     : _M_insert<false>(__s, __io, __fill, __digits); }
1637
1638   // NB: Not especially useful. Without an ios_base object or some
1639   // kind of locale reference, we are left clawing at the air where
1640   // the side of the mountain used to be...
1641   template<typename _CharT, typename _InIter>
1642     time_base::dateorder
1643     time_get<_CharT, _InIter>::do_date_order() const
1644     { return time_base::no_order; }
1645
1646   // Recursively expand a strftime format string and parse it.  Starts w/ %x
1647   // and %X from do_get_time() and do_get_date(), which translate to a more
1648   // specific string, which may contain yet more strings.  I.e. %x => %r =>
1649   // %H:%M:%S => extracted characters.
1650   template<typename _CharT, typename _InIter>
1651     void
1652     time_get<_CharT, _InIter>::
1653     _M_extract_via_format(iter_type& __beg, iter_type& __end, ios_base& __io,
1654                           ios_base::iostate& __err, tm* __tm,
1655                           const _CharT* __format) const
1656     {
1657       const locale __loc = __io.getloc();
1658       const __timepunct<_CharT>& __tp = use_facet<__timepunct<_CharT> >(__loc);
1659       const ctype<_CharT>& __ctype = use_facet<ctype<_CharT> >(__loc);
1660       const size_t __len = char_traits<_CharT>::length(__format);
1661
1662       for (size_t __i = 0; __beg != __end && __i < __len && !__err; ++__i)
1663         {
1664           if (__ctype.narrow(__format[__i], 0) == '%')
1665             {
1666               // Verify valid formatting code, attempt to extract.
1667               char __c = __ctype.narrow(__format[++__i], 0);
1668               int __mem = 0;
1669               if (__c == 'E' || __c == 'O')
1670                 __c = __ctype.narrow(__format[++__i], 0);
1671               switch (__c)
1672                 {
1673                   const char* __cs;
1674                   _CharT __wcs[10];
1675                 case 'a':
1676                   // Abbreviated weekday name [tm_wday]
1677                   const char_type*  __days1[7];
1678                   __tp._M_days_abbreviated(__days1);
1679                   _M_extract_name(__beg, __end, __tm->tm_wday, __days1, 7,
1680                                   __ctype, __err);
1681                   break;
1682                 case 'A':
1683                   // Weekday name [tm_wday].
1684                   const char_type*  __days2[7];
1685                   __tp._M_days(__days2);
1686                   _M_extract_name(__beg, __end, __tm->tm_wday, __days2, 7,
1687                                   __ctype, __err);
1688                   break;
1689                 case 'h':
1690                 case 'b':
1691                   // Abbreviated month name [tm_mon]
1692                   const char_type*  __months1[12];
1693                   __tp._M_months_abbreviated(__months1);
1694                   _M_extract_name(__beg, __end, __tm->tm_mon, __months1, 12,
1695                                   __ctype, __err);
1696                   break;
1697                 case 'B':
1698                   // Month name [tm_mon].
1699                   const char_type*  __months2[12];
1700                   __tp._M_months(__months2);
1701                   _M_extract_name(__beg, __end, __tm->tm_mon, __months2, 12,
1702                                   __ctype, __err);
1703                   break;
1704                 case 'c':
1705                   // Default time and date representation.
1706                   const char_type*  __dt[2];
1707                   __tp._M_date_time_formats(__dt);
1708                   _M_extract_via_format(__beg, __end, __io, __err, __tm,
1709                                         __dt[0]);
1710                   break;
1711                 case 'd':
1712                   // Day [01, 31]. [tm_mday]
1713                   _M_extract_num(__beg, __end, __tm->tm_mday, 1, 31, 2,
1714                                  __ctype, __err);
1715                   break;
1716                 case 'e':
1717                   // Day [1, 31], with single digits preceded by
1718                   // space. [tm_mday]
1719                   if (__ctype.is(ctype_base::space, *__beg))
1720                     _M_extract_num(++__beg, __end, __tm->tm_mday, 1, 9, 1,
1721                                    __ctype, __err);
1722                   else
1723                     _M_extract_num(__beg, __end, __tm->tm_mday, 10, 31, 2,
1724                                    __ctype, __err);
1725                   break;
1726                 case 'D':
1727                   // Equivalent to %m/%d/%y.[tm_mon, tm_mday, tm_year]
1728                   __cs = "%m/%d/%y";
1729                   __ctype.widen(__cs, __cs + 9, __wcs);
1730                   _M_extract_via_format(__beg, __end, __io, __err, __tm,
1731                                         __wcs);
1732                   break;
1733                 case 'H':
1734                   // Hour [00, 23]. [tm_hour]
1735                   _M_extract_num(__beg, __end, __tm->tm_hour, 0, 23, 2,
1736                                  __ctype, __err);
1737                   break;
1738                 case 'I':
1739                   // Hour [01, 12]. [tm_hour]
1740                   _M_extract_num(__beg, __end, __tm->tm_hour, 1, 12, 2,
1741                                  __ctype, __err);
1742                   break;
1743                 case 'm':
1744                   // Month [01, 12]. [tm_mon]
1745                   _M_extract_num(__beg, __end, __mem, 1, 12, 2, __ctype,
1746                                  __err);
1747                   if (!__err)
1748                     __tm->tm_mon = __mem - 1;
1749                   break;
1750                 case 'M':
1751                   // Minute [00, 59]. [tm_min]
1752                   _M_extract_num(__beg, __end, __tm->tm_min, 0, 59, 2,
1753                                  __ctype, __err);
1754                   break;
1755                 case 'n':
1756                   if (__ctype.narrow(*__beg, 0) == '\n')
1757                     ++__beg;
1758                   else
1759                     __err |= ios_base::failbit;
1760                   break;
1761                 case 'R':
1762                   // Equivalent to (%H:%M).
1763                   __cs = "%H:%M";
1764                   __ctype.widen(__cs, __cs + 6, __wcs);
1765                   _M_extract_via_format(__beg, __end, __io, __err, __tm,
1766                                         __wcs);
1767                   break;
1768                 case 'S':
1769                   // Seconds.
1770                   _M_extract_num(__beg, __end, __tm->tm_sec, 0, 59, 2,
1771                                  __ctype, __err);
1772                   break;
1773                 case 't':
1774                   if (__ctype.narrow(*__beg, 0) == '\t')
1775                     ++__beg;
1776                   else
1777                     __err |= ios_base::failbit;
1778                   break;
1779                 case 'T':
1780                   // Equivalent to (%H:%M:%S).
1781                   __cs = "%H:%M:%S";
1782                   __ctype.widen(__cs, __cs + 9, __wcs);
1783                   _M_extract_via_format(__beg, __end, __io, __err, __tm,
1784                                         __wcs);
1785                   break;
1786                 case 'x':
1787                   // Locale's date.
1788                   const char_type*  __dates[2];
1789                   __tp._M_date_formats(__dates);
1790                   _M_extract_via_format(__beg, __end, __io, __err, __tm,
1791                                         __dates[0]);
1792                   break;
1793                 case 'X':
1794                   // Locale's time.
1795                   const char_type*  __times[2];
1796                   __tp._M_time_formats(__times);
1797                   _M_extract_via_format(__beg, __end, __io, __err, __tm,
1798                                         __times[0]);
1799                   break;
1800                 case 'y':
1801                 case 'C': // C99
1802                   // Two digit year. [tm_year]
1803                   _M_extract_num(__beg, __end, __tm->tm_year, 0, 99, 2,
1804                                  __ctype, __err);
1805                   break;
1806                 case 'Y':
1807                   // Year [1900). [tm_year]
1808                   _M_extract_num(__beg, __end, __mem, 0, 9999, 4,
1809                                  __ctype, __err);
1810                   if (!__err)
1811                     __tm->tm_year = __mem - 1900;
1812                   break;
1813                 case 'Z':
1814                   // Timezone info.
1815                   if (__ctype.is(ctype_base::upper, *__beg))
1816                     {
1817                       int __tmp;
1818                       _M_extract_name(__beg, __end, __tmp,
1819                                       __timepunct_cache<_CharT>::_S_timezones,
1820                                       14, __ctype, __err);
1821
1822                       // GMT requires special effort.
1823                       if (__beg != __end && !__err && __tmp == 0
1824                           && (*__beg == __ctype.widen('-')
1825                               || *__beg == __ctype.widen('+')))
1826                         {
1827                           _M_extract_num(__beg, __end, __tmp, 0, 23, 2,
1828                                           __ctype, __err);
1829                           _M_extract_num(__beg, __end, __tmp, 0, 59, 2,
1830                                           __ctype, __err);
1831                         }
1832                     }
1833                   else
1834                     __err |= ios_base::failbit;
1835                   break;
1836                 default:
1837                   // Not recognized.
1838                   __err |= ios_base::failbit;
1839                 }
1840             }
1841           else
1842             {
1843               // Verify format and input match, extract and discard.
1844               if (__format[__i] == *__beg)
1845                 ++__beg;
1846               else
1847                 __err |= ios_base::failbit;
1848             }
1849         }
1850     }
1851
1852   template<typename _CharT, typename _InIter>
1853     void
1854     time_get<_CharT, _InIter>::
1855     _M_extract_num(iter_type& __beg, iter_type& __end, int& __member,
1856                    int __min, int __max, size_t __len,
1857                    const ctype<_CharT>& __ctype,
1858                    ios_base::iostate& __err) const
1859     {
1860       // As-is works for __len = 1, 2, 4, the values actually used.
1861       int __mult = __len == 2 ? 10 : (__len == 4 ? 1000 : 1);
1862
1863       ++__min;
1864       size_t __i = 0;
1865       int __value = 0;
1866       for (; __beg != __end && __i < __len; ++__beg, ++__i)
1867         {
1868           const char __c = __ctype.narrow(*__beg, '*');
1869           if (__c >= '0' && __c <= '9')
1870             {
1871               __value = __value * 10 + (__c - '0');
1872               const int __valuec = __value * __mult;
1873               if (__valuec > __max || __valuec + __mult < __min)
1874                 break;
1875               __mult /= 10;
1876             }
1877           else
1878             break;
1879         }
1880       if (__i == __len)
1881         __member = __value;
1882       else
1883         __err |= ios_base::failbit;
1884     }
1885
1886   // Assumptions:
1887   // All elements in __names are unique.
1888   template<typename _CharT, typename _InIter>
1889     void
1890     time_get<_CharT, _InIter>::
1891     _M_extract_name(iter_type& __beg, iter_type& __end, int& __member,
1892                     const _CharT** __names, size_t __indexlen,
1893                     const ctype<_CharT>& __ctype,
1894                     ios_base::iostate& __err) const
1895     {
1896       typedef char_traits<_CharT>               __traits_type;
1897       int* __matches = static_cast<int*>(__builtin_alloca(sizeof(int)
1898                                                           * __indexlen));
1899       size_t __nmatches = 0;
1900       size_t __pos = 0;
1901       bool __testvalid = true;
1902       const char_type* __name;
1903
1904       // Look for initial matches.
1905       // NB: Some of the locale data is in the form of all lowercase
1906       // names, and some is in the form of initially-capitalized
1907       // names. Look for both.
1908       if (__beg != __end)
1909         {
1910           const char_type __c = *__beg;
1911           for (size_t __i1 = 0; __i1 < __indexlen; ++__i1)
1912             if (__c == __names[__i1][0]
1913                 || __c == __ctype.toupper(__names[__i1][0]))
1914               __matches[__nmatches++] = __i1;
1915         }
1916
1917       while (__nmatches > 1)
1918         {
1919           // Find smallest matching string.
1920           size_t __minlen = 10;
1921           for (size_t __i2 = 0; __i2 < __nmatches; ++__i2)
1922             __minlen = std::min(__minlen,
1923                                 __traits_type::length(__names[__matches[__i2]]));
1924           ++__beg;
1925           if (__pos < __minlen && __beg != __end)
1926             {
1927               ++__pos;
1928               for (size_t __i3 = 0; __i3 < __nmatches; ++__i3)
1929                 {
1930                   __name = __names[__matches[__i3]];
1931                   if (__name[__pos] != *__beg)
1932                     __matches[__i3] = __matches[--__nmatches];
1933                 }
1934             }
1935           else
1936             break;
1937         }
1938
1939       if (__nmatches == 1)
1940         {
1941           // If there was only one match, the first compare is redundant.
1942           if (__pos == 0)
1943             {
1944               ++__pos;
1945               ++__beg;
1946             }
1947
1948           // Make sure found name is completely extracted.
1949           __name = __names[__matches[0]];
1950           const size_t __len = __traits_type::length(__name);
1951           while (__pos < __len && __beg != __end && __name[__pos] == *__beg)
1952             ++__beg, ++__pos;
1953
1954           if (__len == __pos)
1955             __member = __matches[0];
1956           else
1957             __testvalid = false;
1958         }
1959       else
1960         __testvalid = false;
1961       if (!__testvalid)
1962         __err |= ios_base::failbit;
1963     }
1964
1965   template<typename _CharT, typename _InIter>
1966     _InIter
1967     time_get<_CharT, _InIter>::
1968     do_get_time(iter_type __beg, iter_type __end, ios_base& __io,
1969                 ios_base::iostate& __err, tm* __tm) const
1970     {
1971       _CharT __wcs[3];
1972       const char* __cs = "%X";
1973       const locale __loc = __io.getloc();
1974       ctype<_CharT> const& __ctype = use_facet<ctype<_CharT> >(__loc);
1975       __ctype.widen(__cs, __cs + 3, __wcs);
1976       _M_extract_via_format(__beg, __end, __io, __err, __tm, __wcs);
1977       if (__beg == __end)
1978         __err |= ios_base::eofbit;
1979       return __beg;
1980     }
1981
1982   template<typename _CharT, typename _InIter>
1983     _InIter
1984     time_get<_CharT, _InIter>::
1985     do_get_date(iter_type __beg, iter_type __end, ios_base& __io,
1986                 ios_base::iostate& __err, tm* __tm) const
1987     {
1988       _CharT __wcs[3];
1989       const char* __cs = "%x";
1990       const locale __loc = __io.getloc();
1991       ctype<_CharT> const& __ctype = use_facet<ctype<_CharT> >(__loc);
1992       __ctype.widen(__cs, __cs + 3, __wcs);
1993       _M_extract_via_format(__beg, __end, __io, __err, __tm, __wcs);
1994       if (__beg == __end)
1995         __err |= ios_base::eofbit;
1996       return __beg;
1997     }
1998
1999   template<typename _CharT, typename _InIter>
2000     _InIter
2001     time_get<_CharT, _InIter>::
2002     do_get_weekday(iter_type __beg, iter_type __end, ios_base& __io,
2003                    ios_base::iostate& __err, tm* __tm) const
2004     {
2005       typedef char_traits<_CharT>               __traits_type;
2006       const locale __loc = __io.getloc();
2007       const __timepunct<_CharT>& __tp = use_facet<__timepunct<_CharT> >(__loc);
2008       const ctype<_CharT>& __ctype = use_facet<ctype<_CharT> >(__loc);
2009       const char_type*  __days[7];
2010       __tp._M_days_abbreviated(__days);
2011       int __tmpwday;
2012       _M_extract_name(__beg, __end, __tmpwday, __days, 7, __ctype, __err);
2013
2014       // Check to see if non-abbreviated name exists, and extract.
2015       // NB: Assumes both _M_days and _M_days_abbreviated organized in
2016       // exact same order, first to last, such that the resulting
2017       // __days array with the same index points to a day, and that
2018       // day's abbreviated form.
2019       // NB: Also assumes that an abbreviated name is a subset of the name.
2020       if (!__err)
2021         {
2022           size_t __pos = __traits_type::length(__days[__tmpwday]);
2023           __tp._M_days(__days);
2024           const char_type* __name = __days[__tmpwday];
2025           if (__name[__pos] == *__beg)
2026             {
2027               // Extract the rest of it.
2028               const size_t __len = __traits_type::length(__name);
2029               while (__pos < __len && __beg != __end
2030                      && __name[__pos] == *__beg)
2031                 ++__beg, ++__pos;
2032               if (__len != __pos)
2033                 __err |= ios_base::failbit;
2034             }
2035           if (!__err)
2036             __tm->tm_wday = __tmpwday;
2037         }
2038       if (__beg == __end)
2039         __err |= ios_base::eofbit;
2040       return __beg;
2041      }
2042
2043   template<typename _CharT, typename _InIter>
2044     _InIter
2045     time_get<_CharT, _InIter>::
2046     do_get_monthname(iter_type __beg, iter_type __end,
2047                      ios_base& __io, ios_base::iostate& __err, tm* __tm) const
2048     {
2049       typedef char_traits<_CharT>               __traits_type;
2050       const locale __loc = __io.getloc();
2051       const __timepunct<_CharT>& __tp = use_facet<__timepunct<_CharT> >(__loc);
2052       const ctype<_CharT>& __ctype = use_facet<ctype<_CharT> >(__loc);
2053       const char_type*  __months[12];
2054       __tp._M_months_abbreviated(__months);
2055       int __tmpmon;
2056       _M_extract_name(__beg, __end, __tmpmon, __months, 12, __ctype, __err);
2057
2058       // Check to see if non-abbreviated name exists, and extract.
2059       // NB: Assumes both _M_months and _M_months_abbreviated organized in
2060       // exact same order, first to last, such that the resulting
2061       // __months array with the same index points to a month, and that
2062       // month's abbreviated form.
2063       // NB: Also assumes that an abbreviated name is a subset of the name.
2064       if (!__err)
2065         {
2066           size_t __pos = __traits_type::length(__months[__tmpmon]);
2067           __tp._M_months(__months);
2068           const char_type* __name = __months[__tmpmon];
2069           if (__name[__pos] == *__beg)
2070             {
2071               // Extract the rest of it.
2072               const size_t __len = __traits_type::length(__name);
2073               while (__pos < __len && __beg != __end
2074                      && __name[__pos] == *__beg)
2075                 ++__beg, ++__pos;
2076               if (__len != __pos)
2077                 __err |= ios_base::failbit;
2078             }
2079           if (!__err)
2080             __tm->tm_mon = __tmpmon;
2081         }
2082
2083       if (__beg == __end)
2084         __err |= ios_base::eofbit;
2085       return __beg;
2086     }
2087
2088   template<typename _CharT, typename _InIter>
2089     _InIter
2090     time_get<_CharT, _InIter>::
2091     do_get_year(iter_type __beg, iter_type __end, ios_base& __io,
2092                 ios_base::iostate& __err, tm* __tm) const
2093     {
2094       const locale __loc = __io.getloc();
2095       const ctype<_CharT>& __ctype = use_facet<ctype<_CharT> >(__loc);
2096
2097       size_t __i = 0;
2098       int __value = 0;
2099       for (; __beg != __end && __i < 4; ++__beg, ++__i)
2100         {
2101           const char __c = __ctype.narrow(*__beg, '*');
2102           if (__c >= '0' && __c <= '9')
2103             __value = __value * 10 + (__c - '0');
2104           else
2105             break;
2106         }
2107       if (__i == 2 || __i == 4)
2108         __tm->tm_year = __i == 2 ? __value : __value - 1900;
2109       else
2110         __err |= ios_base::failbit;
2111       if (__beg == __end)
2112         __err |= ios_base::eofbit;
2113       return __beg;
2114     }
2115
2116   template<typename _CharT, typename _OutIter>
2117     _OutIter
2118     time_put<_CharT, _OutIter>::
2119     put(iter_type __s, ios_base& __io, char_type __fill, const tm* __tm,
2120         const _CharT* __beg, const _CharT* __end) const
2121     {
2122       const locale __loc = __io.getloc();
2123       ctype<_CharT> const& __ctype = use_facet<ctype<_CharT> >(__loc);
2124       for (; __beg != __end; ++__beg)
2125         if (__ctype.narrow(*__beg, 0) != '%')
2126           {
2127             *__s = *__beg;
2128             ++__s;
2129           }
2130         else if (++__beg != __end)
2131           {
2132             char __format;
2133             char __mod = 0;
2134             const char __c = __ctype.narrow(*__beg, 0);
2135             if (__c != 'E' && __c != 'O')
2136               __format = __c;
2137             else if (++__beg != __end)
2138               {
2139                 __mod = __c;
2140                 __format = __ctype.narrow(*__beg, 0);
2141               }
2142             else
2143               break;
2144             __s = this->do_put(__s, __io, __fill, __tm,
2145                                __format, __mod);
2146           }
2147         else
2148           break;
2149       return __s;
2150     }
2151
2152   template<typename _CharT, typename _OutIter>
2153     _OutIter
2154     time_put<_CharT, _OutIter>::
2155     do_put(iter_type __s, ios_base& __io, char_type, const tm* __tm,
2156            char __format, char __mod) const
2157     {
2158       const locale __loc = __io.getloc();
2159       ctype<_CharT> const& __ctype = use_facet<ctype<_CharT> >(__loc);
2160       __timepunct<_CharT> const& __tp = use_facet<__timepunct<_CharT> >(__loc);
2161
2162       // NB: This size is arbitrary. Should this be a data member,
2163       // initialized at construction?
2164       const size_t __maxlen = 64;
2165       char_type* __res =
2166         static_cast<char_type*>(__builtin_alloca(sizeof(char_type)
2167                                                  * __maxlen));
2168
2169       // NB: In IEE 1003.1-200x, and perhaps other locale models, it
2170       // is possible that the format character will be longer than one
2171       // character. Possibilities include 'E' or 'O' followed by a
2172       // format character: if __mod is not the default argument, assume
2173       // it's a valid modifier.
2174       char_type __fmt[4];
2175       __fmt[0] = __ctype.widen('%');
2176       if (!__mod)
2177         {
2178           __fmt[1] = __format;
2179           __fmt[2] = char_type();
2180         }
2181       else
2182         {
2183           __fmt[1] = __mod;
2184           __fmt[2] = __format;
2185           __fmt[3] = char_type();
2186         }
2187
2188       __tp._M_put(__res, __maxlen, __fmt, __tm);
2189
2190       // Write resulting, fully-formatted string to output iterator.
2191       return std::__write(__s, __res, char_traits<char_type>::length(__res));
2192     }
2193
2194
2195   // Generic version does nothing.
2196   template<typename _CharT>
2197     int
2198     collate<_CharT>::_M_compare(const _CharT*, const _CharT*) const
2199     { return 0; }
2200
2201   // Generic version does nothing.
2202   template<typename _CharT>
2203     size_t
2204     collate<_CharT>::_M_transform(_CharT*, const _CharT*, size_t) const
2205     { return 0; }
2206
2207   template<typename _CharT>
2208     int
2209     collate<_CharT>::
2210     do_compare(const _CharT* __lo1, const _CharT* __hi1,
2211                const _CharT* __lo2, const _CharT* __hi2) const
2212     {
2213       // strcoll assumes zero-terminated strings so we make a copy
2214       // and then put a zero at the end.
2215       const string_type __one(__lo1, __hi1);
2216       const string_type __two(__lo2, __hi2);
2217
2218       const _CharT* __p = __one.c_str();
2219       const _CharT* __pend = __one.data() + __one.length();
2220       const _CharT* __q = __two.c_str();
2221       const _CharT* __qend = __two.data() + __two.length();
2222
2223       // strcoll stops when it sees a nul character so we break
2224       // the strings into zero-terminated substrings and pass those
2225       // to strcoll.
2226       for (;;)
2227         {
2228           const int __res = _M_compare(__p, __q);
2229           if (__res)
2230             return __res;
2231
2232           __p += char_traits<_CharT>::length(__p);
2233           __q += char_traits<_CharT>::length(__q);
2234           if (__p == __pend && __q == __qend)
2235             return 0;
2236           else if (__p == __pend)
2237             return -1;
2238           else if (__q == __qend)
2239             return 1;
2240
2241           __p++;
2242           __q++;
2243         }
2244     }
2245
2246   template<typename _CharT>
2247     typename collate<_CharT>::string_type
2248     collate<_CharT>::
2249     do_transform(const _CharT* __lo, const _CharT* __hi) const
2250     {
2251       // strxfrm assumes zero-terminated strings so we make a copy
2252       string_type __str(__lo, __hi);
2253
2254       const _CharT* __p = __str.c_str();
2255       const _CharT* __pend = __str.data() + __str.length();
2256
2257       size_t __len = (__hi - __lo) * 2;
2258
2259       string_type __ret;
2260
2261       // strxfrm stops when it sees a nul character so we break
2262       // the string into zero-terminated substrings and pass those
2263       // to strxfrm.
2264       for (;;)
2265         {
2266           // First try a buffer perhaps big enough.
2267           _CharT* __c =
2268             static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) * __len));
2269           size_t __res = _M_transform(__c, __p, __len);
2270           // If the buffer was not large enough, try again with the
2271           // correct size.
2272           if (__res >= __len)
2273             {
2274               __len = __res + 1;
2275               __c = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT)
2276                                                           * __len));
2277               __res = _M_transform(__c, __p, __res + 1);
2278             }
2279
2280           __ret.append(__c, __res);
2281           __p += char_traits<_CharT>::length(__p);
2282           if (__p == __pend)
2283             return __ret;
2284
2285           __p++;
2286           __ret.push_back(_CharT());
2287         }
2288     }
2289
2290   template<typename _CharT>
2291     long
2292     collate<_CharT>::
2293     do_hash(const _CharT* __lo, const _CharT* __hi) const
2294     {
2295       unsigned long __val = 0;
2296       for (; __lo < __hi; ++__lo)
2297         __val = *__lo + ((__val << 7) |
2298                        (__val >> (numeric_limits<unsigned long>::digits - 7)));
2299       return static_cast<long>(__val);
2300     }
2301
2302   // Construct correctly padded string, as per 22.2.2.2.2
2303   // Assumes
2304   // __newlen > __oldlen
2305   // __news is allocated for __newlen size
2306   // Used by both num_put and ostream inserters: if __num,
2307   // internal-adjusted objects are padded according to the rules below
2308   // concerning 0[xX] and +-, otherwise, exactly as right-adjusted
2309   // ones are.
2310
2311   // NB: Of the two parameters, _CharT can be deduced from the
2312   // function arguments. The other (_Traits) has to be explicitly specified.
2313   template<typename _CharT, typename _Traits>
2314     void
2315     __pad<_CharT, _Traits>::_S_pad(ios_base& __io, _CharT __fill,
2316                                    _CharT* __news, const _CharT* __olds,
2317                                    const streamsize __newlen,
2318                                    const streamsize __oldlen, const bool __num)
2319     {
2320       const size_t __plen = static_cast<size_t>(__newlen - __oldlen);
2321       const ios_base::fmtflags __adjust = __io.flags() & ios_base::adjustfield;
2322
2323       // Padding last.
2324       if (__adjust == ios_base::left)
2325         {
2326           _Traits::copy(__news, const_cast<_CharT*>(__olds), __oldlen);
2327           _Traits::assign(__news + __oldlen, __plen, __fill);
2328           return;
2329         }
2330
2331       size_t __mod = 0;
2332       if (__adjust == ios_base::internal && __num)
2333         {
2334           // Pad after the sign, if there is one.
2335           // Pad after 0[xX], if there is one.
2336           // Who came up with these rules, anyway? Jeeze.
2337           const locale& __loc = __io._M_getloc();
2338           const ctype<_CharT>& __ctype = use_facet<ctype<_CharT> >(__loc);
2339
2340           const bool __testsign = _Traits::eq(__ctype.widen('-'), __olds[0])
2341                                   || _Traits::eq(__ctype.widen('+'), __olds[0]);
2342           const bool __testhex = (_Traits::eq(__ctype.widen('0'), __olds[0])
2343                                   && __oldlen > 1
2344                                   && (_Traits::eq(__ctype.widen('x'), __olds[1])
2345                                       || _Traits::eq(__ctype.widen('X'),
2346                                                      __olds[1])));
2347           if (__testhex)
2348             {
2349               __news[0] = __olds[0];
2350               __news[1] = __olds[1];
2351               __mod = 2;
2352               __news += 2;
2353             }
2354           else if (__testsign)
2355             {
2356               __news[0] = __olds[0];
2357               __mod = 1;
2358               ++__news;
2359             }
2360           // else Padding first.
2361         }
2362       _Traits::assign(__news, __plen, __fill);
2363       _Traits::copy(__news + __plen, const_cast<_CharT*>(__olds + __mod),
2364                     __oldlen - __mod);
2365     }
2366
2367   bool
2368   __verify_grouping(const char* __grouping, size_t __grouping_size,
2369                     const string& __grouping_tmp)
2370   {
2371     const size_t __n = __grouping_tmp.size() - 1;
2372     const size_t __min = std::min(__n, __grouping_size - 1);
2373     size_t __i = __n;
2374     bool __test = true;
2375     
2376     // Parsed number groupings have to match the
2377     // numpunct::grouping string exactly, starting at the
2378     // right-most point of the parsed sequence of elements ...
2379     for (size_t __j = 0; __j < __min && __test; --__i, ++__j)
2380       __test = __grouping_tmp[__i] == __grouping[__j];
2381     for (; __i && __test; --__i)
2382       __test = __grouping_tmp[__i] == __grouping[__min];
2383     // ... but the last parsed grouping can be <= numpunct
2384     // grouping.
2385     __test &= __grouping_tmp[0] <= __grouping[__min];
2386     return __test;
2387   }
2388
2389   template<typename _CharT>
2390     _CharT*
2391     __add_grouping(_CharT* __s, _CharT __sep,
2392                    const char* __gbeg, size_t __gsize,
2393                    const _CharT* __first, const _CharT* __last)
2394     {
2395       if (__last - __first > *__gbeg)
2396         {
2397           const bool __bump = __gsize != 1;
2398           __s = std::__add_grouping(__s,  __sep, __gbeg + __bump,
2399                                     __gsize - __bump, __first,
2400                                     __last - *__gbeg);
2401           __first = __last - *__gbeg;
2402           *__s++ = __sep;
2403         }
2404       do
2405         *__s++ = *__first++;
2406       while (__first != __last);
2407       return __s;
2408     }
2409
2410   // Inhibit implicit instantiations for required instantiations,
2411   // which are defined via explicit instantiations elsewhere.
2412   // NB: This syntax is a GNU extension.
2413 #if _GLIBCXX_EXTERN_TEMPLATE
2414   extern template class moneypunct<char, false>;
2415   extern template class moneypunct<char, true>;
2416   extern template class moneypunct_byname<char, false>;
2417   extern template class moneypunct_byname<char, true>;
2418   extern template class money_get<char>;
2419   extern template class money_put<char>;
2420   extern template class numpunct<char>;
2421   extern template class numpunct_byname<char>;
2422   extern template class num_get<char>;
2423   extern template class num_put<char>;
2424   extern template class __timepunct<char>;
2425   extern template class time_put<char>;
2426   extern template class time_put_byname<char>;
2427   extern template class time_get<char>;
2428   extern template class time_get_byname<char>;
2429   extern template class messages<char>;
2430   extern template class messages_byname<char>;
2431   extern template class ctype_byname<char>;
2432   extern template class codecvt_byname<char, char, mbstate_t>;
2433   extern template class collate<char>;
2434   extern template class collate_byname<char>;
2435
2436   extern template
2437     const codecvt<char, char, mbstate_t>&
2438     use_facet<codecvt<char, char, mbstate_t> >(const locale&);
2439
2440   extern template
2441     const collate<char>&
2442     use_facet<collate<char> >(const locale&);
2443
2444   extern template
2445     const numpunct<char>&
2446     use_facet<numpunct<char> >(const locale&);
2447
2448   extern template
2449     const num_put<char>&
2450     use_facet<num_put<char> >(const locale&);
2451
2452   extern template
2453     const num_get<char>&
2454     use_facet<num_get<char> >(const locale&);
2455
2456   extern template
2457     const moneypunct<char, true>&
2458     use_facet<moneypunct<char, true> >(const locale&);
2459
2460   extern template
2461     const moneypunct<char, false>&
2462     use_facet<moneypunct<char, false> >(const locale&);
2463
2464   extern template
2465     const money_put<char>&
2466     use_facet<money_put<char> >(const locale&);
2467
2468   extern template
2469     const money_get<char>&
2470     use_facet<money_get<char> >(const locale&);
2471
2472   extern template
2473     const __timepunct<char>&
2474     use_facet<__timepunct<char> >(const locale&);
2475
2476   extern template
2477     const time_put<char>&
2478     use_facet<time_put<char> >(const locale&);
2479
2480   extern template
2481     const time_get<char>&
2482     use_facet<time_get<char> >(const locale&);
2483
2484   extern template
2485     const messages<char>&
2486     use_facet<messages<char> >(const locale&);
2487
2488   extern template
2489     bool
2490     has_facet<ctype<char> >(const locale&);
2491
2492   extern template
2493     bool
2494     has_facet<codecvt<char, char, mbstate_t> >(const locale&);
2495
2496   extern template
2497     bool
2498     has_facet<collate<char> >(const locale&);
2499
2500   extern template
2501     bool
2502     has_facet<numpunct<char> >(const locale&);
2503
2504   extern template
2505     bool
2506     has_facet<num_put<char> >(const locale&);
2507
2508   extern template
2509     bool
2510     has_facet<num_get<char> >(const locale&);
2511
2512   extern template
2513     bool
2514     has_facet<moneypunct<char> >(const locale&);
2515
2516   extern template
2517     bool
2518     has_facet<money_put<char> >(const locale&);
2519
2520   extern template
2521     bool
2522     has_facet<money_get<char> >(const locale&);
2523
2524   extern template
2525     bool
2526     has_facet<__timepunct<char> >(const locale&);
2527
2528   extern template
2529     bool
2530     has_facet<time_put<char> >(const locale&);
2531
2532   extern template
2533     bool
2534     has_facet<time_get<char> >(const locale&);
2535
2536   extern template
2537     bool
2538     has_facet<messages<char> >(const locale&);
2539
2540 #ifdef _GLIBCXX_USE_WCHAR_T
2541   extern template class moneypunct<wchar_t, false>;
2542   extern template class moneypunct<wchar_t, true>;
2543   extern template class moneypunct_byname<wchar_t, false>;
2544   extern template class moneypunct_byname<wchar_t, true>;
2545   extern template class money_get<wchar_t>;
2546   extern template class money_put<wchar_t>;
2547   extern template class numpunct<wchar_t>;
2548   extern template class numpunct_byname<wchar_t>;
2549   extern template class num_get<wchar_t>;
2550   extern template class num_put<wchar_t>;
2551   extern template class __timepunct<wchar_t>;
2552   extern template class time_put<wchar_t>;
2553   extern template class time_put_byname<wchar_t>;
2554   extern template class time_get<wchar_t>;
2555   extern template class time_get_byname<wchar_t>;
2556   extern template class messages<wchar_t>;
2557   extern template class messages_byname<wchar_t>;
2558   extern template class ctype_byname<wchar_t>;
2559   extern template class codecvt_byname<wchar_t, char, mbstate_t>;
2560   extern template class collate<wchar_t>;
2561   extern template class collate_byname<wchar_t>;
2562
2563   extern template
2564     const codecvt<wchar_t, char, mbstate_t>&
2565     use_facet<codecvt<wchar_t, char, mbstate_t> >(locale const&);
2566
2567   extern template
2568     const collate<wchar_t>&
2569     use_facet<collate<wchar_t> >(const locale&);
2570
2571   extern template
2572     const numpunct<wchar_t>&
2573     use_facet<numpunct<wchar_t> >(const locale&);
2574
2575   extern template
2576     const num_put<wchar_t>&
2577     use_facet<num_put<wchar_t> >(const locale&);
2578
2579   extern template
2580     const num_get<wchar_t>&
2581     use_facet<num_get<wchar_t> >(const locale&);
2582
2583   extern template
2584     const moneypunct<wchar_t, true>&
2585     use_facet<moneypunct<wchar_t, true> >(const locale&);
2586
2587   extern template
2588     const moneypunct<wchar_t, false>&
2589     use_facet<moneypunct<wchar_t, false> >(const locale&);
2590
2591   extern template
2592     const money_put<wchar_t>&
2593     use_facet<money_put<wchar_t> >(const locale&);
2594
2595   extern template
2596     const money_get<wchar_t>&
2597     use_facet<money_get<wchar_t> >(const locale&);
2598
2599   extern template
2600     const __timepunct<wchar_t>&
2601     use_facet<__timepunct<wchar_t> >(const locale&);
2602
2603   extern template
2604     const time_put<wchar_t>&
2605     use_facet<time_put<wchar_t> >(const locale&);
2606
2607   extern template
2608     const time_get<wchar_t>&
2609     use_facet<time_get<wchar_t> >(const locale&);
2610
2611   extern template
2612     const messages<wchar_t>&
2613     use_facet<messages<wchar_t> >(const locale&);
2614
2615  extern template
2616     bool
2617     has_facet<ctype<wchar_t> >(const locale&);
2618
2619   extern template
2620     bool
2621     has_facet<codecvt<wchar_t, char, mbstate_t> >(const locale&);
2622
2623   extern template
2624     bool
2625     has_facet<collate<wchar_t> >(const locale&);
2626
2627   extern template
2628     bool
2629     has_facet<numpunct<wchar_t> >(const locale&);
2630
2631   extern template
2632     bool
2633     has_facet<num_put<wchar_t> >(const locale&);
2634
2635   extern template
2636     bool
2637     has_facet<num_get<wchar_t> >(const locale&);
2638
2639   extern template
2640     bool
2641     has_facet<moneypunct<wchar_t> >(const locale&);
2642
2643   extern template
2644     bool
2645     has_facet<money_put<wchar_t> >(const locale&);
2646
2647   extern template
2648     bool
2649     has_facet<money_get<wchar_t> >(const locale&);
2650
2651   extern template
2652     bool
2653     has_facet<__timepunct<wchar_t> >(const locale&);
2654
2655   extern template
2656     bool
2657     has_facet<time_put<wchar_t> >(const locale&);
2658
2659   extern template
2660     bool
2661     has_facet<time_get<wchar_t> >(const locale&);
2662
2663   extern template
2664     bool
2665     has_facet<messages<wchar_t> >(const locale&);
2666 #endif
2667 #endif
2668 } // namespace std
2669
2670 #endif