STD::NUM_PUT(3cxx)

πŸŽ€ std::num_put< _CharT, _OutIter > β€” from the 3cxx manual πŸŽ€

okay so bestie, buckle up, because this facet is lowkey the whole reason your numbers look cute when you << them into a stream. This is the 3cxx page for it. Let's go πŸ’…


🌸 NAME 🌸

std::num_put< _CharT, _OutIter > β€” the Primary class template num_put. that's it, that's the name ✨


✨ SYNOPSIS ✨

#include <locale>

Inherits std::locale::facet. yup, it's a facet, it's fancy, it's giving locale royalty πŸ‘‘


πŸŽ€ Public Types πŸŽ€

these are the public typedefs, bestie, iykyk:

  • typedef _CharT char_type β€” Public typedefs.
  • typedef _OutIter iter_type β€” Public typedefs.

πŸ’– Public Member Functions πŸ’–

  • num_put (size_t __refs=0) β€” Constructor performs initialization. yes, it does exactly what it says on the tin 🫢
  • template<typename _ValueT > _OutIter _M_insert_float (_OutIter __s, ios_base &__io, _CharT __fill, char __mod, _ValueT __v) const
  • template<typename _ValueT > _OutIter _M_insert_int (_OutIter __s, ios_base &__io, _CharT __fill, _ValueT __v) const
  • iter_type put (iter_type __s, ios_base &__io, char_type __fill, bool __v) const β€” Numeric formatting.
  • iter_type put (iter_type __s, ios_base &__io, char_type __fill, const void *__v) const β€” Numeric formatting.

and then the whole overload squad, all of them "Numeric formatting" (they said it nine times and honestly? respect for consistency):

  • iter_type put (iter_type __s, ios_base &__io, char_type __fill, long __v) const β€” Numeric formatting.
  • iter_type put (iter_type __s, ios_base &__io, char_type __fill, unsigned long __v) const β€” Numeric formatting.
  • iter_type put (iter_type __s, ios_base &__io, char_type __fill, long long __v) const β€” Numeric formatting.
  • iter_type put (iter_type __s, ios_base &__io, char_type __fill, unsigned long long __v) const β€” Numeric formatting.

float era πŸ’…:

  • iter_type put (iter_type __s, ios_base &__io, char_type __fill, double __v) const β€” Numeric formatting.
  • iter_type put (iter_type __s, ios_base &__io, char_type __fill, long double __v) const β€” Numeric formatting.

πŸ¦‹ Static Public Attributes πŸ¦‹

  • static locale::id id β€” Numpunct facet id. that's the one, bestie πŸ’–

