Merge from mainline (163495:164578).
[official-gcc/graphite-test-results.git] / libstdc++-v3 / testsuite / 22_locale / time_put / put / char / 9780-1.cc
blob95c4b684490c3a60e335db3b9cb67bde8e8deaf5
1 // { dg-require-namedlocale "de_DE" }
2 // { dg-require-namedlocale "es_ES" }
4 // Copyright (C) 2004, 2005, 2009 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 3, or (at your option)
10 // any later version.
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License along
18 // with this library; see the file COPYING3. If not see
19 // <http://www.gnu.org/licenses/>.
21 #include <sstream>
22 #include <locale>
23 #include <testsuite_hooks.h>
25 int main()
27 using namespace std;
29 bool test __attribute__((unused)) = true;
30 locale l1 = locale("de_DE");
31 locale l2 = locale("es_ES");
33 const time_put<char> &tp = use_facet<time_put<char> >(l1);
34 ostringstream oss;
35 oss.imbue(l2);
37 tm t = tm();
38 tp.put(oss.rdbuf(), oss, ' ', &t, 'A');
39 string res = oss.str();
41 VERIFY( res == "domingo" );
43 return 0;
46 // Two interpretations of the standard.
48 // 1 : time_get, time_put each have their own data internally
49 // use internal data for time and date specifics
50 // use getloc for ctype info
52 // 2 : time_get, time_put use the ios_base& argument and getloc to
53 // retrieve the necessary data.
54 // use getloc for ctype, time and date specifics
56 // It is my opinion that the language in the standard is sufficiently
57 // vague to permit both interpretations. In particular, the interface
58 // for time_get and time_put is based on strftime, which as
59 // POSIX notes is dependent on LC_TIME. The C++ standard, however,
60 // does not specify the equivalent mappings of LC_TIME to time_get and
61 // time_put.
64 The problems with the first approach, as above, are numerous.
66 1) The locale usage and design for formatters and parsers becomes
67 fragmented. On one side, num_put and money_put, and on the other,
68 time_put. This inconsistency is not useful.
70 2) The data structures for time and date formatting are the largest in
71 the locale library. Making time_put and time_get keep separate
72 copies is inefficient. (Note that time_put and time_get are in the
73 same locale::category).
78 22.2.5 - The time category [lib.category.time]
80 -1- Templates time_get<charT,InputIterator> and
81 time_put<charT,OutputIterator> provide date and time formatting and
82 parsing. All specifications of member functions for time_put and
83 time_get in the subclauses of lib.category.time only apply to the
84 instantiations required in Tables 51 and 52
85 (lib.locale.category). Their members use their ios_base&,
86 ios_base::iostate&, and fill arguments as described in
87 (lib.locale.categories), and the ctype<> facet, to determine
88 formatting details.
92 22.2 - Standard locale categories [lib.locale.categories]
94 -1- Each of the standard categories includes a family of facets. Some
95 of these implement formatting or parsing of a datum, for use by
96 standard or users' iostream operators << and >>, as members put() and
97 get(), respectively. Each such member function takes an ios_base&
98 argument whose members flags(), precision(), and width(), specify the
99 format of the corresponding datum. (lib.ios.base). Those functions
100 which need to use other facets call its member getloc() to retrieve
101 the locale imbued there. Formatting facets use the character argument
102 fill to fill out the specified width where necessary.
106 With GCC/libstdc++, the output of the program with the arguments
107 of de_DE es_ES is:
108 domingo
109 lunes
110 martes
111 miércoles
112 jueves
113 viernes
114 sábado
116 With Intel C++, it is: (this is clearly wrong)
117 Sunday
118 Monday
119 Tuesday
120 Wednesday
121 Thursday
122 Friday
123 Saturday
125 And with RogueWave C++
126 Sonntag
127 Montag
128 Dienstag
129 Mittwoch
130 Donnerstag
131 Freitag
132 Samstag