Ch11.3.1: Manipulators Reference

This page is a complete reference of every manipulator provided by fast_io. Manipulators live in the namespace ::fast_io::manipulators, which is aliased as ::fast_io::mnp for convenience. They are passed directly to print, println, or scan to control how values are formatted or parsed — no format strings, no implicit conversions, no surprises.

Each section below groups the manipulators by purpose. The tables list the manipulator signature, a short description, and a small usage example using the ::fast_io::mnp:: prefix.

1. Integer Base Manipulators

Control the numeric base used when printing or scanning integers. The base<N> family accepts any base from 2 to 36. Shorthand manipulators are provided for the most common bases: decimal (10), octal (8), binary (2), and hexadecimal (16). The upper variants emit uppercase digits A–F instead of a–f.

Manipulator Description Example
::fast_io::mnp::base<N>(t) Print or scan t in base N (2 ≤ N ≤ 36) with lowercase digits. ::fast_io::mnp::base<36>(value)
::fast_io::mnp::baseupper<N>(t) Like base<N>, but uses uppercase letters A–Z for digit values ≥ 10. ::fast_io::mnp::baseupper<16>(value)
::fast_io::mnp::hex(t) Print or scan t in lowercase hexadecimal (base 16). ::fast_io::mnp::hex(0xDEAD)
::fast_io::mnp::hexupper(t) Print or scan t in uppercase hexadecimal (base 16, digits A–F). ::fast_io::mnp::hexupper(0xBEEF)
::fast_io::mnp::hex0x(t) Like hex, but prefixes the output with 0x. ::fast_io::mnp::hex0x(42)0x2a
::fast_io::mnp::hex0xupper(t) Like hexupper, but prefixes the output with 0x. ::fast_io::mnp::hex0xupper(42)0x2A
::fast_io::mnp::dec(t) Print or scan t in decimal (base 10). This is the default for integers. ::fast_io::mnp::dec(1234)
::fast_io::mnp::oct(t) Print or scan t in octal (base 8). ::fast_io::mnp::oct(0777)
::fast_io::mnp::bin(t) Print or scan t in binary (base 2). ::fast_io::mnp::bin(0b1010)
::fast_io::mnp::uhexfull(t) Print t as a zero-padded, full-width lowercase hexadecimal value (all nibbles shown). ::fast_io::mnp::uhexfull(std::uint32_t{0xFF})000000ff
::fast_io::mnp::uhexupperfull(t) Like uhexfull, but uses uppercase hex digits A–F. ::fast_io::mnp::uhexupperfull(std::uint32_t{0xFF})000000FF

2. Pointer / Address Manipulators

Format pointers, addresses, and callable references in a platform-appropriate hexadecimal representation. Each manipulator targets a specific kind of address so the output is unambiguous.

Manipulator Description Example
::fast_io::mnp::addrvw(t) Print a generic address (pointer, handle, etc.) in hexadecimal with full width and 0x prefix. ::fast_io::mnp::addrvw(ptr)
::fast_io::mnp::pointervw(t) Print an ordinary object pointer in hexadecimal address form. ::fast_io::mnp::pointervw(&obj)
::fast_io::mnp::itervw(t) Print an iterator's underlying address in hexadecimal. ::fast_io::mnp::itervw(vec.begin())
::fast_io::mnp::funcvw(t) Print a function pointer in hexadecimal address form. ::fast_io::mnp::funcvw(&main)
::fast_io::mnp::fieldptrvw(t) Print a pointer-to-data-member in hexadecimal form. ::fast_io::mnp::fieldptrvw(&MyStruct::field)
::fast_io::mnp::methodvw(t) Print a pointer-to-member-function in hexadecimal form. ::fast_io::mnp::methodvw(&MyClass::doWork)
::fast_io::mnp::handlevw(t) Print an OS handle or file descriptor value in hexadecimal form. ::fast_io::mnp::handlevw(posix_file.fd())

3. Boolean Manipulators

Control how bool values are printed. By default, booleans print as 1 or 0. The boolalpha manipulators switch to textual representation.

Manipulator Description Example
::fast_io::mnp::boolalpha(b) Print b as "true" or "false" (lowercase). ::fast_io::mnp::boolalpha(flag)true
::fast_io::mnp::boolalpha<true>(b) Print b as "TRUE" or "FALSE" (uppercase). ::fast_io::mnp::boolalpha<true>(flag)TRUE

4. Floating-Point Manipulators

Choose the notation used when printing floating-point values. An optional second argument n controls the precision (number of digits after the radix point). The comma_ variants insert locale-style thousand separators into the integer part of the output.

