diff --git a/doc/api.rst b/doc/api.rst index 631049e8..7cfd6b5a 100644 --- a/doc/api.rst +++ b/doc/api.rst @@ -59,7 +59,9 @@ Named arguments Argument lists -------------- -.. doxygenclass:: fmt::basic_arg +.. doxygenfunction:: fmt::make_args(const Args&...) + +.. doxygenclass:: fmt::arg_store :members: .. doxygenclass:: fmt::basic_format_args @@ -67,7 +69,8 @@ Argument lists .. doxygenstruct:: fmt::format_args -.. doxygenfunction:: fmt::make_args(const Args&...) +.. doxygenclass:: fmt::basic_arg + :members: Compatibility ------------- @@ -193,6 +196,7 @@ allocator:: const Args & ... args) { return vformat(alloc, format_str, fmt::make_args(args...)); } + Custom formatting of built-in types ----------------------------------- @@ -237,9 +241,6 @@ custom argument formatter class:: .. doxygenclass:: fmt::ArgVisitor :members: -.. doxygenclass:: fmt::arg_formatter_base - :members: - .. doxygenclass:: fmt::arg_formatter :members: @@ -305,36 +306,3 @@ argument type doesn't match its format specification. .. doxygenfunction:: fprintf(std::ostream&, string_view, const Args&...) .. doxygenfunction:: sprintf(string_view, const Args&...) - -Write API -========= - -The write API provides classes for writing formatted data into character -streams. It is usually faster than the `format API`_ but, as IOStreams, -may result in larger compiled code size. The main writer class is -`~fmt::basic_memory_writer` which stores its output in a memory buffer and -provides direct access to it. It is possible to create custom writers that -store output elsewhere by subclassing `~fmt::BasicWriter`. - -.. doxygenclass:: fmt::BasicWriter - :members: - -.. doxygenclass:: fmt::basic_memory_writer - :members: - -.. doxygenclass:: fmt::BasicArrayWriter - :members: - -.. doxygenclass:: fmt::BasicStringWriter - :members: - -.. doxygenfunction:: bin(int) - -.. doxygenfunction:: oct(int) - -.. doxygenfunction:: hex(int) - -.. doxygenfunction:: hexu(int) - -.. doxygenfunction:: pad(int, unsigned, Char) - diff --git a/include/fmt/core.h b/include/fmt/core.h index 7c16a244..3ddb3b4a 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -950,6 +950,13 @@ inline typename std::enable_if>::type } } +/** + \rst + An array of references to arguments. It can be implicitly converted into + `~fmt::basic_format_args` for passing into type-erased formatting functions + such as `~fmt::vformat`. + \endrst + */ template class arg_store { private: @@ -964,6 +971,8 @@ class arg_store { // If the arguments are not packed, add one more element to mark the end. value_type data_[NUM_ARGS + (IS_PACKED && NUM_ARGS != 0 ? 0 : 1)]; + friend class basic_format_args; + public: static const uint64_t TYPES; @@ -978,8 +987,6 @@ class arg_store { #endif basic_format_args operator*() const { return *this; } - - const value_type *data() const { return data_; } }; template @@ -987,6 +994,13 @@ const uint64_t arg_store::TYPES = IS_PACKED ? internal::get_types() : -static_cast(NUM_ARGS); +/** + \rst + Constructs an `~fmt::arg_store` object that contains references to arguments + and can be implicitly converted to `~fmt::format_args`. `Context` can be + omitted in which case it defaults to `~fmt::context`. + \endrst + */ template inline arg_store make_args(const Args & ... args) { return arg_store(args...); @@ -1050,10 +1064,15 @@ class basic_format_args { public: basic_format_args() : types_(0) {} + /** + \rst + Constructs a `basic_format_args` object from `~fmt::arg_store`. + \endrst + */ template basic_format_args(const arg_store &store) : types_(store.TYPES) { - set_data(store.data()); + set_data(store.data_); } /** Returns the argument at specified index. */ @@ -1065,9 +1084,9 @@ class basic_format_args { unsigned max_size() const { int64_t signed_types = static_cast(types_); - return static_cast(signed_types < 0 - ? -signed_types - : static_cast(internal::max_packed_args)); + return static_cast( + signed_types < 0 ? + -signed_types : static_cast(internal::max_packed_args)); } }; diff --git a/include/fmt/format.h b/include/fmt/format.h index b54edec7..6283780a 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -1399,7 +1399,8 @@ class arg_formatter_base { } void write(const char_type *value) { - auto length = value != FMT_NULL ? std::char_traits::length(value) : 0; + auto length = value != FMT_NULL ? + std::char_traits::length(value) : 0; writer_.write_str(basic_string_view(value, length), specs_); }