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

Compile-time format string parsing. 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::CompiledString
struct  fmt::IsCompiledString< S >
struct  fmt::CompiledFormatString< Str >
class  fmt::StaticFormatResult< N >

Namespaces

namespace  fmt::literals

Functions

template<detail::FixedString Str>
constexpr auto fmt::literals::operator""_cf () -> CompiledFormatString< Str >
template<typename T, typename... Tail>
constexpr auto fmt::detail::first (const T &value, const Tail &...) -> const T &
template<typename OutputIt, typename S, typename... T>
requires (IsCompiledString<S>::value)
auto fmt::formatToN (OutputIt out, size_t n, const S &fmt, T &&... args) -> FormatToNResult< OutputIt >
template<typename S, typename... T>
requires (IsCompiledString<S>::value)
constexpr auto fmt::formattedSize (const S &fmt, T &&... args) -> size_t
template<typename S, typename... T>
requires (IsCompiledString<S>::value)
auto fmt::print (std::FILE *f, const S &fmt, T &&... args) -> void
template<typename S, typename... T>
requires (IsCompiledString<S>::value)
auto fmt::print (const S &fmt, T &&... args) -> void
template<detail::FixedString Str, auto... Args>
constexpr auto fmt::staticFormat ()

Detailed Description

Compile-time format string parsing.

Interface partition fmt:compile.

Function Documentation

◆ formattedSize()

template<typename S, typename... T>
requires (IsCompiledString<S>::value)
auto fmt::formattedSize ( const S & fmt,
T &&... args ) -> size_t
constexprexport

Returns the number of characters format would produce.

Nothing is written; the arguments are formatted into a counting buffer. Use this to size a buffer before formatting into it.

Parameters
fmta compiled format string, from _cf.
argsthe arguments to format.
Returns
the length of the output, excluding any terminating NUL.

◆ formatToN()

template<typename OutputIt, typename S, typename... T>
requires (IsCompiledString<S>::value)
auto fmt::formatToN ( OutputIt out,
size_t n,
const S & fmt,
T &&... args ) -> FormatToNResult< OutputIt >
export

Formats args with the compiled format string fmt, writing at most n characters to out.

Parameters
outan output iterator to write to.
nthe maximum number of characters to write.
fmta compiled format string, from _cf.
argsthe arguments to format.
Returns
the iterator past the last character written, and the total size the output would have had, which may exceed n.

◆ print() [1/2]

template<typename S, typename... T>
requires (IsCompiledString<S>::value)
auto fmt::print ( const S & fmt,
T &&... args ) -> void
export

Formats args with the compiled format string fmt and prints the result to stdout.

Parameters
fmta compiled format string, from _cf.
argsthe arguments to format.

◆ print() [2/2]

template<typename S, typename... T>
requires (IsCompiledString<S>::value)
auto fmt::print ( std::FILE * f,
const S & fmt,
T &&... args ) -> void
export

Formats args with the compiled format string fmt and prints the result to the stream f.

Parameters
fthe stream to write to.
fmta compiled format string, from _cf.
argsthe arguments to format.

◆ staticFormat()

template<detail::FixedString Str, auto... Args>
auto fmt::staticFormat ( )
constexprexport

Formats Args with the compile-time format string Str, entirely at compile time.

Unlike the other functions here, which compile the format string and format the arguments at run time, this also requires the arguments to be constant expressions. The result is a fixed-size buffer usable in a constant expression.

Template Parameters
Strthe format string.
Argsthe arguments, which must be structural types usable as non-type template parameters.
Returns
a static_format_result holding the formatted, NUL-terminated text.

Example:

constexpr auto result = fmt::staticFormat<"{}", 42>();
const char* s = result.c_str();  // "42"