Namespaces
Variants
Views
Actions

Difference between revisions of "cpp/locale/moneypunct byname"

From cppreference.com
< cpp‎ | locale
m (r2.7.3) (Robot: Adding de, es, fr, it, ja, pt, ru, zh)
m (fmt)
 
(8 intermediate revisions by 4 users not shown)
Line 1: Line 1:
{{cpp/title | moneypunct_byname}}
+
{{cpp/title|moneypunct_byname}}
 
{{cpp/locale/navbar}}
 
{{cpp/locale/navbar}}
{{ddcl list begin}}
+
{{dcl begin}}
{{ddcl list header | locale}}
+
{{dcl header|locale}}
{{ddcl list item | 1=
+
{{dcl|1=
template< class charT, bool Intl = false >
+
template< class CharT, bool Intl = false >
class moneypunct_byname : public std::moneypunct<charT, Intl>;
+
class moneypunct_byname : public std::moneypunct<CharT, Intl>;
 
}}
 
}}
{{ddcl list end}}
+
{{dcl end}}
  
{{c|std::moneypunct_byname}} is a {{c|std::moneypunct}} facet which encapsulates monetary formatting preferences of a locale specified at its construction.
+
{{tt|std::moneypunct_byname}} is a {{lc|std::moneypunct}} facet which encapsulates monetary formatting preferences of a locale specified at its construction.
  
Two specializations are provided by the standard library
+
===Specializations===
 
+
The standard library is guaranteed to provide every specialization that satisfies the following type requirements:
{{dcl list begin}}
+
* {{tt|CharT}} is one of {{c/core|char}} and {{c/core|wchar_t}}, and
{{dcl list header | locale }}
+
* {{tt|Intl}} is a possible specialization on a {{c/core|bool}} parameter.<!-- wording taken from [locale.category] p6, I am not sure whether it simply means 'true or false' -->
{{dcl list item | {{c|std::moneypunct_byname<char, Intl>}} | locale-specific {{c|std::moneypunct}} facet for narrow character I/O }}
+
{{dcl list item | {{c|std::moneypunct_byname<wchar_t, Intl>}} | locale-specific {{c|std::moneypunct}} facet for wide character I/O }}
+
{{dcl list end}}
+
  
 
===Member types===
 
===Member types===
{{dcl list begin}}
+
{{dsc begin}}
{{dcl list hitem | Member type | Definition}}
+
{{dsc hitem | Member type | Definition}}
{{dcl list item | {{tt|pattern}} | {{c|std::money_base::pattern}}}}
+
{{dsc | {{tt|pattern}} | {{lc|std::money_base::pattern}}}}
{{dcl list item | {{tt|string_type}} | {{c|std::basic_string<charT>}}}}
+
{{dsc | {{tt|string_type}} | {{c/core|std::basic_string<CharT>}}}}
{{dcl list end}}
+
{{dsc end}}
  
 
===Member functions===
 
===Member functions===
{{dcl list begin}}
+
{{dsc begin}}
{{dcl list mem ctor | cpp/locale/moneypunct_byname/moneypunct_byname | constructs a new moneypunct_byname facet }}
+
{{dsc inc | cpp/locale/byname/dsc constructor | moneypunct_byname}}
{{dcl list prot mem dtor | cpp/locale/moneypunct_byname/~moneypunct_byname | destructs a moneypunct_byname facet }}
+
{{dsc inc | cpp/locale/byname/dsc destructor | moneypunct_byname}}
{{dcl list end}}
+
{{dsc end}}
  
===Example===
+
{{include | cpp/locale/byname/constructor | moneypunct_byname}}
 +
{{include | cpp/locale/byname/destructor | moneypunct_byname}}
  
 +
{{include | cpp/locale/moneypunct/inherit}}
 +
{{include | cpp/locale/money_base/inherit}}
 +
 +
===Example===
 
