Q about ctype.narrow

Martin Sebor sebor@roguewave.com
Wed Nov 26 16:41:00 GMT 2003


Pétur Runólfsson wrote:

...
> The numpunct_cache meets this requirement, so it's OK. Also, since
> only facets that are installed in locales are bound by this rule,
> this would be OK, so long as this facet is never put in a locale:
> 
> class Qux : public ctype<char>
> {
> protected:
>   char do_widen(char c) const { return (c + time(NULL)) % 256; }
> };

This usage was also, I'm sure, not intended -- the (admittedly
non-normative) note in 22.1.1, p5 makes it pretty clear, IMO:

   -5- [Note: All locale semantics are accessed via use_facet<>
       and has_facet<>, except that: ...

I.e., you have to install a facet in a locale before calling any
of its member functions, and you can only call them after a call
to use_facet on that locale. Our implementation even relies on
it (i.e., some facets, including ctype, will not work correctly
otherwise).

Martin




More information about the Libstdc++ mailing list