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) consttemplate<typename _ValueT > _OutIter _M_insert_int (_OutIter __s, ios_base &__io, _CharT __fill, _ValueT __v) constiter_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) constvoid _M_group_int (const char *__grouping, size_t __grouping_size, char_type __sep, ios_base &__io, char_type *__new, char_type *__cs, int &__len) consttemplate<typename _ValueT > iter_type _M_insert_float (iter_type, ios_base &__io, char_type __fill, char __mod, _ValueT __v) consttemplate<typename _ValueT > iter_type _M_insert_int (iter_type, ios_base &__io, char_type __fill, _ValueT __v) constvoid _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β theChar_typeused 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_typeto 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_typeto 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 toios_base::fixed, it formats like the printffspecifier. Else if it's equal toios_base::scientific, it formats likeeorEwithios_base::uppercaseunset or set respectively. Otherwise, it formats likegorGdepending on uppercase. Note that if bothfixedandscientificare set, the effect will also be likegorG. wild, i know. - The output precision is given by
io.precision(). That precision is capped atnumeric_limits::digits10 + 2(different fordoubleandlong double). The default precision is6. - If
ios_base::showposis set,'+'is output before positive values. Ifios_base::showpointis set, a decimal point will always be output. always always. - The decimal point character used is
numpunct::decimal_point(). Thousands separators get inserted according tonumpunct::grouping()andnumpunct::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. Ifios_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_typeto 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 equalsios_base::oct, it formats like the printfospecifier. Else if it equalsios_base::hex, it formats likexorXwithios_base::uppercaseunset or set respectively. Otherwise, it formats liked,ld,lldfor signed andu,lu,llufor unsigned values. Note that if bothoctandhexare set, neither will take effect. neither!! π - If
ios_base::showposis set,'+'is output before positive values. Ifios_base::showbaseis set,'0'precedes octal values (except0) and'0[xX]'precedes hex values. - The decimal point character used is
numpunct::decimal_point(). Thousands separators are inserted according tonumpunct::grouping()andnumpunct::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. Ifios_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_typeto 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 toios_base::fixed? Then it formats like the printffspecifier. Else if it'sios_base::scientific, it formats likeeorEwithios_base::uppercaseunset or set respectively. Otherwise it formats likegorGdepending on uppercase. Note that if bothfixedandscientificare set, the effect will also be likegorG. - The output precision comes from
io.precision(), and it's capped atnumeric_limits::digits10 + 2(different fordoubleandlong double). Default precision is6. ios_base::showposset β'+'gets output before positive values.ios_base::showpointset β a decimal point is always output.- Decimal point character =
numpunct::decimal_point(). Thousands separators go in pernumpunct::grouping()andnumpunct::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. Ifios_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_typeto 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 equalsios_base::oct, formats like the printfospecifier. Else if it equalsios_base::hex, formats likexorXwithios_base::uppercaseunset or set respectively. Otherwise it formats liked,ld,lldfor signed andu,lu,llufor unsigned values. Note that if bothoctandhexare set, neither takes effect. ios_base::showposset β'+'before positive values.ios_base::showbaseset β'0'precedes octal values (except0) and'0[xX]'precedes hex values.- The decimal point character is
numpunct::decimal_point(), and thousands separators are inserted according tonumpunct::grouping()andnumpunct::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_typeto 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 toios_base::octβ formats like the printfospecifier. Else if equal toios_base::hexβ formats likexorXwithios_base::uppercaseunset or set respectively. Otherwise β formats liked,ld,lldfor signed andu,lu,llufor unsigned values. Note that if bothoctandhexare set, neither will take effect. ios_base::showposset β'+'is output before positive values.ios_base::showbaseset β'0'precedes octal values (except0) and'0[xX]'precedes hex values.- The decimal point character used is
numpunct::decimal_point(). Thousands separators are inserted according tonumpunct::grouping()andnumpunct::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. Ifios_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_typeto 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_typeto 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
- ubuntu noble: libstdc++-14-doc 14-20240412-0ubuntu1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms