22 Localization library [localization]

22.4 Standard locale categories [locale.categories]

22.4.6 The monetary category [category.monetary]

22.4.6.3 Class template moneypunct [locale.moneypunct]

namespace std {
  class money_base {
  public:
    enum part { none, space, symbol, sign, value };
    struct pattern { char field[4]; };
  };

  template <class charT, bool International = false>
  class moneypunct : public locale::facet, public money_base {
  public:
    typedef charT char_type;
    typedef basic_string<charT> string_type;

    explicit moneypunct(size_t refs = 0);

    charT        decimal_point() const;
    charT        thousands_sep() const;
    string       grouping()      const;
    string_type  curr_symbol()   const;
    string_type  positive_sign() const;
    string_type  negative_sign() const;
    int          frac_digits()   const;
    pattern      pos_format()    const;
    pattern      neg_format()    const;

    static locale::id id;
    static const bool intl = International;

  protected:
    ~moneypunct();
    virtual charT        do_decimal_point() const;
    virtual charT        do_thousands_sep() const;
    virtual string       do_grouping()      const;
    virtual string_type  do_curr_symbol()   const;
    virtual string_type  do_positive_sign() const;
    virtual string_type  do_negative_sign() const;
    virtual int          do_frac_digits()   const;
    virtual pattern      do_pos_format()    const;
    virtual pattern      do_neg_format()    const;
  };
}

The moneypunct<> facet defines monetary formatting parameters used by money_get<> and money_put<>. A monetary format is a sequence of four components, specified by a pattern value p, such that the part value static_cast<part>(p.field[i]) determines the ith component of the format256 In the field member of a pattern object, each value symbol, sign, value, and either space or none appears exactly once. The value none, if present, is not first; the value space, if present, is neither first nor last.

Where none or space appears, white space is permitted in the format, except where none appears at the end, in which case no white space is permitted. The value space indicates that at least one space is required at that position. Where symbol appears, the sequence of characters returned by curr_symbol() is permitted, and can be required. Where sign appears, the first (if any) of the sequence of characters returned by positive_sign() or negative_sign() (respectively as the monetary value is non-negative or negative) is required. Any remaining characters of the sign sequence are required after all other format components. Where value appears, the absolute numeric monetary value is required.

The format of the numeric monetary value is a decimal number:

value ::= units [ decimal-point [ digits ]] |
  decimal-point digits

if frac_digits() returns a positive value, or

value ::= units

otherwise. The symbol decimal-point indicates the character returned by decimal_point(). The other symbols are defined as follows:

units ::= digits [ thousands-sep units ]
digits ::= adigit [ digits ]

In the syntax specification, the symbol adigit is any of the values ct.widen(c) for c in the range '0' through '9', inclusive, and ct is a reference of type const ctype<charT>& obtained as described in the definitions of money_get<> and money_put<>. The symbol thousands-sep is the character returned by thousands_sep(). The space character used is the value ct.widen(' '). White space characters are those characters c for which ci.is(space,c) returns true. The number of digits required after the decimal point (if any) is exactly the value returned by frac_digits().

The placement of thousands-separator characters (if any) is determined by the value returned by grouping(), defined identically as the member numpunct<>::do_grouping().

An array of char, rather than an array of part, is specified for pattern::field purely for efficiency.

22.4.6.3.1 moneypunct members [locale.moneypunct.members]

charT        decimal_point() const;
charT        thousands_sep() const;
string       grouping()      const;
string_type  curr_symbol()   const;
string_type  positive_sign() const;
string_type  negative_sign() const;
int          frac_digits()   const;
pattern      pos_format()    const;
pattern      neg_format()    const;

Each of these functions F returns the result of calling the corresponding virtual member function do_F().

22.4.6.3.2 moneypunct virtual functions [locale.moneypunct.virtuals]

charT do_decimal_point() const;

Returns: The radix separator to use in case do_frac_digits() is greater than zero.257

charT do_thousands_sep() const;

Returns: The digit group separator to use in case do_grouping() specifies a digit grouping pattern.258

string do_grouping() const;

Returns: A pattern defined identically as, but not necessarily equal to, the result of numpunct<charT>::do_grouping().259

string_type do_curr_symbol() const;

Returns: A string to use as the currency identifier symbol.260

string_type do_positive_sign() const; string_type do_negative_sign() const;

Returns: do_positive_sign() returns the string to use to indicate a positive monetary value;261 do_negative_sign() returns the string to use to indicate a negative value.

int do_frac_digits() const;

Returns: The number of digits after the decimal radix separator, if any.262

pattern do_pos_format() const; pattern do_neg_format() const;

Returns: The specializations required in Table [tab:localization.required.specializations] ([locale.category]), namely moneypunct<char>, moneypunct<wchar_t>, moneypunct<char,true>, and moneypunct<wchar_t,true>, return an object of type pattern initialized to { symbol, sign, none, value }.263

In common U.S. locales this is '.'.

In common U.S. locales this is ','.

To specify grouping by 3s, the value is "\003" not "3".

For international specializations (second template parameter true) this is typically four characters long, usually three letters and a space.

This is usually the empty string.

In common U.S. locales, this is 2.

Note that the international symbol returned by do_curr_sym() usually contains a space, itself; for example, "USD ".