mirror of
https://github.com/fmtlib/fmt.git
synced 2025-11-27 12:49:46 +01:00
Improve docs
This commit is contained in:
@@ -813,25 +813,17 @@ FMT_BEGIN_EXPORT
|
||||
enum { inline_buffer_size = 500 };
|
||||
|
||||
/**
|
||||
\rst
|
||||
A dynamically growing memory buffer for trivially copyable/constructible types
|
||||
with the first ``SIZE`` elements stored in the object itself.
|
||||
|
||||
You can use the ``memory_buffer`` type alias for ``char`` instead.
|
||||
|
||||
**Example**::
|
||||
|
||||
auto out = fmt::memory_buffer();
|
||||
fmt::format_to(std::back_inserter(out), "The answer is {}.", 42);
|
||||
|
||||
This will append the following output to the ``out`` object:
|
||||
|
||||
.. code-block:: none
|
||||
|
||||
The answer is 42.
|
||||
|
||||
The output can be converted to an ``std::string`` with ``to_string(out)``.
|
||||
\endrst
|
||||
* A dynamically growing memory buffer for trivially copyable/constructible
|
||||
* types with the first `SIZE` elements stored in the object itself. Most
|
||||
* commonly used via the `memory_buffer` alias for `char`.
|
||||
*
|
||||
* **Example**::
|
||||
*
|
||||
* auto out = fmt::memory_buffer();
|
||||
* fmt::format_to(std::back_inserter(out), "The answer is {}.", 42);
|
||||
*
|
||||
* This will append "The answer is 42." to `out`. The buffer content can be
|
||||
* converted to `std::string` with `to_string(out)`.
|
||||
*/
|
||||
template <typename T, size_t SIZE = inline_buffer_size,
|
||||
typename Allocator = std::allocator<T>>
|
||||
@@ -904,22 +896,14 @@ class basic_memory_buffer : public detail::buffer<T> {
|
||||
}
|
||||
|
||||
public:
|
||||
/**
|
||||
\rst
|
||||
Constructs a :class:`fmt::basic_memory_buffer` object moving the content
|
||||
of the other object to it.
|
||||
\endrst
|
||||
*/
|
||||
/// Constructs a `basic_memory_buffer` object moving the content of the other
|
||||
/// object to it.
|
||||
FMT_CONSTEXPR20 basic_memory_buffer(basic_memory_buffer&& other) noexcept
|
||||
: detail::buffer<T>(grow) {
|
||||
move(other);
|
||||
}
|
||||
|
||||
/**
|
||||
\rst
|
||||
Moves the content of the other ``basic_memory_buffer`` object to this one.
|
||||
\endrst
|
||||
*/
|
||||
/// Moves the content of the other `basic_memory_buffer` object to this one.
|
||||
auto operator=(basic_memory_buffer&& other) noexcept -> basic_memory_buffer& {
|
||||
FMT_ASSERT(this != &other, "");
|
||||
deallocate();
|
||||
@@ -930,13 +914,11 @@ class basic_memory_buffer : public detail::buffer<T> {
|
||||
// Returns a copy of the allocator associated with this buffer.
|
||||
auto get_allocator() const -> Allocator { return alloc_; }
|
||||
|
||||
/**
|
||||
Resizes the buffer to contain *count* elements. If T is a POD type new
|
||||
elements may not be initialized.
|
||||
*/
|
||||
/// Resizes the buffer to contain *count* elements. If T is a POD type new
|
||||
/// elements may not be initialized.
|
||||
FMT_CONSTEXPR20 void resize(size_t count) { this->try_resize(count); }
|
||||
|
||||
/** Increases the buffer capacity to *new_capacity*. */
|
||||
/// Increases the buffer capacity to *new_capacity*.
|
||||
void reserve(size_t new_capacity) { this->try_reserve(new_capacity); }
|
||||
|
||||
using detail::buffer<T>::append;
|
||||
@@ -965,7 +947,7 @@ FMT_BEGIN_EXPORT
|
||||
# pragma clang diagnostic ignored "-Wweak-vtables"
|
||||
#endif
|
||||
|
||||
/** An error reported from a formatting function. */
|
||||
/// An error reported from a formatting function.
|
||||
class FMT_SO_VISIBILITY("default") format_error : public std::runtime_error {
|
||||
public:
|
||||
using std::runtime_error::runtime_error;
|
||||
@@ -1828,14 +1810,12 @@ inline auto find_escape(const char* begin, const char* end)
|
||||
}()
|
||||
|
||||
/**
|
||||
\rst
|
||||
Constructs a compile-time format string from a string literal *s*.
|
||||
|
||||
**Example**::
|
||||
|
||||
// A compile-time error because 'd' is an invalid specifier for strings.
|
||||
std::string s = fmt::format(FMT_STRING("{:d}"), "foo");
|
||||
\endrst
|
||||
* Constructs a compile-time format string from a string literal *s*.
|
||||
*
|
||||
* **Example**::
|
||||
*
|
||||
* // A compile-time error because 'd' is an invalid specifier for strings.
|
||||
* std::string s = fmt::format(FMT_STRING("{:d}"), "foo");
|
||||
*/
|
||||
#define FMT_STRING(s) FMT_STRING_IMPL(s, fmt::detail::compile_string, )
|
||||
|
||||
@@ -4028,13 +4008,11 @@ template <typename Char, size_t N>
|
||||
struct formatter<Char[N], Char> : formatter<basic_string_view<Char>, Char> {};
|
||||
|
||||
/**
|
||||
\rst
|
||||
Converts ``p`` to ``const void*`` for pointer formatting.
|
||||
|
||||
**Example**::
|
||||
|
||||
auto s = fmt::format("{}", fmt::ptr(p));
|
||||
\endrst
|
||||
* Converts `p` to `const void*` for pointer formatting.
|
||||
*
|
||||
* **Example**::
|
||||
*
|
||||
* auto s = fmt::format("{}", fmt::ptr(p));
|
||||
*/
|
||||
template <typename T> auto ptr(T p) -> const void* {
|
||||
static_assert(std::is_pointer<T>::value, "");
|
||||
@@ -4042,14 +4020,12 @@ template <typename T> auto ptr(T p) -> const void* {
|
||||
}
|
||||
|
||||
/**
|
||||
\rst
|
||||
Converts ``e`` to the underlying type.
|
||||
|
||||
**Example**::
|
||||
|
||||
enum class color { red, green, blue };
|
||||
auto s = fmt::format("{}", fmt::underlying(color::red));
|
||||
\endrst
|
||||
* Converts `e` to the underlying type.
|
||||
*
|
||||
* **Example**::
|
||||
*
|
||||
* enum class color { red, green, blue };
|
||||
* auto s = fmt::format("{}", fmt::underlying(color::red));
|
||||
*/
|
||||
template <typename Enum>
|
||||
constexpr auto underlying(Enum e) noexcept -> underlying_t<Enum> {
|
||||
@@ -4199,15 +4175,11 @@ template <typename T, typename Char = char> struct nested_formatter {
|
||||
};
|
||||
|
||||
/**
|
||||
\rst
|
||||
Converts *value* to ``std::string`` using the default format for type *T*.
|
||||
|
||||
**Example**::
|
||||
|
||||
#include <fmt/format.h>
|
||||
|
||||
std::string answer = fmt::to_string(42);
|
||||
\endrst
|
||||
* Converts *value* to ``std::string`` using the default format for type *T*.
|
||||
*
|
||||
* **Example**::
|
||||
*
|
||||
* std::string answer = fmt::to_string(42);
|
||||
*/
|
||||
template <typename T, FMT_ENABLE_IF(!std::is_integral<T>::value &&
|
||||
!detail::has_format_as<T>::value)>
|
||||
@@ -4381,15 +4353,13 @@ constexpr auto operator""_a(const char* s, size_t) -> detail::udl_arg<char> {
|
||||
FMT_API auto vformat(string_view fmt, format_args args) -> std::string;
|
||||
|
||||
/**
|
||||
\rst
|
||||
Formats ``args`` according to specifications in ``fmt`` and returns the result
|
||||
as a string.
|
||||
|
||||
**Example**::
|
||||
|
||||
#include <fmt/core.h>
|
||||
std::string message = fmt::format("The answer is {}.", 42);
|
||||
\endrst
|
||||
* Formats `args` according to specifications in `fmt` and returns the result
|
||||
* as a string.
|
||||
*
|
||||
* **Example**::
|
||||
*
|
||||
* #include <fmt/core.h>
|
||||
* std::string message = fmt::format("The answer is {}.", 42);
|
||||
*/
|
||||
template <typename... T>
|
||||
FMT_NODISCARD FMT_INLINE auto format(format_string<T...> fmt, T&&... args)
|
||||
|
||||
Reference in New Issue
Block a user