Merge branch 'master' into ci
This commit is contained in:
commit
194616e8c5
@ -133,7 +133,7 @@ endfunction()
|
|||||||
|
|
||||||
# Define the fmt library, its includes and the needed defines.
|
# Define the fmt library, its includes and the needed defines.
|
||||||
add_headers(FMT_HEADERS core.h format.h format-inl.h locale.h ostream.h printf.h
|
add_headers(FMT_HEADERS core.h format.h format-inl.h locale.h ostream.h printf.h
|
||||||
time.h)
|
time.h ranges.h)
|
||||||
set(FMT_SOURCES src/format.cc)
|
set(FMT_SOURCES src/format.cc)
|
||||||
if (HAVE_OPEN)
|
if (HAVE_OPEN)
|
||||||
add_headers(FMT_HEADERS posix.h)
|
add_headers(FMT_HEADERS posix.h)
|
||||||
|
|||||||
@ -52,6 +52,27 @@
|
|||||||
<source>:12:45: error: expression '<throw-expression>' is not a constant expression
|
<source>:12:45: error: expression '<throw-expression>' is not a constant expression
|
||||||
throw format_error("invalid specifier");
|
throw format_error("invalid specifier");
|
||||||
|
|
||||||
|
* Added `iterator support
|
||||||
|
<http://fmtlib.net/dev/api.html#output-iterator-support>`_:
|
||||||
|
|
||||||
|
.. code:: c++
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <fmt/format.h>
|
||||||
|
|
||||||
|
std::vector<char> out;
|
||||||
|
fmt::format_to(std::back_inserter(out), "{}", 42);
|
||||||
|
|
||||||
|
* Added the `formatted_size
|
||||||
|
<http://fmtlib.net/dev/api.html#output-iterator-support>`_ function for
|
||||||
|
computing output size:
|
||||||
|
|
||||||
|
.. code:: c++
|
||||||
|
|
||||||
|
#include <fmt/format.h>
|
||||||
|
|
||||||
|
auto size = fmt::formatted_size("{}", 12345); // size == 5
|
||||||
|
|
||||||
* Improved compile times by reducing dependencies on standard headers and
|
* Improved compile times by reducing dependencies on standard headers and
|
||||||
providing a lightweight `core API <http://fmtlib.net/dev/api.html#core-api>`_:
|
providing a lightweight `core API <http://fmtlib.net/dev/api.html#core-api>`_:
|
||||||
|
|
||||||
@ -94,6 +115,19 @@
|
|||||||
in the format API and provided ``fmt::string_view`` which implements a subset
|
in the format API and provided ``fmt::string_view`` which implements a subset
|
||||||
of ``std::string_view`` API for pre-C++17 systems.
|
of ``std::string_view`` API for pre-C++17 systems.
|
||||||
|
|
||||||
|
* Added support for ``std::experimental::string_view``
|
||||||
|
(`#607 <https://github.com/fmtlib/fmt/pull/607>`_):
|
||||||
|
|
||||||
|
.. code:: c++
|
||||||
|
|
||||||
|
#include <fmt/core.h>
|
||||||
|
#include <experimental/string_view>
|
||||||
|
|
||||||
|
fmt::print("{}", std::experimental::string_view("foo"));
|
||||||
|
|
||||||
|
Thanks `@virgiliofornazin (Virgilio Alexandre Fornazin)
|
||||||
|
<https://github.com/virgiliofornazin>`_.
|
||||||
|
|
||||||
* Allowed mixing named and automatic arguments:
|
* Allowed mixing named and automatic arguments:
|
||||||
|
|
||||||
.. code:: c++
|
.. code:: c++
|
||||||
|
|||||||
@ -151,6 +151,8 @@ The following user-defined literals are defined in ``fmt/format.h``.
|
|||||||
Utilities
|
Utilities
|
||||||
---------
|
---------
|
||||||
|
|
||||||
|
.. doxygenfunction:: fmt::formatted_size(string_view, const Args&...)
|
||||||
|
|
||||||
.. doxygenfunction:: fmt::to_string(const T&)
|
.. doxygenfunction:: fmt::to_string(const T&)
|
||||||
|
|
||||||
.. doxygenfunction:: fmt::to_wstring(const T&)
|
.. doxygenfunction:: fmt::to_wstring(const T&)
|
||||||
|
|||||||
@ -73,7 +73,8 @@
|
|||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if FMT_HAS_FEATURE(cxx_explicit_conversions)
|
#if FMT_HAS_FEATURE(cxx_explicit_conversions) || \
|
||||||
|
FMT_MSC_VER >= 1800
|
||||||
# define FMT_EXPLICIT explicit
|
# define FMT_EXPLICIT explicit
|
||||||
#else
|
#else
|
||||||
# define FMT_EXPLICIT
|
# define FMT_EXPLICIT
|
||||||
@ -199,13 +200,11 @@ typename std::add_rvalue_reference<T>::type declval() FMT_NOEXCEPT;
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\rst
|
|
||||||
An implementation of ``std::basic_string_view`` for pre-C++17. It provides a
|
An implementation of ``std::basic_string_view`` for pre-C++17. It provides a
|
||||||
subset of the API. ``fmt::basic_string_view`` is used for format strings even
|
subset of the API. ``fmt::basic_string_view`` is used for format strings even
|
||||||
if ``std::string_view`` is available to prevent issues when a library is
|
if ``std::string_view`` is available to prevent issues when a library is
|
||||||
compiled with a different ``-std`` option than the client code (which is not
|
compiled with a different ``-std`` option than the client code (which is not
|
||||||
recommended).
|
recommended).
|
||||||
\endrst
|
|
||||||
*/
|
*/
|
||||||
template <typename Char>
|
template <typename Char>
|
||||||
class basic_string_view {
|
class basic_string_view {
|
||||||
@ -244,11 +243,7 @@ class basic_string_view {
|
|||||||
basic_string_view(const Char *s)
|
basic_string_view(const Char *s)
|
||||||
: data_(s), size_(std::char_traits<Char>::length(s)) {}
|
: data_(s), size_(std::char_traits<Char>::length(s)) {}
|
||||||
|
|
||||||
/**
|
/** Constructs a string reference from a ``std::basic_string`` object. */
|
||||||
\rst
|
|
||||||
Constructs a string reference from a ``std::basic_string`` object.
|
|
||||||
\endrst
|
|
||||||
*/
|
|
||||||
template <typename Alloc>
|
template <typename Alloc>
|
||||||
FMT_CONSTEXPR basic_string_view(
|
FMT_CONSTEXPR basic_string_view(
|
||||||
const std::basic_string<Char, Alloc> &s) FMT_NOEXCEPT
|
const std::basic_string<Char, Alloc> &s) FMT_NOEXCEPT
|
||||||
@ -335,11 +330,7 @@ class basic_buffer {
|
|||||||
capacity_ = capacity;
|
capacity_ = capacity;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** Increases the buffer capacity to hold at least *capacity* elements. */
|
||||||
\rst
|
|
||||||
Increases the buffer capacity to hold at least *capacity* elements.
|
|
||||||
\endrst
|
|
||||||
*/
|
|
||||||
virtual void grow(std::size_t capacity) = 0;
|
virtual void grow(std::size_t capacity) = 0;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -371,11 +362,7 @@ class basic_buffer {
|
|||||||
size_ = new_size;
|
size_ = new_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** Reserves space to store at least *capacity* elements. */
|
||||||
\rst
|
|
||||||
Reserves space to store at least *capacity* elements.
|
|
||||||
\endrst
|
|
||||||
*/
|
|
||||||
void reserve(std::size_t capacity) {
|
void reserve(std::size_t capacity) {
|
||||||
if (capacity > capacity_)
|
if (capacity > capacity_)
|
||||||
grow(capacity);
|
grow(capacity);
|
||||||
@ -910,10 +897,8 @@ class basic_format_context :
|
|||||||
using typename base::iterator;
|
using typename base::iterator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\rst
|
|
||||||
Constructs a ``basic_format_context`` object. References to the arguments are
|
Constructs a ``basic_format_context`` object. References to the arguments are
|
||||||
stored in the object so make sure they have appropriate lifetimes.
|
stored in the object so make sure they have appropriate lifetimes.
|
||||||
\endrst
|
|
||||||
*/
|
*/
|
||||||
basic_format_context(OutputIt out, basic_string_view<char_type> format_str,
|
basic_format_context(OutputIt out, basic_string_view<char_type> format_str,
|
||||||
basic_format_args<basic_format_context> args)
|
basic_format_args<basic_format_context> args)
|
||||||
@ -997,8 +982,17 @@ class format_arg_store {
|
|||||||
|
|
||||||
friend class basic_format_args<Context>;
|
friend class basic_format_args<Context>;
|
||||||
|
|
||||||
|
static FMT_CONSTEXPR uint64_t get_types() {
|
||||||
|
return IS_PACKED ? internal::get_types<Context, Args...>()
|
||||||
|
: -static_cast<int64_t>(NUM_ARGS);
|
||||||
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
#if FMT_USE_CONSTEXPR
|
||||||
|
static constexpr uint64_t TYPES = get_types();
|
||||||
|
#else
|
||||||
static const uint64_t TYPES;
|
static const uint64_t TYPES;
|
||||||
|
#endif
|
||||||
|
|
||||||
#if FMT_GCC_VERSION && FMT_GCC_VERSION <= 405
|
#if FMT_GCC_VERSION && FMT_GCC_VERSION <= 405
|
||||||
// Workaround an array initialization bug in gcc 4.5 and earlier.
|
// Workaround an array initialization bug in gcc 4.5 and earlier.
|
||||||
@ -1011,10 +1005,10 @@ class format_arg_store {
|
|||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#if !FMT_USE_CONSTEXPR
|
||||||
template <typename Context, typename ...Args>
|
template <typename Context, typename ...Args>
|
||||||
const uint64_t format_arg_store<Context, Args...>::TYPES = IS_PACKED ?
|
const uint64_t format_arg_store<Context, Args...>::TYPES = get_types();
|
||||||
internal::get_types<Context, Args...>() :
|
#endif
|
||||||
-static_cast<int64_t>(NUM_ARGS);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\rst
|
\rst
|
||||||
|
|||||||
@ -1395,13 +1395,13 @@ class float_type_checker : private ErrorHandler {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename ErrorHandler>
|
template <typename ErrorHandler, typename CharType>
|
||||||
class char_specs_checker : public ErrorHandler {
|
class char_specs_checker : public ErrorHandler {
|
||||||
private:
|
private:
|
||||||
char type_;
|
CharType type_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
FMT_CONSTEXPR char_specs_checker(char type, ErrorHandler eh)
|
FMT_CONSTEXPR char_specs_checker(CharType type, ErrorHandler eh)
|
||||||
: ErrorHandler(eh), type_(type) {}
|
: ErrorHandler(eh), type_(type) {}
|
||||||
|
|
||||||
FMT_CONSTEXPR void on_int() {
|
FMT_CONSTEXPR void on_int() {
|
||||||
@ -3138,8 +3138,10 @@ struct formatter<
|
|||||||
type_spec, internal::int_type_checker<decltype(eh)>(eh));
|
type_spec, internal::int_type_checker<decltype(eh)>(eh));
|
||||||
break;
|
break;
|
||||||
case internal::char_type:
|
case internal::char_type:
|
||||||
handle_char_specs(specs_, internal::char_specs_checker<decltype(eh)>(
|
handle_char_specs(
|
||||||
static_cast<char>(type_spec), eh));
|
specs_,
|
||||||
|
internal::char_specs_checker<decltype(eh), decltype(type_spec)>(
|
||||||
|
type_spec, eh));
|
||||||
break;
|
break;
|
||||||
case internal::double_type:
|
case internal::double_type:
|
||||||
case internal::long_double_type:
|
case internal::long_double_type:
|
||||||
@ -3419,9 +3421,7 @@ std::string to_string(const T &value) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\rst
|
|
||||||
Converts *value* to ``std::wstring`` using the default format for type *T*.
|
Converts *value* to ``std::wstring`` using the default format for type *T*.
|
||||||
\endrst
|
|
||||||
*/
|
*/
|
||||||
template <typename T>
|
template <typename T>
|
||||||
std::wstring to_wstring(const T &value) {
|
std::wstring to_wstring(const T &value) {
|
||||||
@ -3478,6 +3478,17 @@ inline OutputIt vformat_to(OutputIt out, string_view format_str,
|
|||||||
return vformat_to<arg_formatter<range>>(range(out), format_str, args);
|
return vformat_to<arg_formatter<range>>(range(out), format_str, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
\rst
|
||||||
|
Formats arguments, writes the result to the output iterator ``out`` and returns
|
||||||
|
the iterator past the end of the output range.
|
||||||
|
|
||||||
|
**Example**::
|
||||||
|
|
||||||
|
std::vector<char> out;
|
||||||
|
fmt::format_to(std::back_inserter(out), "{}", 42);
|
||||||
|
\endrst
|
||||||
|
*/
|
||||||
template <typename OutputIt, typename... Args>
|
template <typename OutputIt, typename... Args>
|
||||||
inline OutputIt format_to(OutputIt out, string_view format_str,
|
inline OutputIt format_to(OutputIt out, string_view format_str,
|
||||||
const Args & ... args) {
|
const Args & ... args) {
|
||||||
@ -3552,7 +3563,10 @@ inline typename std::enable_if<internal::is_format_string<String>::value>::type
|
|||||||
return vprint(format_str.data(), make_format_args(args...));
|
return vprint(format_str.data(), make_format_args(args...));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Counts the number of characters in the output of format(format_str, args...).
|
/**
|
||||||
|
Returns the number of characters in the output of
|
||||||
|
``format(format_str, args...)``.
|
||||||
|
*/
|
||||||
template <typename... Args>
|
template <typename... Args>
|
||||||
inline std::size_t formatted_size(string_view format_str,
|
inline std::size_t formatted_size(string_view format_str,
|
||||||
const Args & ... args) {
|
const Args & ... args) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user