ArgArray -> format_arg_store
This commit is contained in:
parent
fc73e10620
commit
4873685c7e
66
fmt/format.h
66
fmt/format.h
@ -37,6 +37,7 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <type_traits>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
@ -2093,34 +2094,33 @@ inline uint64_t make_type(const T &arg) {
|
|||||||
return MakeValue< BasicFormatter<char> >::type(arg);
|
return MakeValue< BasicFormatter<char> >::type(arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <unsigned N, bool/*IsPacked*/= (N < format_args::MAX_PACKED_ARGS)>
|
template <typename ...Args>
|
||||||
struct ArgArray;
|
class format_arg_store {
|
||||||
|
private:
|
||||||
|
static const size_t NUM_ARGS = sizeof...(Args);
|
||||||
|
static const bool PACKED = NUM_ARGS <= format_args::MAX_PACKED_ARGS;
|
||||||
|
|
||||||
template <unsigned N>
|
typedef typename std::conditional<PACKED, Value, Arg>::type value_type;
|
||||||
struct ArgArray<N, true/*IsPacked*/> {
|
|
||||||
typedef Value Type[N > 0 ? N : 1];
|
|
||||||
|
|
||||||
template <typename Formatter, typename T>
|
// If the arguments are not packed we add one more element to mark the end.
|
||||||
static Value make(const T &value) {
|
std::array<value_type, NUM_ARGS + (PACKED ? 0 : 1)> data_;
|
||||||
#ifdef __clang__
|
|
||||||
Value result = MakeValue<Formatter>(value);
|
template <typename Formatter, typename ...A>
|
||||||
// Workaround a bug in Apple LLVM version 4.2 (clang-425.0.28) of clang:
|
friend format_arg_store<A...> make_format_args(const A & ... args);
|
||||||
// https://github.com/fmtlib/fmt/issues/276
|
|
||||||
(void)result.custom.format;
|
public:
|
||||||
return result;
|
template <typename Formatter>
|
||||||
#else
|
format_arg_store(const Args &... args, Formatter *)
|
||||||
return MakeValue<Formatter>(value);
|
: data_{MakeValue<Formatter>(args)...} {}
|
||||||
#endif
|
|
||||||
}
|
const value_type *data() const { return data_.data(); }
|
||||||
};
|
};
|
||||||
|
|
||||||
template <unsigned N>
|
template <typename Formatter, typename ...Args>
|
||||||
struct ArgArray<N, false/*IsPacked*/> {
|
inline format_arg_store<Args...> make_format_args(const Args & ... args) {
|
||||||
typedef Arg Type[N + 1]; // +1 for the list end Arg::NONE
|
Formatter *f = nullptr;
|
||||||
|
return format_arg_store<Args...>(args..., f);
|
||||||
template <typename Formatter, typename T>
|
}
|
||||||
static Arg make(const T &value) { return MakeArg<Formatter>(value); }
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename Arg, typename... Args>
|
template <typename Arg, typename... Args>
|
||||||
inline uint64_t make_type(const Arg &first, const Args & ... tail) {
|
inline uint64_t make_type(const Arg &first, const Args & ... tail) {
|
||||||
@ -2140,20 +2140,16 @@ inline uint64_t make_type(const Arg &first, const Args & ... tail) {
|
|||||||
# define FMT_VARIADIC_VOID(func, arg_type) \
|
# define FMT_VARIADIC_VOID(func, arg_type) \
|
||||||
template <typename... Args> \
|
template <typename... Args> \
|
||||||
void func(arg_type arg0, const Args & ... args) { \
|
void func(arg_type arg0, const Args & ... args) { \
|
||||||
typedef fmt::internal::ArgArray<sizeof...(Args)> ArgArray; \
|
auto store = fmt::internal::make_format_args< fmt::BasicFormatter<Char> >(args...); \
|
||||||
typename ArgArray::Type array{ \
|
func(arg0, fmt::format_args(fmt::internal::make_type(args...), store.data())); \
|
||||||
ArgArray::template make<fmt::BasicFormatter<Char> >(args)...}; \
|
|
||||||
func(arg0, fmt::format_args(fmt::internal::make_type(args...), array)); \
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Defines a variadic constructor.
|
// Defines a variadic constructor.
|
||||||
# define FMT_VARIADIC_CTOR(ctor, func, arg0_type, arg1_type) \
|
# define FMT_VARIADIC_CTOR(ctor, func, arg0_type, arg1_type) \
|
||||||
template <typename... Args> \
|
template <typename... Args> \
|
||||||
ctor(arg0_type arg0, arg1_type arg1, const Args & ... args) { \
|
ctor(arg0_type arg0, arg1_type arg1, const Args & ... args) { \
|
||||||
typedef fmt::internal::ArgArray<sizeof...(Args)> ArgArray; \
|
auto store = internal::make_format_args< fmt::BasicFormatter<Char> >(args...); \
|
||||||
typename ArgArray::Type array{ \
|
func(arg0, arg1, fmt::format_args(fmt::internal::make_type(args...), store.data())); \
|
||||||
ArgArray::template make<fmt::BasicFormatter<Char> >(args)...}; \
|
|
||||||
func(arg0, arg1, fmt::format_args(fmt::internal::make_type(args...), array)); \
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generates a comma-separated list with results of applying f to pairs
|
// Generates a comma-separated list with results of applying f to pairs
|
||||||
@ -3290,11 +3286,9 @@ void arg(WStringRef, const internal::NamedArg<Char>&) FMT_DELETED_OR_UNDEFINED;
|
|||||||
template <typename... Args> \
|
template <typename... Args> \
|
||||||
ReturnType func(FMT_FOR_EACH(FMT_ADD_ARG_NAME, __VA_ARGS__), \
|
ReturnType func(FMT_FOR_EACH(FMT_ADD_ARG_NAME, __VA_ARGS__), \
|
||||||
const Args & ... args) { \
|
const Args & ... args) { \
|
||||||
typedef fmt::internal::ArgArray<sizeof...(Args)> ArgArray; \
|
auto store = fmt::internal::make_format_args< fmt::BasicFormatter<Char> >(args...); \
|
||||||
typename ArgArray::Type array{ \
|
|
||||||
ArgArray::template make<fmt::BasicFormatter<Char> >(args)...}; \
|
|
||||||
call(FMT_FOR_EACH(FMT_GET_ARG_NAME, __VA_ARGS__), \
|
call(FMT_FOR_EACH(FMT_GET_ARG_NAME, __VA_ARGS__), \
|
||||||
fmt::format_args(fmt::internal::make_type(args...), array)); \
|
fmt::format_args(fmt::internal::make_type(args...), store.data())); \
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -121,6 +121,7 @@ endif ()
|
|||||||
check_cxx_compiler_flag(-fno-exceptions HAVE_FNO_EXCEPTIONS_FLAG)
|
check_cxx_compiler_flag(-fno-exceptions HAVE_FNO_EXCEPTIONS_FLAG)
|
||||||
if (HAVE_FNO_EXCEPTIONS_FLAG)
|
if (HAVE_FNO_EXCEPTIONS_FLAG)
|
||||||
add_library(noexception-test ../fmt/format.cc)
|
add_library(noexception-test ../fmt/format.cc)
|
||||||
|
target_compile_options(noexception-test PUBLIC ${CPP11_FLAG})
|
||||||
target_include_directories(noexception-test PRIVATE ${PROJECT_SOURCE_DIR})
|
target_include_directories(noexception-test PRIVATE ${PROJECT_SOURCE_DIR})
|
||||||
target_compile_options(noexception-test PRIVATE -fno-exceptions)
|
target_compile_options(noexception-test PRIVATE -fno-exceptions)
|
||||||
endif ()
|
endif ()
|
||||||
|
Loading…
Reference in New Issue
Block a user