Topic: 22.2.2.2.2 Facet locale and function put
Author: yecril@bluebottle.com ("Krzysztof Zelechowski")
Date: Tue, 7 Jun 2005 16:20:19 GMT Raw View
And what if I replace "English" with "C" and "Polish" with ""? I get the
same result and I am in the defined area.
Chris
Uzytkownik "Alberto Barbati" <AlbertoBarbati@libero.it> napisal w wiadomosci
news:SK4ie.10796$795.344588@twister1.libero.it...
Krzysztof elechowski wrote:
> If I use facet num_put that belongs to the Polish locale to put a number
> with the str parameter localized to the English locale, I get an English
> form of a number. What is the motivation making this facet belong to a
> locale if the locale it belongs to has no influence on how it works?
> Chris
>
> Relevant code snippet produces the output 100,000:
>
> std::wcout.imbue(std::locale("English"));
>
> *std::use_facet<std::num_put<wchar_t> >(std::locale("Polish"))
>
> .put(std::wcout, std::wcout, L' ', 100000L) = L'\n';
>
This is a quality-of-implementation issue. The standard does not require
any specific behaviour to locale objects and their facets if they are
created with names different from "C" or "".
Alberto
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: yecril@bluebottle.com ("Krzysztof Zelechowski")
Date: Tue, 7 Jun 2005 17:08:21 GMT Raw View
Nope. I have found it in the standard at last, it is described in
22.1.1.1.1/5. My following question is: why is this clarification
restricted to num_*? I think that all *_put and *_get facets should be
described in the same way. And let me repeat the main question: what is the
motivation for using the stream's locale instead of using the locale the
facet was derived from?
Chris
Uzytkownik "Alberto Barbati" <AlbertoBarbati@libero.it> napisal w wiadomosci
news:SK4ie.10796$795.344588@twister1.libero.it...
Krzysztof elechowski wrote:
> If I use facet num_put that belongs to the Polish locale to put a number
> with the str parameter localized to the English locale, I get an English
> form of a number. What is the motivation making this facet belong to a
> locale if the locale it belongs to has no influence on how it works?
> Chris
>
> Relevant code snippet produces the output 100,000:
>
> std::wcout.imbue(std::locale("English"));
>
> *std::use_facet<std::num_put<wchar_t> >(std::locale("Polish"))
>
> .put(std::wcout, std::wcout, L' ', 100000L) = L'\n';
>
This is a quality-of-implementation issue. The standard does not require
any specific behaviour to locale objects and their facets if they are
created with names different from "C" or "".
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: AlbertoBarbati@libero.it (Alberto Barbati)
Date: Tue, 7 Jun 2005 23:23:35 GMT Raw View
Krzysztof Zelechowski wrote:
> Nope. I have found it in the standard at last, it is described in
> 22.1.1.1.1/5. My following question is: why is this clarification
> restricted to num_*? I think that all *_put and *_get facets should be
> described in the same way.
Why? *Only* num_put and num_get need to call use_facet to obtain access
to other facets, namely numpunct and ctype. No other facet have such
requirement so why would they need such clarification?
> And let me repeat the main question: what is the
> motivation for using the stream's locale instead of using the locale the
> facet was derived from?
>
Because the same facet may be present in more than one locale. Executing
do_put, a num_put facet instance requires a numpunct facet instance,
where does it look that for? As the relationship between locale and
facets is N-to-1, the num_put facet cannot obtain such a facet on its
own: it must be provided in some other way.
Let me say that again in other words: suppose you have
std::locale g; // a snapshot of the global locale
std::locale l(g, new numpunct_byname<char>("Some_Valid_Name"));
then most implementations would satisfy both
&use_facet<num_put<char> >(g) == &use_facet<num_put<char> >(l)
and
&use_facet<numpunct<char> >(g) != &use_facet<numpunct<char> >(l)
When you call num_put<char>::do_put(), which numpunct<char> instance
would you use? The one in g or the one in l? Using the facet from the
stream is the most obvious answer.
HTH,
Alberto
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: kanze@gabi-soft.fr
Date: Wed, 8 Jun 2005 10:05:17 CST Raw View
Alberto Barbati wrote:
> Krzysztof Zelechowski wrote:
> > Nope. I have found it in the standard at last, it is
> > described in 22.1.1.1.1/5. My following question is: why is
> > this clarification restricted to num_*? I think that all
> > *_put and *_get facets should be described in the same way.
> Why? *Only* num_put and num_get need to call use_facet to
> obtain access to other facets, namely numpunct and ctype. No
> other facet have such requirement so why would they need such
> clarification?
Perhaps, but that doesn't change the crux of his question. He
explicitly asks that a number be formatted in the Polish locale,
and he gets what looks very much like an English locale. (It
could be worse. In fact, parts of the conversion, like the
order of the digits, are controled by the Polish locale. If he
had asked for an "Arabic" locale, he would have gotten English
num_punct, but the digits would have been output in the Arabic
order, which is the reverse of what we usually see.)
For all intents and purposes, the sentence he has quoted makes
the numeric facets unusable.
> > And let me repeat the main question: what is the motivation
> > for using the stream's locale instead of using the locale
> > the facet was derived from?
> Because the same facet may be present in more than one
> locale. Executing do_put, a num_put facet instance requires a
> numpunct facet instance, where does it look that for? As the
> relationship between locale and facets is N-to-1, the num_put
> facet cannot obtain such a facet on its own: it must be
> provided in some other way.
Actually, the motivation is simple: make it easier to create new
locales with different numeric formatting. If you need a locale
where the thousands separator is ':', you don't have to
re-implement the actual conversions in num_get and num_put; you
just change num_punct. Since most numeric formats only differ
by what is in num_punct, this makes it a lot easier to create
new numeric formats.
Still, there should have been some way for num_get and num_put
to pick up the correct numeric_formats. (One possible solution
would have been to have the num_punct elements belong to the
num_xxx facets, and pass them as a parameter to the constructor,
much like is done for ctype when charT is char.)
> Let me say that again in other words: suppose you have
> std::locale g; // a snapshot of the global locale
> std::locale l(g, new numpunct_byname<char>("Some_Valid_Name"));
> then most implementations would satisfy both
> &use_facet<num_put<char> >(g) == &use_facet<num_put<char> >(l)
> and
> &use_facet<numpunct<char> >(g) != &use_facet<numpunct<char> >(l)
> When you call num_put<char>::do_put(), which numpunct<char>
> instance would you use? The one in g or the one in l? Using
> the facet from the stream is the most obvious answer.
*IF* you suppose that the current design (division into facets,
etc.) is the only possible one. Facets are instances, not
types, and two facets with exactly the same type may behave
differently; ctype<char> is a good example of this. So why not
put the actual conversion in a class which takes the
punctuation as a parameter to the constructor? (One obvious
answer is that time_get/put and money_get/put also need
num_punct. And num_punct is there for any facets for new types
which also might need it.)
To be honest, it is a difficult problem, and the goal of
allowing the user to effectively create a new conversion format
without having to reimplement all of the conversion, is
certainly laudable. But the OP is correct that the current
situation doesn't work very well.
--
James Kanze GABI Software
Conseils en informatique orient e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S mard, 78210 St.-Cyr-l' cole, France, +33 (0)1 30 23 00 34
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: yecril@bluebottle.com ("Krzysztof Zelechowski")
Date: Thu, 9 Jun 2005 18:15:22 GMT Raw View
Uzytkownik <kanze@gabi-soft.fr> napisal w wiadomosci
news:1118236583.195989.36540@f14g2000cwb.googlegroups.com...
> *IF* you suppose that the current design (division into facets,
> etc.) is the only possible one. Facets are instances, not
> types, and two facets with exactly the same type may behave
> differently; ctype<char> is a good example of this. So why not
> put the actual conversion in a class which takes the
> punctuation as a parameter to the constructor? (One obvious
> answer is that time_get/put and money_get/put also need
> num_punct. And num_punct is there for any facets for new types
> which also might need it.)
If all *_* facets use_facet<numpunct> (ios_base::getloc()) in the main
method, I repeat my second question: why is 22.1.1.1.1/5 restricted to
num_*? It should apply to *_* accordingly.
Chris
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: sebor@roguewave.com
Date: Thu, 9 Jun 2005 16:08:07 CST Raw View
You are not using a num_put facet from the Polish locale. You're using
the one and only num_put<wchar_t> facet there is: the base facet
(there's usually no difference between the facet in the Polish locale
and one in any other locale). The numpunct facet is what determines the
punctuation characters and the format (i.e., the data), while the
num_put facet controls how the formatting data are applied (i.e., the
formatting algorithm). If this weren't split up, every named locale
would end up with a separate copy of both the data and the algorithm
facets (i.e., both the formatting and the parsing facet). This way they
can all share the same algorithm object (not that it takes up a whole
lot of space). In our implementation there's at most one
num_put<wchar_t> object for the whole process, regardless of how many
named locales the process creates.
In addition, if the punctuation and formatting facets weren't
separated, it could be tricky to keep num_get and num_put in sync with
one another (just as it can be tricky to keep time_get and time_put in
sync). Customizing one would require customizing the other exactly the
same way.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: yecril@bluebottle.com ("Krzysztof elechowski")
Date: Mon, 16 May 2005 16:20:10 GMT Raw View
If I use facet num_put that belongs to the Polish locale to put a number
with the str parameter localized to the English locale, I get an English
form of a number. What is the motivation making this facet belong to a
locale if the locale it belongs to has no influence on how it works?
Chris
Relevant code snippet produces the output 100,000:
std::wcout.imbue(std::locale("English"));
*std::use_facet<std::num_put<wchar_t> >(std::locale("Polish"))
.put(std::wcout, std::wcout, L' ', 100000L) = L'\n';
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: AlbertoBarbati@libero.it (Alberto Barbati)
Date: Tue, 17 May 2005 23:31:25 GMT Raw View
Krzysztof =AFelechowski wrote:
> If I use facet num_put that belongs to the Polish locale to put a numbe=
r=20
> with the str parameter localized to the English locale, I get an Englis=
h=20
> form of a number. What is the motivation making this facet belong to a=
=20
> locale if the locale it belongs to has no influence on how it works?
> Chris
>=20
> Relevant code snippet produces the output 100,000:
>=20
> std::wcout.imbue(std::locale("English"));
>=20
> *std::use_facet<std::num_put<wchar_t> >(std::locale("Polish"))
>=20
> .put(std::wcout, std::wcout, L' ', 100000L) =3D L'\n';
>=20
This is a quality-of-implementation issue. The standard does not require
any specific behaviour to locale objects and their facets if they are
created with names different from "C" or "".
Alberto
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]