CppDS.com

C++ 98 11 14 17 20 手册

std::has_facet

来自cppreference.com
< cpp‎ | locale
定义于头文件 <locale>
template< class Facet >
bool has_facet( const locale& loc ) throw();
(C++11 前)
template< class Facet >
bool has_facet( const locale& loc ) noexcept;
(C++11 起)

检查 locale loc 是否实装平面 Facet

参数

loc - 要查询的 locale 对象

返回值

若当前 locale loc 中安装了平面 Facet 则返回 true ,否则返回 false

示例

#include <iostream>
#include <locale>
 
// 最小定制平面
struct myfacet : public std::locale::facet {
    static std::locale::id id;
};
 
std::locale::id myfacet::id;
 
int main()
{
    // loc 是加上 myfacet 的 "C" 本地环境
    std::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';
}

输出:

Can loc classify chars? true
Can loc classify char32_t? false
Does loc implement myfacet? true

参阅

用以封装文化差异的多态刻面的集合
(类)
从本地环境获得一个刻面
(函数模板)
关闭