public member function
<locale>
pattern neg_format() const;
Return format of negative monetary expressions
Returns the pattern that specifies the format for negative monetary expressions.
This pattern represents the order in which the components of a monetary expression are ordered.
It is expressed as an object of member type pattern (inherited from money_base), which is an array of four char
elements, each corresponding to a value of member enum
type part (also inherited from money_base).
Internally, this function simply calls the virtual protected member do_neg_format, which for the standard specializations returns a pattern object initialized to {symbol,sign,none,value}
.
Return value
A pattern object containing four part elements (casted to char
s), each representing one of:
member constant | value | representation | notes |
none | 0 | Nothing. Can be expanded to whitespaces (unless it is the last specifier) | cannot be be the first specifier |
space | 1 | At least one white space, but can be expanded to more | can neither be the first nor last specifier |
symbol | 2 | Currency symbol | |
sign | 3 | Negative sign | |
value | 4 | The numerical value of the monetary expression | |
Member type pattern is inherited from money_base: it is an array of four char elements, each expected to be the conversion of one of the part values: the sequence contains (in some unspecified order that depends on the locale) either one space element or one none element and exactly one of each of the others (symbol, sign and value).
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
// moneypunct example
#include <iostream> // std::cout
#include <locale> // std::locale, std::moneypunct, std::use_facet
// overload inserter to print patterns:
std::ostream& operator<< (std::ostream& os, std::moneypunct<char>::pattern p)
{
for (int i=0; i<4; i++)
switch (p.field[i]) {
case std::moneypunct<char>::none: std::cout << "none "; break;
case std::moneypunct<char>::space: std::cout << "space "; break;
case std::moneypunct<char>::symbol: std::cout << "symbol "; break;
case std::moneypunct<char>::sign: std::cout << "sign "; break;
case std::moneypunct<char>::value: std::cout << "value "; break;
}
return os;
}
int main ()
{
std::locale mylocale;
const std::moneypunct<char>& mp = std::use_facet<std::moneypunct<char> >(mylocale);
std::cout << "moneypunct in locale \"" << mylocale.name() << "\":\n";
std::cout << "decimal_point: " << mp.decimal_point() << '\n';
std::cout << "thousands_sep: " << mp.thousands_sep() << '\n';
std::cout << "grouping: " << mp.grouping() << '\n';
std::cout << "curr_symbol: " << mp.curr_symbol() << '\n';
std::cout << "positive_sign: " << mp.positive_sign() << '\n';
std::cout << "negative_sign: " << mp.negative_sign() << '\n';
std::cout << "frac_digits: " << mp.frac_digits() << '\n';
std::cout << "pos_format: " << mp.pos_format() << '\n';
std::cout << "neg_format: " << mp.neg_format() << '\n';
return 0;
}
|
Possible output:
moneypunct in locale "C":
decimal_point:
thousands_sep:
grouping:
curr_symbol:
positive_sign:
negative_sign: -
frac_digits: 0
pos_format: symbol sign none value
neg_format: symbol sign none value
|
Data races
The facet is accessed.
Exception safety
Strong guarantee: No side effects in case an exception is thrown.
See also
moneypunct::patternmoneypunct::part- moneypunct::neg_format
- Return format of negative monetary expressions (public member function
)