Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::has_facet

      From cppreference.com
      <cpp‎ |locale
       
       
       
      Localization library
       
      Defined in header<locale>
      template<class Facet>
      bool has_facet(const locale& loc)throw();
      (until C++11)
      template<class Facet>
      bool has_facet(const locale& loc)noexcept;
      (since C++11)

      Checks if the localeloc implements the facetFacet.

      The program is ill-formed if Facet is not afacet or it is a volatile-qualified facet.

      Contents

      [edit]Parameters

      loc - the locale object to query

      [edit]Return value

      Returnstrue if the facetFacet was installed in the localeloc,false otherwise.

      [edit]Notes

      std::has_facet must returntrue for all localesloc ifFacet is one of the standard facets givenhere.

      [edit]Example

      Run this code
      #include <iostream>#include <locale> // minimal custom facetstruct myfacet:publicstd::locale::facet{staticstd::locale::id id;}; std::locale::id myfacet::id; int main(){// loc is a "C" locale with myfacet addedstd::locale loc(std::locale::classic(), new myfacet);std::cout<<std::boolalpha<<"Can loc classify chars? "<< std::has_facet<std::ctype<char>>(loc)<<'\n'<<"Can loc classify char32_t? "<< std::has_facet<std::ctype<char32_t>>(loc)<<'\n'<<"Does loc implement myfacet? "<< std::has_facet<myfacet>(loc)<<'\n';}

      Output:

      Can loc classify chars? trueCan loc classify char32_t? falseDoes loc implement myfacet? true

      [edit]Defect reports

      The following behavior-changing defect reports were applied retroactively to previously published C++ standards.

      DRApplied toBehavior as publishedCorrect behavior
      LWG 436C++98it was unclear whetherFacet can be cv-qualifiedit can be const-qualified, but not volatile-qualified

      [edit]See also

      set of polymorphic facets that encapsulate cultural differences
      (class)[edit]
      obtains a facet from a locale
      (function template)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/locale/has_facet&oldid=148215"

      [8]ページ先頭

      ©2009-2025 Movatter.jp