c++ - When should I use a derived class facet in lieu of a base class facet? -
there few standard base class facets in c++ standard library default behavior dependent on classic "c" locale (std::locale::classic()
). make reasonable switch derived class facets (aka byname
facets) behavior depends on locale specified @ construction if program requires culturally-specific functionality.
for example, std::ctype
provides classic "c" character classification:
§22.4.1.3.3
static const mask* classic_table() noexcept;
returns: pointer initial element of array of size
table_size
represents classifications of characters in "c" locale
does mean behavior of std::ctype
functionally distinct of locale installed? instance, have japanese locale:
std::locale loc("ja_jp");
and wanted use facet performed character classification on japanese characters. character classification std::ctype
for:
auto& f = std::use_facet<std::ctype<char>>(loc);
will f
's ctype
methods classify characters based on japanese locale, or classic "c" one? first guess "c" locale based on standard quote above, in fact japanese locale. i'm wondering why quote doesn't agree happening here.
here questions:
why standard
ctype
performs "c" character classification when ctype classifies based on locale being used?since above true, derived class facets come in? why should use derived class facet when base class uses locale want?
only default-constructed std::ctype<char>
facet uses classic_table
classification. facet obtained system-provided "ja_jp"
not example of that.
when talking derived facets, people refer user-defined facets derived std::ctype , like, not system-providedbyname
facets. may use derived ctype
facet if want redefine character class, example, treat commas whitespace parse comma-separated input stream, or stop treating spaces , tabs whitespace, parse stream line-by-line.
Comments
Post a Comment