commit
b1ec3d6dc3
30
doc/api.rst
30
doc/api.rst
@ -58,6 +58,36 @@ formatting::
|
|||||||
The format string syntax is described in the documentation of
|
The format string syntax is described in the documentation of
|
||||||
`strftime <http://en.cppreference.com/w/cpp/chrono/c/strftime>`_.
|
`strftime <http://en.cppreference.com/w/cpp/chrono/c/strftime>`_.
|
||||||
|
|
||||||
|
Formatting user-defined types
|
||||||
|
-----------------------------
|
||||||
|
|
||||||
|
A custom ``format_arg`` function may be implemented and used to format any
|
||||||
|
user-defined type. That is how date and time formatting described in the
|
||||||
|
previous section is implemented in :file:`fmt/time.h`. The following example
|
||||||
|
shows how to implement custom formatting for a user-defined structure.
|
||||||
|
|
||||||
|
::
|
||||||
|
|
||||||
|
struct MyStruct { double a, b; };
|
||||||
|
|
||||||
|
void format_arg(fmt::BasicFormatter<char> &f,
|
||||||
|
const char *&format_str, const MyStruct &s) {
|
||||||
|
f.writer().write("[MyStruct: a={:.1f}, b={:.2f}]", s.a, s.b);
|
||||||
|
}
|
||||||
|
|
||||||
|
MyStruct m = { 1, 2 };
|
||||||
|
std::string s = fmt::format("m={}", n);
|
||||||
|
// s == "m=[MyStruct: a=1.0, b=2.00]"
|
||||||
|
|
||||||
|
Note in the example above the ``format_arg`` function ignores the contents of
|
||||||
|
``format_str`` so the type will always be formatted as specified. See
|
||||||
|
``format_arg`` in :file:`fmt/time.h` for an advanced example of how to use
|
||||||
|
the ``format_str`` argument to customize the formatted output.
|
||||||
|
|
||||||
|
This section shows how to define a custom format function for a user-defined
|
||||||
|
type. The next section describes how to get ``fmt`` to use a conventional stream
|
||||||
|
output ``operator<<`` when one is defined for a user-defined type.
|
||||||
|
|
||||||
``std::ostream`` support
|
``std::ostream`` support
|
||||||
------------------------
|
------------------------
|
||||||
|
|
||||||
|
|||||||
13
fmt/format.h
13
fmt/format.h
@ -194,6 +194,17 @@ typedef __int64 intmax_t;
|
|||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef FMT_OVERRIDE
|
||||||
|
# if FMT_USE_OVERRIDE || FMT_HAS_FEATURE(cxx_override) || \
|
||||||
|
(FMT_GCC_VERSION >= 408 && FMT_HAS_GXX_CXX11) || \
|
||||||
|
FMT_MSC_VER >= 1900
|
||||||
|
# define FMT_OVERRIDE override
|
||||||
|
# else
|
||||||
|
# define FMT_OVERRIDE
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
// A macro to disallow the copy constructor and operator= functions
|
// A macro to disallow the copy constructor and operator= functions
|
||||||
// This should be used in the private: declarations for a class
|
// This should be used in the private: declarations for a class
|
||||||
#ifndef FMT_USE_DELETED_FUNCTIONS
|
#ifndef FMT_USE_DELETED_FUNCTIONS
|
||||||
@ -678,7 +689,7 @@ class MemoryBuffer : private Allocator, public Buffer<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void grow(std::size_t size);
|
void grow(std::size_t size) FMT_OVERRIDE;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit MemoryBuffer(const Allocator &alloc = Allocator())
|
explicit MemoryBuffer(const Allocator &alloc = Allocator())
|
||||||
|
|||||||
@ -10,7 +10,7 @@
|
|||||||
#ifndef FMT_POSIX_H_
|
#ifndef FMT_POSIX_H_
|
||||||
#define FMT_POSIX_H_
|
#define FMT_POSIX_H_
|
||||||
|
|
||||||
#ifdef __MINGW32__
|
#if defined(__MINGW32__) || defined(__CYGWIN__)
|
||||||
// Workaround MinGW bug https://sourceforge.net/p/mingw/bugs/2024/.
|
// Workaround MinGW bug https://sourceforge.net/p/mingw/bugs/2024/.
|
||||||
# undef __STRICT_ANSI__
|
# undef __STRICT_ANSI__
|
||||||
#endif
|
#endif
|
||||||
@ -302,7 +302,8 @@ class File {
|
|||||||
// Returns the memory page size.
|
// Returns the memory page size.
|
||||||
long getpagesize();
|
long getpagesize();
|
||||||
|
|
||||||
#if (defined(LC_NUMERIC_MASK) || defined(_MSC_VER)) && !defined(__ANDROID__)
|
#if (defined(LC_NUMERIC_MASK) || defined(_MSC_VER)) && \
|
||||||
|
!defined(__ANDROID__) && !defined(__CYGWIN__)
|
||||||
# define FMT_LOCALE
|
# define FMT_LOCALE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user