Manipulator Description Example
::fast_io::mnp::hexfloat(t)
::fast_io::mnp::hexfloat(t, n)
Print t in hexadecimal floating-point notation (e.g. 0x1.921fb6p+2). ::fast_io::mnp::hexfloat(3.14)
::fast_io::mnp::decimal(t)
::fast_io::mnp::decimal(t, n)
Print t in plain decimal floating-point notation with n fractional digits. ::fast_io::mnp::decimal(3.14, 4)3.1400
::fast_io::mnp::general(t)
::fast_io::mnp::general(t, n)
Print t using the shorter of decimal or scientific, with up to n significant digits. ::fast_io::mnp::general(123456.0, 3)
::fast_io::mnp::fixed(t)
::fast_io::mnp::fixed(t, n)
Print t in fixed-point notation with n digits after the decimal point. ::fast_io::mnp::fixed(3.14, 2)3.14
::fast_io::mnp::scientific(t)
::fast_io::mnp::scientific(t, n)
Print t in scientific (exponential) notation with n fractional digits. ::fast_io::mnp::scientific(3.14, 2)3.14e+00
::fast_io::mnp::comma_hexfloat(t)
::fast_io::mnp::comma_hexfloat(t, n)
Like hexfloat, with thousand separators in the integer part. ::fast_io::mnp::comma_hexfloat(4096.0)
::fast_io::mnp::comma_decimal(t)
::fast_io::mnp::comma_decimal(t, n)
Like decimal, with thousand separators. ::fast_io::mnp::comma_decimal(1234567.89, 2)
::fast_io::mnp::comma_general(t)
::fast_io::mnp::comma_general(t, n)
Like general, with thousand separators. ::fast_io::mnp::comma_general(9876543.21)
::fast_io::mnp::comma_fixed(t)
::fast_io::mnp::comma_fixed(t, n)
Like fixed, with thousand separators. ::fast_io::mnp::comma_fixed(12345.678, 2)
::fast_io::mnp::comma_scientific(t)
::fast_io::mnp::comma_scientific(t, n)
Like scientific, with thousand separators. ::fast_io::mnp::comma_scientific(1234567.89, 2)

5. Width / Alignment Manipulators

Pad the output of t to a minimum field width of n columns. An optional third argument ch sets the fill character (default is a space). These mirror the alignment options familiar from <iomanip> but are resolved entirely at compile time where possible.

Manipulator Description Example
::fast_io::mnp::left(t, n) Left-align t in a field of width n, padded with spaces. ::fast_io::mnp::left("hi", 10)"hi        "
::fast_io::mnp::left(t, n, ch) Left-align t in a field of width n, padded with ch. ::fast_io::mnp::left("hi", 10, '.')"hi........"
::fast_io::mnp::right(t, n) Right-align t in a field of width n, padded with spaces. ::fast_io::mnp::right("hi", 10)"        hi"
::fast_io::mnp::right(t, n, ch) Right-align t in a field of width n, padded with ch. ::fast_io::mnp::right("hi", 10, '_')"________hi"
::fast_io::mnp::middle(t, n) Center t in a field of width n, padded with spaces. ::fast_io::mnp::middle("hi", 10)"    hi    "
::fast_io::mnp::middle(t, n, ch) Center t in a field of width n, padded with ch. ::fast_io::mnp::middle("hi", 10, '=')"====hi===="
::fast_io::mnp::internal(t, n) Pad after any sign or base prefix but before the digits, in a field of width n, with spaces. ::fast_io::mnp::internal(-42, 8)"-     42"
::fast_io::mnp::internal(t, n, ch) Like internal, but uses ch as the fill character. ::fast_io::mnp::internal(-42, 8, '0')"-0000042"

6. Conditional Manipulators

Select between two alternative outputs at runtime based on a boolean predicate. When the predicate is true, t1 is printed; otherwise t2 is printed. The single-argument overload omits the else branch (printing nothing when the predicate is false).

Manipulator Description Example
::fast_io::mnp::cond(pred, t1, t2) Print t1 if pred is true; otherwise print t2. ::fast_io::mnp::cond(ok, "pass", "fail")
::fast_io::mnp::cond(pred, t1) Print t1 if pred is true; otherwise print nothing. ::fast_io::mnp::cond(showDetail, extra)

7. Percentage Manipulators

Format the ratio num / deno as a human-readable percentage. percentage_conventional multiplies by 100 and appends %. The base_percentage_conventional<N> variant lets you specify the output base N (default 10) for the percentage digits.