{{example
 
{{example
| This example demonistrates how to apply monetary formatting rules of another language without changing the rest of the locale.  
+
|This example demonstrates how to apply monetary formatting rules of another language without changing the rest of the locale.  
| code=
+
|code=
#include <iostream>
+
 
#include <iomanip>
 
#include <iomanip>
 +
#include <iostream>
 
#include <locale>
 
#include <locale>
 +
 
int main()
 
int main()
 
{
 
{
Line 45: Line 48:
 
     std::locale::global(std::locale("en_US.utf8"));
 
     std::locale::global(std::locale("en_US.utf8"));
 
     std::wcout.imbue(std::locale());
 
     std::wcout.imbue(std::locale());
     std::wcout << L"american locale : " << std::showbase
+
     std::wcout << L"american locale: " << std::showbase
 
               << std::put_money(mon) << '\n';
 
               << std::put_money(mon) << '\n';
 
     std::wcout.imbue(std::locale(std::wcout.getloc(),
 
     std::wcout.imbue(std::locale(std::wcout.getloc(),
Line 52: Line 55:
 
               << std::put_money(mon) << '\n';
 
               << std::put_money(mon) << '\n';
 
}
 
}
| output=
+
|output=
american locale : $12,345.67
+
american locale: $12,345.67
 
american locale with russian moneypunct: 12 345.67 руб
 
american locale with russian moneypunct: 12 345.67 руб
 
}}
 
}}
  
 
===See also===
 
===See also===
{{dcl list begin}}
+
{{dsc begin}}
{{dcl list template | cpp/locale/dcl list moneypunct}}
+
{{dsc inc|cpp/locale/dsc moneypunct}}
{{dcl list end}}
+
{{dsc end}}
  
[[de:cpp/locale/moneypunct byname]]
+
{{langlinks|de|es|fr|it|ja|pt|ru|zh}}
[[es:cpp/locale/moneypunct byname]]
+
[[fr:cpp/locale/moneypunct byname]]
+
[[it:cpp/locale/moneypunct byname]]
+
[[ja:cpp/locale/moneypunct byname]]
+
[[pt:cpp/locale/moneypunct byname]]
+
[[ru:cpp/locale/moneypunct byname]]
+
[[zh:cpp/locale/moneypunct byname]]
+

Latest revision as of 10:40, 20 March 2023

 
 
 
Defined in header <locale>
template< class CharT, bool Intl = false >
class moneypunct_byname : public std::moneypunct<CharT, Intl>;

std::moneypunct_byname is a std::moneypunct facet which encapsulates monetary formatting preferences of a locale specified at its construction.

Contents

[edit] Specializations

The standard library is guaranteed to provide every specialization that satisfies the following type requirements:

  • CharT is one of char and wchar_t, and
  • Intl is a possible specialization on a bool parameter.

[edit] Member types

Member type Definition
pattern std::money_base::pattern
string_type std::basic_string<CharT>

[edit] Member functions

(constructor)
constructs a new moneypunct_byname facet
(public member function) [edit]
(destructor)
destroys a moneypunct_byname facet
(protected member function) [edit]

std::moneypunct_byname::moneypunct_byname

explicit moneypunct_byname( const char* name, std::size_t refs = 0 );
explicit moneypunct_byname( const std::string& name, std::size_t refs = 0 );
(since C++11)

Constructs a new std::moneypunct_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::moneypunct_byname::~moneypunct_byname

protected:
~moneypunct_byname();

Destroys the facet.

Inherited from std::moneypunct

Member types

Member type Definition
char_type CharT
string_type std::basic_string<CharT>

Member functions

invokes do_decimal_point
(public member function of std::moneypunct<CharT,International>) [edit]
invokes do_thousands_sep
(public member function of std::moneypunct<CharT,International>) [edit]
invokes do_grouping
(public member function of std::moneypunct<CharT,International>) [edit]
invokes do_curr_symbol
(public member function of std::moneypunct<CharT,International>) [edit]
invokes do_positive_sign or do_negative_sign
(public member function of std::moneypunct<CharT,International>) [edit]
invokes do_frac_digits
(public member function of std::moneypunct<CharT,International>) [edit]
invokes do_pos_format/do_neg_format
(public member function of std::moneypunct<CharT,International>) [edit]

Protected member functions

provides the character to use as decimal point
(virtual protected member function of std::moneypunct<CharT,International>) [edit]
provides the character to use as thousands separator
(virtual protected member function of std::moneypunct<CharT,International>) [edit]
[virtual]
provides the numbers of digits between each pair of thousands separators
(virtual protected member function of std::moneypunct<CharT,International>) [edit]
provides the string to use as the currency identifier
(virtual protected member function of std::moneypunct<CharT,International>) [edit]
provides the string to indicate a positive or negative value
(virtual protected member function of std::moneypunct<CharT,International>) [edit]
provides the number of digits to display after the decimal point
(virtual protected member function of std::moneypunct<CharT,International>) [edit]
provides the formatting pattern for currency values
(virtual protected member function of std::moneypunct<CharT,International>) [edit]

Member constants

Member Definition
const bool intl (static) International

Member objects

static std::locale::id id
id of the locale
(public member object)

Inherited from std::money_base

Member type Definition
enum part { none, space, symbol, sign, value }; unscoped enumeration type
struct pattern { char field[4]; }; the monetary format type
Enumeration constant Definition
none whitespace is permitted but not required except in the last position, where whitespace is not permitted
space one or more whitespace characters are required
symbol the sequence of characters returned by std::moneypunct::curr_symbol is required
sign the first of the characters returned by std::moneypunct::positive_sign or std::moneypunct::negative_sign is required
value the absolute numeric monetary value is required

[edit] Example

This example demonstrates how to apply monetary formatting rules of another language without changing the rest of the locale.

#include <iomanip>
#include <iostream>
#include <locale>
 
int main()
{
    long double mon = 1234567;
    std::locale::global(std::locale("en_US.utf8"));
    std::wcout.imbue(std::locale());
    std::wcout << L"american locale: " << std::showbase
               << std::put_money(mon) << '\n';
    std::wcout.imbue(std::locale(std::wcout.getloc(),
                                 new std::moneypunct_byname<wchar_t>("ru_RU.utf8")));
    std::wcout << L"american locale with russian moneypunct: "
               << std::put_money(mon) << '\n';
}

Output:

american locale: $12,345.67
american locale with russian moneypunct: 12 345.67 руб

[edit] See also

defines monetary formatting parameters used by std::money_get and std::money_put
(class template) [edit]