fmt
Loading...
Searching...
No Matches
printf.cppm File Reference
module fmt

printf-style formatting. More...

#include "fmt/macros.hpp"
#include <cerrno>
#include <climits>
#include <limits.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <version>
import fmt:format;
import std;

Classes

class  fmt::BasicPrintfContext< Char >
struct  fmt::detail::IntChecker< IS_SIGNED >
struct  fmt::detail::IntChecker< true >
struct  fmt::detail::PrintfPrecisionHandler
struct  fmt::detail::IsZeroInt
struct  fmt::detail::MakeUnsignedOrBool< T >
struct  fmt::detail::MakeUnsignedOrBool< bool >
class  fmt::detail::ArgConverter< T, Context >
class  fmt::detail::CharConverter< Context >
struct  fmt::detail::GetCstring< Char >
class  fmt::detail::PrintfWidthHandler
class  fmt::detail::PrintfArgFormatter< Char >
struct  fmt::VprintfArgs< Char >

Typedefs

using fmt::PrintfContext = BasicPrintfContext<char>
using fmt::WprintfContext = BasicPrintfContext<wchar_t>
using fmt::PrintfArgs = BasicFormatArgs<PrintfContext>
using fmt::WprintfArgs = BasicFormatArgs<WprintfContext>

Functions

template<bool IS_CONSTEXPR, typename T, typename Ptr = const T*>
constexpr auto fmt::detail::find (Ptr first, Ptr last, T value, Ptr &out) -> bool
template<>
auto fmt::detail::find< false, char > (const char *first, const char *last, char value, const char *&out) -> bool
template<typename T, typename Context, typename Char>
auto fmt::detail::convertArg (BasicFormatArg< Context > &arg, Char type) -> void
template<typename Char>
auto fmt::detail::makeArgFormatter (BasicAppender< Char > iter, FormatSpecs &s) -> ArgFormatter< Char >
template<typename Char>
auto fmt::detail::parseFlags (FormatSpecs &specs, const Char *&it, const Char *end) -> void
template<typename Char, typename GetArg>
auto fmt::detail::parseHeader (const Char *&it, const Char *end, FormatSpecs &specs, GetArg get_arg) -> int
auto fmt::detail::parsePrintfPresentationType (char c, Type t, bool &upper) -> PresentationType
template<typename Char, typename Context>
auto fmt::detail::vprintf (Buffer< Char > &buf, BasicStringView< Char > format, BasicFormatArgs< Context > args) -> void
template<typename Char = char, typename... T>
auto fmt::makePrintfArgs (T &... args) -> decltype(fmt::makeFormatArgs< BasicPrintfContext< Char > >(args...))
template<typename Char>
auto fmt::vsprintf (BasicStringView< Char > fmt, typename VprintfArgs< Char >::type args) -> std::basic_string< Char >
template<typename... T>
auto fmt::sprintf (StringView fmt, const T &... args) -> std::string
template<typename... T>
auto fmt::sprintf (BasicStringView< wchar_t > fmt, const T &... args) -> std::wstring
template<typename Char>
auto fmt::vfprintf (std::FILE *f, BasicStringView< Char > fmt, typename VprintfArgs< Char >::type args) -> int
template<typename... T>
auto fmt::fprintf (std::FILE *f, StringView fmt, const T &... args) -> int
template<typename... T>
auto fmt::fprintf (std::FILE *f, BasicStringView< wchar_t > fmt, const T &... args) -> int
template<typename... T>
auto fmt::printf (StringView fmt, const T &... args) -> int

Detailed Description

printf-style formatting.

Interface partition fmt:printf.

Typedef Documentation

◆ PrintfArgs

using fmt::PrintfArgs = BasicFormatArgs<PrintfContext>
export

A view of printf arguments, for the type-erased functions.

◆ PrintfContext

using fmt::PrintfContext = BasicPrintfContext<char>
export

The printf formatting context for char.

◆ WprintfArgs

using fmt::WprintfArgs = BasicFormatArgs<WprintfContext>
export

A view of wide printf arguments.

◆ WprintfContext

using fmt::WprintfContext = BasicPrintfContext<wchar_t>
export

The printf formatting context for wchar_t.

Function Documentation

◆ fprintf() [1/2]

template<typename... T>
auto fmt::fprintf ( std::FILE * f,
BasicStringView< wchar_t > fmt,
const T &... args ) -> int
export
Deprecated
Wide printf formatting is deprecated.

◆ fprintf() [2/2]

template<typename... T>
auto fmt::fprintf ( std::FILE * f,
StringView fmt,
const T &... args ) -> int
export

Formats args according to printf specifications in fmt and writes the result to the stream f.

Parameters
fthe stream to write to.
fmta printf format string.
argsthe arguments to format.
Returns
the number of characters written, or -1 if the write fails.

Example:

fmt::fprintf(stderr, "Don't %s!", "panic");

◆ makePrintfArgs()

template<typename Char = char, typename... T>
auto fmt::makePrintfArgs ( T &... args) -> decltype(fmt::makeFormatArgs< BasicPrintfContext< Char > >(args...))
export

Bundles args for passing to a type-erased printf function.

Parameters
argsthe arguments to bundle.
Returns
a view of the arguments, which must outlive it.

◆ printf()

template<typename... T>
auto fmt::printf ( StringView fmt,
const T &... args ) -> int
export

Formats args according to printf specifications in fmt and writes the result to stdout.

Parameters
fmta printf format string.
argsthe arguments to format.
Returns
the number of characters written, or a negative value on error.

Example:

fmt::printf("Elapsed time: %.2f seconds", 1.23);

◆ sprintf() [1/2]

template<typename... T>
auto fmt::sprintf ( BasicStringView< wchar_t > fmt,
const T &... args ) -> std::wstring
export
Deprecated
Wide printf formatting is deprecated.

◆ sprintf() [2/2]

template<typename... T>
auto fmt::sprintf ( StringView fmt,
const T &... args ) -> std::string
export

Formats args according to printf specifications in fmt and returns the result as a string.

Supports the usual printf conversions, with the length modifiers such as ld accepted but ignored: the argument type is taken from the argument itself, so a mismatch cannot occur.

Parameters
fmta printf format string.
argsthe arguments to format.
Returns
the formatted string.
Exceptions
fmt::format_errorif the format string is invalid.

Example:

std::string message = fmt::sprintf("The answer is %d", 42);

◆ vfprintf()

template<typename Char>
auto fmt::vfprintf ( std::FILE * f,
BasicStringView< Char > fmt,
typename VprintfArgs< Char >::type args ) -> int
export

Type-erased form of fprintf.

Parameters
fthe stream to write to.
fmta printf format string.
argsthe type-erased arguments.
Returns
the number of characters written, or -1 if the write fails.

◆ vsprintf()

template<typename Char>
auto fmt::vsprintf ( BasicStringView< Char > fmt,
typename VprintfArgs< Char >::type args ) -> std::basic_string< Char >
export

Type-erased form of sprintf.

Parameters
fmta printf format string.
argsthe type-erased arguments.
Returns
the formatted string.