mirror of
https://github.com/fmtlib/fmt.git
synced 2025-09-25 14:10:55 +02:00
Update docs
This commit is contained in:
@@ -558,7 +558,7 @@ marked with `FMT_COMPILE` or `_cf` are parsed, checked and converted into
|
||||
efficient formatting code at compile-time. This supports arguments of built-in
|
||||
and string types as well as user-defined types with `format` methods taking
|
||||
the format context type as a template parameter in their `formatter`
|
||||
specializations. For example:
|
||||
specializations. For example ([run](https://www.godbolt.org/z/3c13erEoq)):
|
||||
|
||||
struct point {
|
||||
double x;
|
||||
@@ -586,7 +586,7 @@ and `consteval` functions. Additionally there is an experimental
|
||||
`FMT_STATIC_FORMAT` that allows formatting into a string of the exact
|
||||
required size at compile time. Compile-time formatting works with built-in
|
||||
and user-defined formatters that have `constexpr` `format` methods.
|
||||
Example ([run](https://www.godbolt.org/z/3c13erEoq)):
|
||||
Example:
|
||||
|
||||
template <> struct fmt::formatter<point> {
|
||||
constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); }
|
||||
|
@@ -22,8 +22,6 @@ FMT_EXPORT class compiled_string {};
|
||||
template <typename S>
|
||||
struct is_compiled_string : std::is_base_of<compiled_string, S> {};
|
||||
|
||||
namespace detail {
|
||||
|
||||
/**
|
||||
* Converts a string literal `s` into a format string that will be parsed at
|
||||
* compile time and converted into efficient formatting code. Requires C++17
|
||||
@@ -41,6 +39,28 @@ namespace detail {
|
||||
# define FMT_COMPILE(s) FMT_STRING(s)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Converts a string literal into a format string that will be parsed at
|
||||
* compile time and converted into efficient formatting code. Requires support
|
||||
* for class types in constant template parameters (a C++20 feature).
|
||||
*
|
||||
* **Example**:
|
||||
*
|
||||
* // Converts 42 into std::string using the most efficient method and no
|
||||
* // runtime format string processing.
|
||||
* using namespace fmt::literals;
|
||||
* std::string s = fmt::format("{}"_cf, 42);
|
||||
*/
|
||||
#if FMT_USE_NONTYPE_TEMPLATE_ARGS
|
||||
inline namespace literals {
|
||||
template <detail::fixed_string Str> constexpr auto operator""_cf() {
|
||||
return FMT_COMPILE(Str.data);
|
||||
}
|
||||
} // namespace literals
|
||||
#endif
|
||||
|
||||
namespace detail {
|
||||
|
||||
template <typename T, typename... Tail>
|
||||
constexpr auto first(const T& value, const Tail&...) -> const T& {
|
||||
return value;
|
||||
@@ -559,14 +579,6 @@ template <size_t N> class static_format_result {
|
||||
fmt::formatted_size(FMT_COMPILE(fmt_str), __VA_ARGS__) + 1>( \
|
||||
FMT_COMPILE(fmt_str), __VA_ARGS__)
|
||||
|
||||
#if FMT_USE_NONTYPE_TEMPLATE_ARGS
|
||||
inline namespace literals {
|
||||
template <detail::fixed_string Str> constexpr auto operator""_cf() {
|
||||
return FMT_COMPILE(Str.data);
|
||||
}
|
||||
} // namespace literals
|
||||
#endif
|
||||
|
||||
FMT_END_EXPORT
|
||||
FMT_END_NAMESPACE
|
||||
|
||||
|
Reference in New Issue
Block a user