Manipulator Description Example
::fast_io::mnp::percentage_conventional(num, deno) Print num/deno as a conventional base-10 percentage (e.g. 75%). ::fast_io::mnp::percentage_conventional(3, 4)75%
::fast_io::mnp::base_percentage_conventional<N>(num, deno) Print num/deno as a percentage in base N. ::fast_io::mnp::base_percentage_conventional<16>(0xFF, 0x100)

8. Ordinal Manipulator

Append the English ordinal suffix (st, nd, rd, or th) to an integer.

Manipulator Description Example
::fast_io::mnp::ordinal(t) Print integer t with its English ordinal suffix: 1st, 2nd, 3rd, 4th, etc. ::fast_io::mnp::ordinal(42)42nd

9. Range View Manipulator

Print every element of a range, separated by a given delimiter. This replaces the need for manual loops when displaying containers such as std::vector, std::array, or any std::ranges::range.

Manipulator Description Example
::fast_io::mnp::rgvw(r, sep) Print every element of range r, inserting the string sep between consecutive elements. ::fast_io::mnp::rgvw(vec, ",")1,2,3

10. Character / String Manipulators

Low-level helpers for printing individual characters and C-style string pointers without relying on null-termination assumptions.

Manipulator Description Example
::fast_io::mnp::chvw(ch) Print a single character ch. ::fast_io::mnp::chvw('A')
::fast_io::mnp::small_scatter(s) Print a small string literal or compile-time-known string s without a heap allocation. ::fast_io::mnp::small_scatter("hello")
::fast_io::mnp::os_c_str(ch, n) Print n characters from the C string pointer ch, without requiring null termination. ::fast_io::mnp::os_c_str(buf, len)
::fast_io::mnp::os_c_str_null_terminated(ch, n) Print up to n characters from the null-terminated C string ch, stopping at the first '\0'. ::fast_io::mnp::os_c_str_null_terminated(cstr, maxLen)

11. Hex Encoding Manipulators

Encode a contiguous sequence of bytes as a hexadecimal string. These manipulators accept either a pair of iterators [first, last) or an entire contiguous range (such as std::vector<std::byte>).

Manipulator Description Example
::fast_io::mnp::hex_encode(first, last) Encode bytes in [first, last) as a lowercase hex string. ::fast_io::mnp::hex_encode(buf.data(), buf.data() + buf.size())
::fast_io::mnp::hex_encode_upper(first, last) Encode bytes in [first, last) as an uppercase hex string. ::fast_io::mnp::hex_encode_upper(buf.data(), buf.data() + buf.size())
::fast_io::mnp::hex_encode(range) Encode every byte in the contiguous range range as a lowercase hex string. ::fast_io::mnp::hex_encode(digest)
::fast_io::mnp::hex_encode_upper(range) Encode every byte in the contiguous range range as an uppercase hex string. ::fast_io::mnp::hex_encode_upper(digest)

12. Crypto Hash File Manipulators

Adapt a crypto-hash context (e.g. sha256_context, md5_context) so it can be written to as if it were an output stream. The as_file family wraps the context reference and selects the character type of the output stream. Once the hashing is done, use the hex-encoding manipulators above or hash_digest to retrieve the result.

Manipulator Description Example
::fast_io::mnp::as_file(hashctx) Wrap hashctx as a narrow (char) output file for incremental hashing. print(::fast_io::mnp::as_file(ctx), data);
::fast_io::mnp::u8as_file(hashctx) Wrap hashctx as a char8_t output file. print(::fast_io::mnp::u8as_file(ctx), u8"data");
::fast_io::mnp::was_file(hashctx) Wrap hashctx as a wchar_t output file. print(::fast_io::mnp::was_file(ctx), L"data");
::fast_io::mnp::u16as_file(hashctx) Wrap hashctx as a char16_t output file. print(::fast_io::mnp::u16as_file(ctx), u"data");
::fast_io::mnp::u32as_file(hashctx) Wrap hashctx as a char32_t output file. print(::fast_io::mnp::u32as_file(ctx), U"data");

A complete hashing example:


#include <fast_io.h>
#include <fast_io_crypto_hash.h>

using namespace fast_io::io;

int main()
{
    ::fast_io::sha256_context ctx;
    print(::fast_io::mnp::as_file(ctx), "Hello, fast_io!\n");
    ctx.do_final();
    println(::fast_io::mnp::hash_digest(ctx));
}

Summary

Every manipulator in ::fast_io::mnp:: is a lightweight, trivially-copyable wrapper that carries formatting intent through the type system. There are no global formatting flags, no locale-dependent surprises, and no format strings to get wrong. Combined with print / println / scan, they give you full control over input and output formatting — safely and efficiently.