std::messages_byname
From cppreference.com
C++
Feature test macros (C++20)
Concepts library (C++20)
Metaprogramming library (C++11)
Ranges library (C++20)
Filesystem library (C++17)
Concurrency support library (C++11)
Execution control library (C++26)
Text processing library
Regular expressions library (C++11)
Formatting library (C++20)
(C++17)
(C++17)
(C++17)
(C++17)
(C++17)
(C++26)
Localization library
messages_byname
(C++11/17/26*)
(C++11/17/26*)
(C++11/17/26*)
(C++11/17/26*)
(C++11/17/26*)
(C++11/17/26*)
Defined in header
<locale>
template< class CharT >
class messages_byname : public std::messages <CharT>;
class messages_byname : public std::messages <CharT>;
std::messages_byname
is a std::messages facet which encapsulates retrieval of strings from message catalogs of the locale specified at its construction.
Contents
[edit] Specializations
The standard library is guaranteed to provide the following specializations:
Defined in header
<locale>
std::messages_byname<char>
narrow/multibyte message catalog access
std::messages_byname<wchar_t>
wide string message catalog access
[edit] Nested types
Type
Definition
catalog
std::messages_base <CharT>::catalog
string_type
std::basic_string <CharT>
[edit] Member functions
std::messages_byname::messages_byname
explicit messages_byname( const char* name, std::size_t refs = 0 );
explicit messages_byname( const std::string & name, std::size_t refs = 0 );
(since C++11)
Constructs a new std::messages_byname
facet for a locale with name.
refs is used for resource management: if refs == 0, the implementation destroys the facet, when the last std::locale object holding it is destroyed. Otherwise, the object is not destroyed.
Parameters
name
-
the name of the locale
refs
-
the number of references that link to the facet
std::messages_byname::~messages_byname
protected:
~messages_byname();
~messages_byname();
Destroys the facet.
Inherited from std::messages
Nested types
Type
Definition
char_type
CharT
string_type
std::basic_string <CharT>
[edit] Data members
Member
Description
Member functions
Protected member functions
[virtual]
(virtual protected member function of
std::messages<CharT>
) [edit]
[virtual]
(virtual protected member function of
std::messages<CharT>
) [edit]
Inherited from std::messages_base
Nested types
Type
Definition
catalog
an unspecified signed integer type
[edit] Example
Run this code
#include <iostream> #include <locale> void try_with(const std::locale & loc) { const std::messages <char>& facet = std::use_facet <std::messages <char>>(loc); std::messages <char>::catalog cat = facet.open("sed", std::cout.getloc()); if (cat < 0) std::cout << "Could not open \"sed\" message catalog\n"; else std::cout << "\"No match\" " << facet.get(cat, 0, 0, "No match") << '\n' << "\"Memory exhausted\" " << facet.get(cat, 0, 0, "Memory exhausted") << '\n'; facet.close(cat); } int main() { std::locale loc("en_US.utf8"); std::cout.imbue(loc); try_with(std::locale (loc, new std::messages_byname<char>("de_DE.utf8"))); try_with(std::locale (loc, new std::messages_byname<char>("fr_FR.utf8"))); try_with(std::locale (loc, new std::messages_byname<char>("ja_JP.utf8"))); }
Possible output:
"No match" Keine Übereinstimmung "Memory exhausted" Speicher erschöpft "No match" Pas de concordance "Memory exhausted" Mémoire épuisée "No match" 照合しません "Memory exhausted" メモリーが足りません