std::has_facet
來自 cppreference.com
定義於標頭檔案 <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 起) | |
檢查區域設定 loc 是否實現了 facet Facet
。
如果 Facet 不是 facet 或者它是 volatile 限定的 facet,則程式格式錯誤。
目錄 |
[編輯] 引數
loc | - | 要查詢的區域設定物件 |
[編輯] 返回值
如果 facet Facet
已安裝在區域設定 loc 中,則返回 true,否則返回 false。
[編輯] 注意
如果 Facet
是 此處 給出的標準 facet 之一,則 std::has_facet
必須對所有區域設定 loc 返回 true。
[編輯] 示例
執行此程式碼
#include <iostream> #include <locale> // minimal custom facet struct myfacet : public std::locale::facet { static std::locale::id id; }; std::locale::id myfacet::id; int main() { // loc is a "C" locale with myfacet added 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
[編輯] 缺陷報告
下列更改行為的缺陷報告追溯地應用於以前出版的 C++ 標準。
缺陷報告 | 應用於 | 釋出時的行為 | 正確的行為 |
---|---|---|---|
LWG 436 | C++98 | 尚不清楚 Facet 是否可以 cv 限定 |
它可以是 const 限定的,但不能是 volatile 限定的 |
[編輯] 另請參閱
封裝文化差異的多型刻面集 (類) | |
從區域設定中獲取一個刻面 (函式模板) |