mirror of
https://github.com/fmtlib/fmt.git
synced 2024-11-22 18:40:05 +00:00
Fix compilation errors on gcc 4.4
This commit is contained in:
parent
936aba5f90
commit
edd5f1445d
@ -616,7 +616,8 @@ FMT_MAKE_VALUE(pointer_type, std::nullptr_t, const void*)
|
||||
// formatting of "[const] volatile char *" which is printed as bool by
|
||||
// iostreams.
|
||||
template <typename C, typename T>
|
||||
typed_value<C, pointer_type> make_value(const T *) {
|
||||
typename std::enable_if<!std::is_same<T, typename C::char_type>::value>::type
|
||||
make_value(const T *) {
|
||||
static_assert(!sizeof(T), "formatting of non-void pointers is disallowed");
|
||||
}
|
||||
|
||||
@ -1240,12 +1241,12 @@ inline std::string format(string_view format_str, const Args & ... args) {
|
||||
// This should be just
|
||||
// return vformat(format_str, make_format_args(args...));
|
||||
// but gcc has trouble optimizing the latter, so break it down.
|
||||
format_arg_store<format_context, Args...> as(args...);
|
||||
format_arg_store<format_context, Args...> as{args...};
|
||||
return vformat(format_str, as);
|
||||
}
|
||||
template <typename... Args>
|
||||
inline std::wstring format(wstring_view format_str, const Args & ... args) {
|
||||
format_arg_store<wformat_context, Args...> as(args...);
|
||||
format_arg_store<wformat_context, Args...> as{args...};
|
||||
return vformat(format_str, as);
|
||||
}
|
||||
|
||||
@ -1286,7 +1287,7 @@ FMT_API void vprint(wstring_view format_str, wformat_args args);
|
||||
*/
|
||||
template <typename... Args>
|
||||
inline void print(string_view format_str, const Args & ... args) {
|
||||
format_arg_store<format_context, Args...> as(args...);
|
||||
format_arg_store<format_context, Args...> as{args...};
|
||||
vprint(format_str, as);
|
||||
}
|
||||
|
||||
|
@ -140,13 +140,13 @@ inline void vprint(std::basic_ostream<Char> &os,
|
||||
template <typename... Args>
|
||||
inline void print(std::ostream &os, string_view format_str,
|
||||
const Args & ... args) {
|
||||
vprint(os, format_str, make_format_args<format_context>(args...));
|
||||
vprint<char>(os, format_str, make_format_args<format_context>(args...));
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
inline void print(std::wostream &os, wstring_view format_str,
|
||||
const Args & ... args) {
|
||||
vprint(os, format_str, make_format_args<wformat_context>(args...));
|
||||
vprint<wchar_t>(os, format_str, make_format_args<wformat_context>(args...));
|
||||
}
|
||||
FMT_END_NAMESPACE
|
||||
|
||||
|
@ -215,7 +215,9 @@ class basic_printf_context;
|
||||
*/
|
||||
template <typename Range>
|
||||
class printf_arg_formatter:
|
||||
public internal::function<void>, public internal::arg_formatter_base<Range> {
|
||||
public internal::function<
|
||||
typename internal::arg_formatter_base<Range>::iterator>,
|
||||
public internal::arg_formatter_base<Range> {
|
||||
private:
|
||||
typedef typename Range::value_type char_type;
|
||||
typedef decltype(internal::declval<Range>().begin()) iterator;
|
||||
@ -627,7 +629,7 @@ template <typename... Args>
|
||||
inline int fprintf(std::FILE *f, string_view format_str, const Args & ... args) {
|
||||
auto vargs = make_format_args<
|
||||
typename printf_context<internal::buffer>::type>(args...);
|
||||
return vfprintf(f, format_str, vargs);
|
||||
return vfprintf<char>(f, format_str, vargs);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
|
@ -34,18 +34,20 @@ template <typename Char, typename Enable = void>
|
||||
struct formatting_range : formatting_base<Char> {
|
||||
static FMT_CONSTEXPR_DECL const std::size_t range_length_limit =
|
||||
FMT_RANGE_OUTPUT_LENGTH_LIMIT; // output only up to N items from the range.
|
||||
Char prefix = '{';
|
||||
Char delimiter = ',';
|
||||
Char postfix = '}';
|
||||
Char prefix;
|
||||
Char delimiter;
|
||||
Char postfix;
|
||||
formatting_range() : prefix('{'), delimiter(','), postfix('}') {}
|
||||
static FMT_CONSTEXPR_DECL const bool add_delimiter_spaces = true;
|
||||
static FMT_CONSTEXPR_DECL const bool add_prepostfix_space = false;
|
||||
};
|
||||
|
||||
template <typename Char, typename Enable = void>
|
||||
struct formatting_tuple : formatting_base<Char> {
|
||||
Char prefix = '(';
|
||||
Char delimiter = ',';
|
||||
Char postfix = ')';
|
||||
Char prefix;
|
||||
Char delimiter;
|
||||
Char postfix;
|
||||
formatting_tuple() : prefix('('), delimiter(','), postfix(')') {}
|
||||
static FMT_CONSTEXPR_DECL const bool add_delimiter_spaces = true;
|
||||
static FMT_CONSTEXPR_DECL const bool add_prepostfix_space = false;
|
||||
};
|
||||
@ -54,9 +56,8 @@ namespace internal {
|
||||
|
||||
template <typename RangeT, typename OutputIterator>
|
||||
void copy(const RangeT &range, OutputIterator out) {
|
||||
for (const auto &it : range) {
|
||||
*out++ = it;
|
||||
}
|
||||
for (auto it = range.begin(), end = range.end(); it != end; ++it)
|
||||
*out++ = *it;
|
||||
}
|
||||
|
||||
template <typename OutputIterator>
|
||||
@ -83,7 +84,7 @@ class is_like_std_string {
|
||||
|
||||
public:
|
||||
static FMT_CONSTEXPR_DECL const bool value =
|
||||
!std::is_void<decltype(check<T>(nullptr))>::value;
|
||||
!std::is_void<decltype(check<T>(FMT_NULL))>::value;
|
||||
};
|
||||
|
||||
template <typename... Ts>
|
||||
@ -95,8 +96,8 @@ struct is_range_ : std::false_type {};
|
||||
template <typename T>
|
||||
struct is_range_<T,typename std::conditional<
|
||||
false,
|
||||
conditional_helper<decltype(std::declval<T>().begin()),
|
||||
decltype(std::declval<T>().end())>,
|
||||
conditional_helper<decltype(internal::declval<T>().begin()),
|
||||
decltype(internal::declval<T>().end())>,
|
||||
void>::type> : std::true_type {};
|
||||
|
||||
template <typename T>
|
||||
@ -111,13 +112,13 @@ class is_tuple_like_ {
|
||||
template <typename U>
|
||||
static auto check(U *p) ->
|
||||
decltype(std::tuple_size<U>::value,
|
||||
std::declval<typename std::tuple_element<0, U>::type>(), int());
|
||||
internal::declval<typename std::tuple_element<0, U>::type>(), int());
|
||||
template <typename>
|
||||
static void check(...);
|
||||
|
||||
public:
|
||||
static FMT_CONSTEXPR_DECL const bool value =
|
||||
!std::is_void<decltype(check<T>(nullptr))>::value;
|
||||
!std::is_void<decltype(check<T>(FMT_NULL))>::value;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
@ -125,7 +126,16 @@ struct is_tuple_like {
|
||||
static FMT_CONSTEXPR_DECL const bool value =
|
||||
is_tuple_like_<T>::value && !is_range_<T>::value;
|
||||
};
|
||||
} // namespace internal
|
||||
|
||||
#if FMT_HAS_FEATURE(__cpp_lib_integer_sequence)
|
||||
# define FMT_USE_INTEGER_SEQUENCE 1
|
||||
#else
|
||||
# define FMT_USE_INTEGER_SEQUENCE 0
|
||||
#endif
|
||||
|
||||
#if FMT_USE_INTEGER_SEQUENCE
|
||||
namespace internal {
|
||||
template <size_t... Is, class Tuple, class F>
|
||||
void for_each(std::index_sequence<Is...>, Tuple &&tup, F &&f) noexcept {
|
||||
using std::get;
|
||||
@ -183,6 +193,7 @@ struct formatter<TupleT, Char,
|
||||
return ctx.out();
|
||||
}
|
||||
};
|
||||
#endif // FMT_USE_INTEGER_SEQUENCE
|
||||
|
||||
template <typename RangeT, typename Char>
|
||||
struct formatter< RangeT, Char,
|
||||
@ -196,11 +207,12 @@ struct formatter< RangeT, Char,
|
||||
}
|
||||
|
||||
template <typename FormatContext>
|
||||
auto format(const RangeT &values, FormatContext &ctx) -> decltype(ctx.out()) {
|
||||
typename FormatContext::iterator format(
|
||||
const RangeT &values, FormatContext &ctx) {
|
||||
auto out = ctx.out();
|
||||
internal::copy(formatting.prefix, out);
|
||||
std::size_t i = 0;
|
||||
for (const auto &it : values) {
|
||||
for (auto it = values.begin(), end = values.end(); it != end; ++it) {
|
||||
if (i > 0) {
|
||||
if (formatting.add_prepostfix_space) {
|
||||
*out++ = ' ';
|
||||
@ -208,9 +220,9 @@ struct formatter< RangeT, Char,
|
||||
internal::copy(formatting.delimiter, out);
|
||||
}
|
||||
if (formatting.add_delimiter_spaces && i > 0) {
|
||||
format_to(out, " {}", it);
|
||||
format_to(out, " {}", *it);
|
||||
} else {
|
||||
format_to(out, "{}", it);
|
||||
format_to(out, "{}", *it);
|
||||
}
|
||||
if (++i > formatting.range_length_limit) {
|
||||
format_to(out, " ... <other elements>");
|
||||
|
@ -1394,7 +1394,8 @@ TEST(FormatTest, FixedEnum) {
|
||||
typedef fmt::back_insert_range<fmt::internal::buffer> buffer_range;
|
||||
|
||||
class mock_arg_formatter:
|
||||
public fmt::internal::function<void>,
|
||||
public fmt::internal::function<
|
||||
fmt::internal::arg_formatter_base<buffer_range>::iterator>,
|
||||
public fmt::internal::arg_formatter_base<buffer_range> {
|
||||
private:
|
||||
MOCK_METHOD1(call, void (int value));
|
||||
|
@ -30,6 +30,7 @@ TEST(RangesTest, FormatVector2) {
|
||||
EXPECT_EQ("{{1, 2}, {3, 5}, {7, 11}}", ivf);
|
||||
}
|
||||
|
||||
#if FMT_USE_INTEGER_SEQUENCE
|
||||
TEST(RangesTest, FormatMap) {
|
||||
std::map<std::string, int32_t> simap{{"one", 1}, {"two", 2}};
|
||||
EXPECT_EQ("{(one, 1), (two, 2)}", fmt::format("{}", simap));
|
||||
@ -46,7 +47,7 @@ TEST(RangesTest, FormatTuple) {
|
||||
EXPECT_EQ("(42, 3.14159, this is tuple)", fmt::format("{}", tu1));
|
||||
}
|
||||
|
||||
/// check if 'if constexpr' is supported.
|
||||
/// Check if 'if constexpr' is supported.
|
||||
#if (__cplusplus > 201402L) || \
|
||||
(defined(_MSVC_LANG) && _MSVC_LANG > 201402L && _MSC_VER >= 1910)
|
||||
|
||||
@ -86,3 +87,4 @@ TEST(RangesTest, FormatStruct) {
|
||||
|
||||
#endif // (__cplusplus > 201402L) || (defined(_MSVC_LANG) && _MSVC_LANG >
|
||||
// 201402L && _MSC_VER >= 1910)
|
||||
#endif // FMT_USE_INTEGER_SEQUENCE
|
||||
|
@ -397,13 +397,14 @@ TEST(FixedBufferTest, BufferOverflow) {
|
||||
EXPECT_THROW_MSG(buffer.resize(11), std::runtime_error, "buffer overflow");
|
||||
}
|
||||
|
||||
struct uint32_pair {
|
||||
uint32_t u[2];
|
||||
};
|
||||
|
||||
TEST(UtilTest, BitCast) {
|
||||
struct S {
|
||||
uint32_t u[2];
|
||||
};
|
||||
auto s = fmt::internal::bit_cast<S>(uint64_t(42));
|
||||
auto s = fmt::internal::bit_cast<uint32_pair>(uint64_t{42});
|
||||
EXPECT_EQ(fmt::internal::bit_cast<uint64_t>(s), 42u);
|
||||
s = fmt::internal::bit_cast<S>(uint64_t(~0ull));
|
||||
s = fmt::internal::bit_cast<uint32_pair>(uint64_t(~0ull));
|
||||
EXPECT_EQ(fmt::internal::bit_cast<uint64_t>(s), ~0ull);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user