mirror of
https://github.com/fmtlib/fmt.git
synced 2025-02-09 21:39:58 +00:00
Move make_args_checked to the public API
This commit is contained in:
parent
e2837084ee
commit
c08518a25b
@ -68,6 +68,8 @@ Argument Lists
|
|||||||
|
|
||||||
.. doxygenfunction:: fmt::make_format_args(const Args&...)
|
.. doxygenfunction:: fmt::make_format_args(const Args&...)
|
||||||
|
|
||||||
|
.. doxygenfunction:: fmt::make_args_checked(const S&, const remove_reference_t<Args>&...)
|
||||||
|
|
||||||
.. doxygenclass:: fmt::format_arg_store
|
.. doxygenclass:: fmt::format_arg_store
|
||||||
:members:
|
:members:
|
||||||
|
|
||||||
|
@ -74,8 +74,8 @@ def build_docs(sphinx_executable='sphinx-build', version='dev', **kwargs):
|
|||||||
GENERATE_MAN = NO
|
GENERATE_MAN = NO
|
||||||
GENERATE_RTF = NO
|
GENERATE_RTF = NO
|
||||||
CASE_SENSE_NAMES = NO
|
CASE_SENSE_NAMES = NO
|
||||||
INPUT = {0}/core.h {0}/compile.h {0}/format.h {0}/os.h \
|
INPUT = {0}/color.h {0}/core.h {0}/compile.h {0}/format.h \
|
||||||
{0}/ostream.h {0}/printf.h {0}/time.h
|
{0}/os.h {0}/ostream.h {0}/printf.h {0}/time.h
|
||||||
QUIET = YES
|
QUIET = YES
|
||||||
JAVADOC_AUTOBRIEF = YES
|
JAVADOC_AUTOBRIEF = YES
|
||||||
AUTOLINK_SUPPORT = NO
|
AUTOLINK_SUPPORT = NO
|
||||||
|
@ -515,7 +515,7 @@ template <typename S, typename... Args,
|
|||||||
void print(std::FILE* f, const text_style& ts, const S& format_str,
|
void print(std::FILE* f, const text_style& ts, const S& format_str,
|
||||||
const Args&... args) {
|
const Args&... args) {
|
||||||
vprint(f, ts, format_str,
|
vprint(f, ts, format_str,
|
||||||
detail::make_args_checked<Args...>(format_str, args...));
|
fmt::make_args_checked<Args...>(format_str, args...));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -556,7 +556,7 @@ template <typename S, typename... Args, typename Char = char_t<S>>
|
|||||||
inline std::basic_string<Char> format(const text_style& ts, const S& format_str,
|
inline std::basic_string<Char> format(const text_style& ts, const S& format_str,
|
||||||
const Args&... args) {
|
const Args&... args) {
|
||||||
return vformat(ts, to_string_view(format_str),
|
return vformat(ts, to_string_view(format_str),
|
||||||
detail::make_args_checked<Args...>(format_str, args...));
|
fmt::make_args_checked<Args...>(format_str, args...));
|
||||||
}
|
}
|
||||||
|
|
||||||
FMT_END_NAMESPACE
|
FMT_END_NAMESPACE
|
||||||
|
@ -506,6 +506,18 @@ template <typename S> struct char_t_impl<S, enable_if_t<is_string<S>::value>> {
|
|||||||
using type = typename result::value_type;
|
using type = typename result::value_type;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Reports a compile-time error if S is not a valid format string.
|
||||||
|
template <typename..., typename S, FMT_ENABLE_IF(!is_compile_string<S>::value)>
|
||||||
|
FMT_INLINE void check_format_string(const S&) {
|
||||||
|
#ifdef FMT_ENFORCE_COMPILE_STRING
|
||||||
|
static_assert(is_compile_string<S>::value,
|
||||||
|
"FMT_ENFORCE_COMPILE_STRING requires all format strings to use "
|
||||||
|
"FMT_STRING.");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
template <typename..., typename S, FMT_ENABLE_IF(is_compile_string<S>::value)>
|
||||||
|
void check_format_string(S);
|
||||||
|
|
||||||
struct error_handler {
|
struct error_handler {
|
||||||
constexpr error_handler() = default;
|
constexpr error_handler() = default;
|
||||||
constexpr error_handler(const error_handler&) = default;
|
constexpr error_handler(const error_handler&) = default;
|
||||||
@ -1555,6 +1567,20 @@ inline format_arg_store<Context, Args...> make_format_args(
|
|||||||
return {args...};
|
return {args...};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Same as `make_format_args` but with compile-time format string checks. */
|
||||||
|
template <typename... Args, typename S, typename Char = char_t<S>>
|
||||||
|
inline format_arg_store<buffer_context<Char>, remove_reference_t<Args>...>
|
||||||
|
make_args_checked(const S& format_str,
|
||||||
|
const remove_reference_t<Args>&... args) {
|
||||||
|
static_assert(
|
||||||
|
detail::count<(
|
||||||
|
std::is_base_of<detail::view, remove_reference_t<Args>>::value &&
|
||||||
|
std::is_reference<Args>::value)...>() == 0,
|
||||||
|
"passing views as lvalues is disallowed");
|
||||||
|
detail::check_format_string<Args...>(format_str);
|
||||||
|
return {args...};
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\rst
|
\rst
|
||||||
Returns a named argument to be used in a formatting function. It should only
|
Returns a named argument to be used in a formatting function. It should only
|
||||||
@ -1870,29 +1896,6 @@ struct wformat_args : basic_format_args<wformat_context> {
|
|||||||
|
|
||||||
namespace detail {
|
namespace detail {
|
||||||
|
|
||||||
// Reports a compile-time error if S is not a valid format string.
|
|
||||||
template <typename..., typename S, FMT_ENABLE_IF(!is_compile_string<S>::value)>
|
|
||||||
FMT_INLINE void check_format_string(const S&) {
|
|
||||||
#ifdef FMT_ENFORCE_COMPILE_STRING
|
|
||||||
static_assert(is_compile_string<S>::value,
|
|
||||||
"FMT_ENFORCE_COMPILE_STRING requires all format strings to use "
|
|
||||||
"FMT_STRING.");
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
template <typename..., typename S, FMT_ENABLE_IF(is_compile_string<S>::value)>
|
|
||||||
void check_format_string(S);
|
|
||||||
|
|
||||||
template <typename... Args, typename S, typename Char = char_t<S>>
|
|
||||||
inline format_arg_store<buffer_context<Char>, remove_reference_t<Args>...>
|
|
||||||
make_args_checked(const S& format_str,
|
|
||||||
const remove_reference_t<Args>&... args) {
|
|
||||||
static_assert(count<(std::is_base_of<view, remove_reference_t<Args>>::value &&
|
|
||||||
std::is_reference<Args>::value)...>() == 0,
|
|
||||||
"passing views as lvalues is disallowed");
|
|
||||||
check_format_string<Args...>(format_str);
|
|
||||||
return {args...};
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename Char, FMT_ENABLE_IF(!std::is_same<Char, char>::value)>
|
template <typename Char, FMT_ENABLE_IF(!std::is_same<Char, char>::value)>
|
||||||
std::basic_string<Char> vformat(
|
std::basic_string<Char> vformat(
|
||||||
basic_string_view<Char> format_str,
|
basic_string_view<Char> format_str,
|
||||||
@ -1943,7 +1946,7 @@ template <typename OutputIt, typename S, typename... Args,
|
|||||||
FMT_ENABLE_IF(detail::is_output_iterator<OutputIt>::value&&
|
FMT_ENABLE_IF(detail::is_output_iterator<OutputIt>::value&&
|
||||||
detail::is_string<S>::value)>
|
detail::is_string<S>::value)>
|
||||||
inline OutputIt format_to(OutputIt out, const S& format_str, Args&&... args) {
|
inline OutputIt format_to(OutputIt out, const S& format_str, Args&&... args) {
|
||||||
const auto& vargs = detail::make_args_checked<Args...>(format_str, args...);
|
const auto& vargs = fmt::make_args_checked<Args...>(format_str, args...);
|
||||||
return vformat_to(out, to_string_view(format_str), vargs);
|
return vformat_to(out, to_string_view(format_str), vargs);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1968,7 +1971,7 @@ FMT_INLINE std::basic_string<Char> vformat(
|
|||||||
// std::basic_string<char_t<S>> to reduce the symbol size.
|
// std::basic_string<char_t<S>> to reduce the symbol size.
|
||||||
template <typename S, typename... Args, typename Char = char_t<S>>
|
template <typename S, typename... Args, typename Char = char_t<S>>
|
||||||
FMT_INLINE std::basic_string<Char> format(const S& format_str, Args&&... args) {
|
FMT_INLINE std::basic_string<Char> format(const S& format_str, Args&&... args) {
|
||||||
const auto& vargs = detail::make_args_checked<Args...>(format_str, args...);
|
const auto& vargs = fmt::make_args_checked<Args...>(format_str, args...);
|
||||||
return detail::vformat(to_string_view(format_str), vargs);
|
return detail::vformat(to_string_view(format_str), vargs);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1988,7 +1991,7 @@ FMT_API void vprint(std::FILE*, string_view, format_args);
|
|||||||
*/
|
*/
|
||||||
template <typename S, typename... Args, typename Char = char_t<S>>
|
template <typename S, typename... Args, typename Char = char_t<S>>
|
||||||
inline void print(std::FILE* f, const S& format_str, Args&&... args) {
|
inline void print(std::FILE* f, const S& format_str, Args&&... args) {
|
||||||
const auto& vargs = detail::make_args_checked<Args...>(format_str, args...);
|
const auto& vargs = fmt::make_args_checked<Args...>(format_str, args...);
|
||||||
return detail::is_unicode<Char>()
|
return detail::is_unicode<Char>()
|
||||||
? vprint(f, to_string_view(format_str), vargs)
|
? vprint(f, to_string_view(format_str), vargs)
|
||||||
: detail::vprint_mojibake(f, to_string_view(format_str), vargs);
|
: detail::vprint_mojibake(f, to_string_view(format_str), vargs);
|
||||||
@ -2007,7 +2010,7 @@ inline void print(std::FILE* f, const S& format_str, Args&&... args) {
|
|||||||
*/
|
*/
|
||||||
template <typename S, typename... Args, typename Char = char_t<S>>
|
template <typename S, typename... Args, typename Char = char_t<S>>
|
||||||
inline void print(const S& format_str, Args&&... args) {
|
inline void print(const S& format_str, Args&&... args) {
|
||||||
const auto& vargs = detail::make_args_checked<Args...>(format_str, args...);
|
const auto& vargs = fmt::make_args_checked<Args...>(format_str, args...);
|
||||||
return detail::is_unicode<Char>()
|
return detail::is_unicode<Char>()
|
||||||
? vprint(to_string_view(format_str), vargs)
|
? vprint(to_string_view(format_str), vargs)
|
||||||
: detail::vprint_mojibake(stdout, to_string_view(format_str),
|
: detail::vprint_mojibake(stdout, to_string_view(format_str),
|
||||||
|
@ -3503,7 +3503,7 @@ template <typename S, typename... Args, size_t SIZE = inline_buffer_size,
|
|||||||
typename Char = enable_if_t<detail::is_string<S>::value, char_t<S>>>
|
typename Char = enable_if_t<detail::is_string<S>::value, char_t<S>>>
|
||||||
inline typename buffer_context<Char>::iterator format_to(
|
inline typename buffer_context<Char>::iterator format_to(
|
||||||
basic_memory_buffer<Char, SIZE>& buf, const S& format_str, Args&&... args) {
|
basic_memory_buffer<Char, SIZE>& buf, const S& format_str, Args&&... args) {
|
||||||
const auto& vargs = detail::make_args_checked<Args...>(format_str, args...);
|
const auto& vargs = fmt::make_args_checked<Args...>(format_str, args...);
|
||||||
return detail::vformat_to(buf, to_string_view(format_str), vargs);
|
return detail::vformat_to(buf, to_string_view(format_str), vargs);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3556,7 +3556,7 @@ template <typename OutputIt, typename S, typename... Args,
|
|||||||
inline format_to_n_result<OutputIt> format_to_n(OutputIt out, size_t n,
|
inline format_to_n_result<OutputIt> format_to_n(OutputIt out, size_t n,
|
||||||
const S& format_str,
|
const S& format_str,
|
||||||
const Args&... args) {
|
const Args&... args) {
|
||||||
const auto& vargs = detail::make_args_checked<Args...>(format_str, args...);
|
const auto& vargs = fmt::make_args_checked<Args...>(format_str, args...);
|
||||||
return vformat_to_n(out, n, to_string_view(format_str), vargs);
|
return vformat_to_n(out, n, to_string_view(format_str), vargs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ inline std::basic_string<Char> format(const std::locale& loc,
|
|||||||
const S& format_str, Args&&... args) {
|
const S& format_str, Args&&... args) {
|
||||||
return detail::vformat(
|
return detail::vformat(
|
||||||
loc, to_string_view(format_str),
|
loc, to_string_view(format_str),
|
||||||
detail::make_args_checked<Args...>(format_str, args...));
|
fmt::make_args_checked<Args...>(format_str, args...));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename S, typename OutputIt, typename... Args,
|
template <typename S, typename OutputIt, typename... Args,
|
||||||
@ -69,7 +69,7 @@ template <typename OutputIt, typename S, typename... Args,
|
|||||||
detail::is_string<S>::value)>
|
detail::is_string<S>::value)>
|
||||||
inline OutputIt format_to(OutputIt out, const std::locale& loc,
|
inline OutputIt format_to(OutputIt out, const std::locale& loc,
|
||||||
const S& format_str, Args&&... args) {
|
const S& format_str, Args&&... args) {
|
||||||
const auto& vargs = detail::make_args_checked<Args...>(format_str, args...);
|
const auto& vargs = fmt::make_args_checked<Args...>(format_str, args...);
|
||||||
return vformat_to(out, loc, to_string_view(format_str), vargs);
|
return vformat_to(out, loc, to_string_view(format_str), vargs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -170,7 +170,7 @@ template <typename S, typename... Args,
|
|||||||
typename Char = enable_if_t<detail::is_string<S>::value, char_t<S>>>
|
typename Char = enable_if_t<detail::is_string<S>::value, char_t<S>>>
|
||||||
void print(std::basic_ostream<Char>& os, const S& format_str, Args&&... args) {
|
void print(std::basic_ostream<Char>& os, const S& format_str, Args&&... args) {
|
||||||
vprint(os, to_string_view(format_str),
|
vprint(os, to_string_view(format_str),
|
||||||
detail::make_args_checked<Args...>(format_str, args...));
|
fmt::make_args_checked<Args...>(format_str, args...));
|
||||||
}
|
}
|
||||||
FMT_END_NAMESPACE
|
FMT_END_NAMESPACE
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user