🌈 Protected Member Functions 🌈

  • virtual ~num_put () β€” Destructor. (protected AND virtual, she's private like that πŸ™ˆ)
  • void _M_group_float (const char *__grouping, size_t __grouping_size, char_type __sep, const char_type *__p, char_type *__new, char_type *__cs, int &__len) const
  • void _M_group_int (const char *__grouping, size_t __grouping_size, char_type __sep, ios_base &__io, char_type *__new, char_type *__cs, int &__len) const
  • template<typename _ValueT > iter_type _M_insert_float (iter_type, ios_base &__io, char_type __fill, char __mod, _ValueT __v) const
  • template<typename _ValueT > iter_type _M_insert_int (iter_type, ios_base &__io, char_type __fill, _ValueT __v) const
  • void _M_pad (char_type __fill, streamsize __w, ios_base &__io, char_type *__new, const char_type *__cs, int &__len) const

and now the virtual do_put hook squad 🧚:

  • virtual iter_type do_put (iter_type __s, ios_base &__io, char_type __fill, bool __v) const β€” Numeric formatting.
  • virtual iter_type do_put (iter_type __s, ios_base &__io, char_type __fill, long __v) const β€” Numeric formatting.
  • virtual iter_type do_put (iter_type __s, ios_base &__io, char_type __fill, unsigned long __v) const β€” Numeric formatting.
  • virtual iter_type do_put (iter_type __s, ios_base &__io, char_type __fill, long long __v) const β€” Numeric formatting.
  • virtual iter_type do_put (iter_type __s, ios_base &__io, char_type __fill, unsigned long long __v) const β€” Numeric formatting.
  • virtual iter_type do_put (iter_type, ios_base &, char_type, double) const β€” Numeric formatting.
  • virtual iter_type do_put (iter_type, ios_base &, char_type, long double) const β€” Numeric formatting.
  • virtual iter_type do_put (iter_type, ios_base &, char_type, const void *) const β€” Numeric formatting.

(note how the last three are the pared-down no-parameter-names version? the manpage did that, not me, don't come for me 😭)


🧚 Static Protected Member Functions 🧚

the _S_* girlies, all static, all protected:

  • static __c_locale _S_clone_c_locale (__c_locale &__cloc) throw ()
  • static void _S_create_c_locale (__c_locale &__cloc, const char *__s, __c_locale __old=0)
  • static void _S_destroy_c_locale (__c_locale &__cloc)
  • static __c_locale _S_get_c_locale ()
  • static const char * _S_get_c_name () throw ()
  • static __c_locale _S_lc_ctype_c_locale (__c_locale __cloc, const char *__s)

πŸ‘‘ Detailed Description πŸ‘‘

template<typename _CharT, typename _OutIter>
    class std::num_put< _CharT, _OutIter >

Primary class template num_put.

okay so here's the tea β˜• β€” this facet encapsulates the code to convert a number to a string. literally its whole job. it's used by the ostream numeric insertion operators (you know, the << moments of your life πŸ’–).

the num_put template uses protected virtual functions to provide the actual results. the public accessors forward the call to the virtual functions. these virtual functions are hooks for developers to implement the behavior they require from the num_put facet. so like β€” the public ones are the main characters, the virtual ones are the backstage crew making it all happen ✨


⭐ Member Typedef Documentation ⭐

template<typename _CharT , typename _OutIter >
typedef _CharT std::num_put< _CharT, _OutIter >::char_type

Public typedefs. that's her πŸ’…

template<typename _CharT , typename _OutIter >
typedef _OutIter std::num_put< _CharT, _OutIter >::iter_type

Public typedefs. and that's the other her πŸ’…


πŸ’œ Constructor & Destructor Documentation πŸ’œ

🌸 num_put

template<typename _CharT , typename _OutIter >
std::num_put< _CharT, _OutIter >::num_put (size_t __refs = 0) [inline],  [explicit]

Constructor performs initialization. This is the constructor provided by the standard. no cap, that's literally the standard's own constructor 🫢

Parameters

  • __refs β€” Passed to the base facet class.

🌸 ~num_put

template<typename _CharT , typename _OutIter >
virtual std::num_put< _CharT, _OutIter >::~num_put () [inline],  [protected],  [virtual]

Destructor. she's [inline], [protected], and [virtual]. iconic, honestly πŸ‘‘


πŸ”₯ Member Function Documentation πŸ”₯

πŸ’€ do_put (the bool one)

template<typename _CharT , typename _OutIter >
_OutIter std::num_put< _CharT, _OutIter >::do_put (iter_type __s, ios_base & __io, char_type __fill, bool __v) const [protected],  [virtual]

Numeric formatting. These functions do the work of formatting numeric values and inserting them into a stream. This function is a hook for derived classes to change the value returned.

Parameters

  • __s β€” Stream to write to.
  • __io β€” Source of locale and flags.
  • __fill β€” Char_type to use for filling.
  • __v β€” Value to format and insert.

Returns β€” Iterator after writing.

References β€” std::ios_base::_M_getloc(), std::ios_base::adjustfield, std::ios_base::boolalpha, std::ios_base::flags(), std::ios_base::left, and std::ios_base::width().

Referenced by β€” std::num_put< _CharT, _OutIter >::put(), and honestly the manpage lists std::num_put< _CharT, _OutIter >::put() a whole eight times (all eight overloads, one each, no skips, fr fr).

πŸ’€ do_put (the long one)

template<typename _CharT , typename _OutIter >
virtual iter_type std::num_put< _CharT, _OutIter >::do_put (iter_type __s, ios_base & __io, char_type __fill, long __v) const [inline],  [protected],  [virtual]

Numeric formatting. These functions do the work of formatting numeric values and inserting them into a stream. This function is a hook for derived classes to change the value returned.

Parameters

  • __s β€” Stream to write to.
  • __io β€” Source of locale and flags.
  • __fill β€” Char_type to use for filling.
  • __v β€” Value to format and insert.

Returns β€” Iterator after writing.

πŸ’€ do_put (the long long one)

template<typename _CharT , typename _OutIter >
virtual iter_type std::num_put< _CharT, _OutIter >::do_put (iter_type __s, ios_base & __io, char_type __fill, long long __v) const [inline],  [protected],  [virtual]

Numeric formatting. These functions do the work of formatting numeric values and inserting them into a stream. This function is a hook for derived classes to change the value returned.

Parameters

  • __s β€” Stream to write to.
  • __io β€” Source of locale and flags.
  • __fill β€” Char_type to use for filling.
  • __v β€” Value to format and insert.

Returns β€” Iterator after writing.

πŸ’€ do_put (the unsigned long one)

template<typename _CharT , typename _OutIter >
virtual iter_type std::num_put< _CharT, _OutIter >::do_put (iter_type __s, ios_base & __io, char_type __fill, unsigned long __v) const [inline],  [protected],  [virtual]

Numeric formatting. These functions do the work of formatting numeric values and inserting them into a stream. This function is a hook for derived classes to change the value returned.

Parameters

  • __s β€” Stream to write to.
  • __io β€” Source of locale and flags.
  • __fill β€” Char_type to use for filling.
  • __v β€” Value to format and insert.

Returns β€” Iterator after writing.

πŸ’€ do_put (the unsigned long long one)

template<typename _CharT , typename _OutIter >
virtual iter_type std::num_put< _CharT, _OutIter >::do_put (iter_type __s, ios_base & __io, char_type __fill, unsigned long long __v) const [inline],  [protected],  [virtual]

Numeric formatting. These functions do the work of formatting numeric values and inserting them into a stream. This function is a hook for derived classes to change the value returned.

Parameters

  • __s β€” Stream to write to.
  • __io β€” Source of locale and flags.
  • __fill β€” Char_type to use for filling.
  • __v β€” Value to format and insert.

Returns β€” Iterator after writing.

πŸ’€ do_put (the const void * one)

template<typename _CharT , typename _OutIter >
_OutIter std::num_put< _CharT, _OutIter >::do_put (iter_type __s, ios_base & __io, char_type __fill, const void * __v) const [protected],  [virtual]

Numeric formatting. These functions do the work of formatting numeric values and inserting them into a stream. This function is a hook for derived classes to change the value returned.

Parameters

  • __s β€” Stream to write to.
  • __io β€” Source of locale and flags.
  • __fill β€” Char_type to use for filling.
  • __v β€” Value to format and insert.

Returns β€” Iterator after writing.

References β€” std::ios_base::basefield, std::ios_base::flags(), std::ios_base::hex, std::ios_base::showbase, and std::ios_base::uppercase.

πŸ’€ do_put (the double one)

template<typename _CharT , typename _OutIter >
_OutIter std::num_put< _CharT, _OutIter >::do_put (iter_type __s, ios_base & __io, char_type __fill, double __v) const [protected],  [virtual]

Numeric formatting. These functions do the work of formatting numeric values and inserting them into a stream. This function is a hook for derived classes to change the value returned.

Parameters

  • __s β€” Stream to write to.
  • __io β€” Source of locale and flags.
  • __fill β€” Char_type to use for filling.
  • __v β€” Value to format and insert.

Returns β€” Iterator after writing.

πŸ’€ do_put (the long double one)

template<typename _CharT , typename _OutIter >
_OutIter std::num_put< _CharT, _OutIter >::do_put (iter_type __s, ios_base & __io, char_type __fill, long double __v) const [protected],  [virtual]

Numeric formatting. These functions do the work of formatting numeric values and inserting them into a stream. This function is a hook for derived classes to change the value returned.

Parameters

  • __s β€” Stream to write to.
  • __io β€” Source of locale and flags.
  • __fill β€” Char_type to use for filling.
  • __v β€” Value to format and insert.

Returns β€” Iterator after writing.

okay so we're picking up mid-flow β€” here's the tail of the deets for that last overload, then we roll straight into the rest of the put squad πŸ’…

  • __s β€” the stream you're writing into, bestie.
  • __io β€” where the locale and the flags are coming from.
  • __fill β€” the Char_type used for filling (padding vibes).
  • __v β€” the actual value getting formatted and inserted.

Returns β€” an iterator sitting right after everything that got written ✨


🌸 the bool one 🌸

template<typename _CharT , typename _OutIter > iter_type std::num_put<
_CharT, _OutIter >::put (iter_type __s, ios_base & __io, char_type
__fill, bool __v) const [inline]

Numeric formatting, but make it boolean πŸ’– This one formats the boolean v and drops it in the stream, and it does that by calling num_put::do_put().

So here's the tea: if ios_base::boolalpha is set, it writes out ctype<CharT>::truename() or ctype<CharT>::falsename() β€” the actual words, iconic. Otherwise it just formats v as an int. no cap.

  • __s β€” stream to write to.
  • __io β€” source of locale and flags.
  • __fill β€” Char_type to use for filling.
  • __v β€” value to format and insert.

Returns β€” iterator after writing.

References std::num_put< _CharT, _OutIter >::do_put().


πŸ¦‹ the const void * one πŸ¦‹

template<typename _CharT , typename _OutIter > iter_type std::num_put<
_CharT, _OutIter >::put (iter_type __s, ios_base & __io, char_type
__fill, const void * __v) const [inline]

Pointer time 🫢 Numeric formatting β€” it takes the pointer value v and inserts it into the stream, by calling num_put::do_put().

The way this one works: it formats v as an unsigned long with ios_base::hex and ios_base::showbase set. so you get that pretty 0x look, periodt.

  • __s β€” stream to write to.
  • __io β€” source of locale and flags.
  • __fill β€” Char_type to use for filling.
  • __v β€” value to format and insert.

Returns β€” iterator after writing.

References std::num_put< _CharT, _OutIter >::do_put().


🌈 the double one 🌈

template<typename _CharT , typename _OutIter > iter_type std::num_put<
_CharT, _OutIter >::put (iter_type __s, ios_base & __io, char_type
__fill, double __v) const [inline]

Floating point formatting, we love to see it πŸ’– It formats the floating point value v and inserts it into the stream, and yes, it does that by calling num_put::do_put().

The flag settings in io are absolutely running the show here, lowkey:

  • The basic format is affected by the value of io.flags() & ios_base::floatfield. If that's equal to ios_base::fixed, it formats like the printf f specifier. Else if it's equal to ios_base::scientific, it formats like e or E with ios_base::uppercase unset or set respectively. Otherwise, it formats like g or G depending on uppercase. Note that if both fixed and scientific are set, the effect will also be like g or G. wild, i know.
  • The output precision is given by io.precision(). That precision is capped at numeric_limits::digits10 + 2 (different for double and long double). The default precision is 6.
  • If ios_base::showpos is set, '+' is output before positive values. If ios_base::showpoint is set, a decimal point will always be output. always always.
  • The decimal point character used is numpunct::decimal_point(). Thousands separators get inserted according to numpunct::grouping() and numpunct::thousands_sep().
  • If io.width() is non-zero, enough fill characters are inserted to make the result at least that wide. If (io.flags() & ios_base::adjustfield) == ios_base::left, the result is padded at the end. If ios_base::internal, then padding occurs immediately after either a '+' or '-' or after '0x' or '0X'. Otherwise, padding occurs at the beginning.
  • __s β€” stream to write to.
  • __io β€” source of locale and flags.
  • __fill β€” Char_type to use for filling.
  • __v β€” value to format and insert.

Returns β€” iterator after writing.

References std::num_put< _CharT, _OutIter >::do_put().


🌟 the long one 🌟

template<typename _CharT , typename _OutIter > iter_type std::num_put<
_CharT, _OutIter >::put (iter_type __s, ios_base & __io, char_type
__fill, long __v) const [inline]

Integral formatting, let's go πŸŽ€ It formats the integral value v and inserts it into the stream, and it does so by calling num_put::do_put().

The flag settings in io are doing the heavy lifting:

  • The basic format is affected by the value of io.flags() & ios_base::basefield. If that equals ios_base::oct, it formats like the printf o specifier. Else if it equals ios_base::hex, it formats like x or X with ios_base::uppercase unset or set respectively. Otherwise, it formats like d, ld, lld for signed and u, lu, llu for unsigned values. Note that if both oct and hex are set, neither will take effect. neither!! πŸ’€
  • If ios_base::showpos is set, '+' is output before positive values. If ios_base::showbase is set, '0' precedes octal values (except 0) and '0[xX]' precedes hex values.
  • The decimal point character used is numpunct::decimal_point(). Thousands separators are inserted according to numpunct::grouping() and numpunct::thousands_sep().
  • If io.width() is non-zero, enough fill characters are inserted to make the result at least that wide. If (io.flags() & ios_base::adjustfield) == ios_base::left, the result is padded at the end. If ios_base::internal, padding happens immediately after either a '+' or '-' or after '0x' or '0X'. Otherwise, padding occurs at the beginning.
  • __s β€” stream to write to.
  • __io β€” source of locale and flags.
  • __fill β€” Char_type to use for filling.
  • __v β€” value to format and insert.

Returns β€” iterator after writing.

References std::num_put< _CharT, _OutIter >::do_put().


πŸ’œ the long double one πŸ’œ

template<typename _CharT , typename _OutIter > iter_type std::num_put<
_CharT, _OutIter >::put (iter_type __s, ios_base & __io, char_type
__fill, long double __v) const [inline]

Same floating-point energy, bigger float 🧚 It formats the floating point value v and inserts it into the stream, by calling num_put::do_put().

Formatting is affected by the flag settings in io, and here's the full rundown:

  • The basic format depends on io.flags() & ios_base::floatfield. Equal to ios_base::fixed? Then it formats like the printf f specifier. Else if it's ios_base::scientific, it formats like e or E with ios_base::uppercase unset or set respectively. Otherwise it formats like g or G depending on uppercase. Note that if both fixed and scientific are set, the effect will also be like g or G.
  • The output precision comes from io.precision(), and it's capped at numeric_limits::digits10 + 2 (different for double and long double). Default precision is 6.
  • ios_base::showpos set β†’ '+' gets output before positive values. ios_base::showpoint set β†’ a decimal point is always output.
  • Decimal point character = numpunct::decimal_point(). Thousands separators go in per numpunct::grouping() and numpunct::thousands_sep().
  • Non-zero io.width() β†’ enough fill characters get inserted to make the result at least that wide. If (io.flags() & ios_base::adjustfield) == ios_base::left, it pads at the end. If ios_base::internal, padding occurs immediately after a '+' or '-' or after '0x' or '0X'. Otherwise, padding occurs at the beginning.
  • __s β€” stream to write to.
  • __io β€” source of locale and flags.
  • __fill β€” Char_type to use for filling.
  • __v β€” value to format and insert.

Returns β€” iterator after writing.

References std::num_put< _CharT, _OutIter >::do_put().


⭐ the long long one ⭐

template<typename _CharT , typename _OutIter > iter_type std::num_put<
_CharT, _OutIter >::put (iter_type __s, ios_base & __io, char_type
__fill, long long __v) const [inline]

Integral formatting again, and this one's the big signed one πŸ‘‘ Formats the integral value v, inserts it into the stream, calls num_put::do_put() to do it.

Flag settings in io? They're in charge, fr fr:

  • Basic format comes from io.flags() & ios_base::basefield. If it equals ios_base::oct, formats like the printf o specifier. Else if it equals ios_base::hex, formats like x or X with ios_base::uppercase unset or set respectively. Otherwise it formats like d, ld, lld for signed and u, lu, llu for unsigned values. Note that if both oct and hex are set, neither takes effect.
  • ios_base::showpos set β†’ '+' before positive values. ios_base::showbase set β†’ '0' precedes octal values (except 0) and '0[xX]' precedes hex values.
  • The decimal point character is numpunct::decimal_point(), and thousands separators are inserted according to numpunct::grouping() and numpunct::thousands_sep().
  • If io.width() is non-zero, enough fill characters are inserted to make the result at least that wide. (io.flags() & ios_base::adjustfield) == ios_base::left β†’ padded at the end. ios_base::internal β†’ padding occurs immediately after either a '+' or '-' or after '0x' or '0X'. Otherwise β†’ padding at the beginning.
  • __s β€” stream to write to.
  • __io β€” source of locale and flags.
  • __fill β€” Char_type to use for filling.
  • __v β€” value to format and insert.

Returns β€” iterator after writing.

References std::num_put< _CharT, _OutIter >::do_put().


πŸ“ the unsigned long one πŸ“

template<typename _CharT , typename _OutIter > iter_type std::num_put<
_CharT, _OutIter >::put (iter_type __s, ios_base & __io, char_type
__fill, unsigned long __v) const [inline]

Unsigned integral formatting, slay 🌸 Formats the integral value v and inserts it into the stream, doing so by calling num_put::do_put().

The flag settings in io are affecting the formatting, and here's exactly how:

  • The basic format is affected by the value of io.flags() & ios_base::basefield. Equal to ios_base::oct β†’ formats like the printf o specifier. Else if equal to ios_base::hex β†’ formats like x or X with ios_base::uppercase unset or set respectively. Otherwise β†’ formats like d, ld, lld for signed and u, lu, llu for unsigned values. Note that if both oct and hex are set, neither will take effect.
  • ios_base::showpos set β†’ '+' is output before positive values. ios_base::showbase set β†’ '0' precedes octal values (except 0) and '0[xX]' precedes hex values.
  • The decimal point character used is numpunct::decimal_point(). Thousands separators are inserted according to numpunct::grouping() and numpunct::thousands_sep().
  • If io.width() is non-zero, enough fill characters get inserted to make the result at least that wide. If (io.flags() & ios_base::adjustfield) == ios_base::left, the result is padded at the end. If ios_base::internal, padding occurs immediately after either a '+' or '-' or after '0x' or '0X'. Otherwise, padding occurs at the beginning.
  • __s β€” stream to write to.
  • __io β€” source of locale and flags.
  • __fill β€” Char_type to use for filling.
  • __v β€” value to format and insert.

Returns β€” iterator after writing.

References std::num_put< _CharT, _OutIter >::do_put().


πŸŽ€ the unsigned long long one πŸŽ€

template<typename _CharT , typename _OutIter > iter_type std::num_put<
_CharT, _OutIter >::put (iter_type __s, ios_base & __io, char_type
__fill, unsigned long long __v) const [inline]

Integral formatting, the biggest unsigned one, main character energy πŸ‘‘ Formats the integral value v and inserts it into the stream, by calling num_put::do_put().

Formatting is affected by the flag settings in io.

okay so the basic format is totally affected by the value of io.flags() & ios_base::basefield. If that equals ios_base::oct, it formats like the printf o specifier. Else if it equals ios_base::hex, it formats like x or X with ios_base::uppercase unset or set respectively. Otherwise, it formats like d, ld, lld for signed and u, lu, llu for unsigned values. Note that if both oct and hex are set, neither will take effect. πŸ’…

If ios_base::showpos is set, a '+' is output before positive values. If ios_base::showbase is set, '0' precedes octal values (except 0) and '0[xX]' precedes hex values. ✨

The decimal point character used is numpunct::decimal_point(). Thousands separators are inserted according to numpunct::grouping() and numpunct::thousands_sep(). πŸŽ€

If io.width() is non-zero, enough fill characters are inserted to make the result at least that wide. If (io.flags() & ios_base::adjustfield) == ios_base::left, the result is padded at the end. If ios_base::internal, then padding occurs immediately after either a '+' or '-' or after '0x' or '0X'. Otherwise, padding occurs at the beginning. πŸ¦‹

πŸ“‹ Parameters

  • __s β€” Stream to write to. πŸ’–
  • __io β€” Source of locale and flags. 🌸
  • __fill β€” Char_type to use for filling. πŸŽ€
  • __v β€” Value to format and insert. ✨

πŸ” Returns

  • Iterator after writing. 🫢

πŸ”— References

  • std::num_put< _CharT, _OutIter >::do_put(). πŸ‘‘

πŸ’Ύ Member Data Documentation

  • template<typename _CharT , typename _OutIter > locale::id std::num_put< _CharT, _OutIter >::id [static] β€” Numpunct facet id. 🌈

✍️ Author

Generated automatically by Doxygen for libstdc++ from the source code. πŸ€–


and that’s the whole vibe, bestie! this iconic page is from libstdc++ (Doxygen-generated, source code realness) for std::num_put< _CharT, _OutIter > in section 3cxx β€” go format those numbers like the main character you are. periodt. πŸ’…βœ¨πŸŽ€

πŸ“¦ where this page comes from