Commit 17702969 authored by gabime's avatar gabime

Upgrded to fmt version 5.2.1

parent cc3613e0
This diff is collapsed.
......@@ -16,7 +16,7 @@
#include <type_traits>
// The fmt library version in the form major * 10000 + minor * 100 + patch.
#define FMT_VERSION 50200
#define FMT_VERSION 50201
#ifdef __has_feature
# define FMT_HAS_FEATURE(x) __has_feature(x)
......@@ -340,9 +340,22 @@ class basic_format_arg;
template <typename Context>
class basic_format_args;
template <typename T>
struct no_formatter_error : std::false_type {};
// A formatter for objects of type T.
template <typename T, typename Char = char, typename Enable = void>
struct formatter;
struct formatter {
static_assert(no_formatter_error<T>::value,
"don't know how to format the type, include fmt/ostream.h if it provides "
"an operator<< that should be used");
// The following functions are not defined intentionally.
template <typename ParseContext>
typename ParseContext::iterator parse(ParseContext &);
template <typename FormatContext>
auto format(const T &val, FormatContext &ctx) -> decltype(ctx.out());
};
template <typename T, typename Char, typename Enable = void>
struct convert_to_int {
......@@ -755,6 +768,54 @@ class basic_format_arg {
bool is_arithmetic() const { return internal::is_arithmetic(type_); }
};
struct monostate {};
/**
\rst
Visits an argument dispatching to the appropriate visit method based on
the argument type. For example, if the argument type is ``double`` then
``vis(value)`` will be called with the value of type ``double``.
\endrst
*/
template <typename Visitor, typename Context>
FMT_CONSTEXPR typename internal::result_of<Visitor(int)>::type
visit(Visitor &&vis, const basic_format_arg<Context> &arg) {
typedef typename Context::char_type char_type;
switch (arg.type_) {
case internal::none_type:
break;
case internal::named_arg_type:
FMT_ASSERT(false, "invalid argument type");
break;
case internal::int_type:
return vis(arg.value_.int_value);
case internal::uint_type:
return vis(arg.value_.uint_value);
case internal::long_long_type:
return vis(arg.value_.long_long_value);
case internal::ulong_long_type:
return vis(arg.value_.ulong_long_value);
case internal::bool_type:
return vis(arg.value_.int_value != 0);
case internal::char_type:
return vis(static_cast<char_type>(arg.value_.int_value));
case internal::double_type:
return vis(arg.value_.double_value);
case internal::long_double_type:
return vis(arg.value_.long_double_value);
case internal::cstring_type:
return vis(arg.value_.string.value);
case internal::string_type:
return vis(basic_string_view<char_type>(
arg.value_.string.value, arg.value_.string.size));
case internal::pointer_type:
return vis(arg.value_.pointer);
case internal::custom_type:
return vis(typename basic_format_arg<Context>::handle(arg.value_.custom));
}
return vis(monostate());
}
// Parsing context consisting of a format string range being parsed and an
// argument counter for automatic indexing.
template <typename Char, typename ErrorHandler = internal::error_handler>
......@@ -1382,8 +1443,7 @@ inline std::basic_string<
typedef typename buffer_context<char_t>::type context_t;
format_arg_store<context_t, Args...> as{args...};
return internal::vformat(
basic_string_view<char_t>(format_str),
basic_format_args<context_t>(as));
basic_string_view<char_t>(format_str), basic_format_args<context_t>(as));
}
FMT_API void vprint(std::FILE *f, string_view format_str, format_args args);
......
......@@ -51,6 +51,12 @@
# define FMT_ICC_VERSION 0
#endif
#ifdef __NVCC__
# define FMT_CUDA_VERSION (__CUDACC_VER_MAJOR__ * 100 + __CUDACC_VER_MINOR__)
#else
# define FMT_CUDA_VERSION 0
#endif
#include "core.h"
#if FMT_GCC_VERSION >= 406 || FMT_CLANG_VERSION
......@@ -114,17 +120,23 @@ FMT_END_NAMESPACE
#endif
#ifndef FMT_USE_USER_DEFINED_LITERALS
// For Intel's compiler both it and the system gcc/msc must support UDLs.
// For Intel's compiler and NVIDIA's compiler both it and the system gcc/msc
// must support UDLs.
# if (FMT_HAS_FEATURE(cxx_user_literals) || \
FMT_GCC_VERSION >= 407 || FMT_MSC_VER >= 1900) && \
(!FMT_ICC_VERSION || FMT_ICC_VERSION >= 1500)
(!(FMT_ICC_VERSION || FMT_CUDA_VERSION) || \
FMT_ICC_VERSION >= 1500 || FMT_CUDA_VERSION >= 700)
# define FMT_USE_USER_DEFINED_LITERALS 1
# else
# define FMT_USE_USER_DEFINED_LITERALS 0
# endif
#endif
#if FMT_USE_USER_DEFINED_LITERALS && FMT_ICC_VERSION == 0 && \
// EDG C++ Front End based compilers (icc, nvcc) do not currently support UDL
// templates.
#if FMT_USE_USER_DEFINED_LITERALS && \
FMT_ICC_VERSION == 0 && \
FMT_CUDA_VERSION == 0 && \
((FMT_GCC_VERSION >= 600 && __cplusplus >= 201402L) || \
(defined(FMT_CLANG_VERSION) && FMT_CLANG_VERSION >= 304))
# define FMT_UDL_TEMPLATE 1
......@@ -1154,54 +1166,6 @@ template <typename T = void>
struct null {};
} // namespace internal
struct monostate {};
/**
\rst
Visits an argument dispatching to the appropriate visit method based on
the argument type. For example, if the argument type is ``double`` then
``vis(value)`` will be called with the value of type ``double``.
\endrst
*/
template <typename Visitor, typename Context>
FMT_CONSTEXPR typename internal::result_of<Visitor(int)>::type
visit(Visitor &&vis, const basic_format_arg<Context> &arg) {
typedef typename Context::char_type char_type;
switch (arg.type_) {
case internal::none_type:
break;
case internal::named_arg_type:
FMT_ASSERT(false, "invalid argument type");
break;
case internal::int_type:
return vis(arg.value_.int_value);
case internal::uint_type:
return vis(arg.value_.uint_value);
case internal::long_long_type:
return vis(arg.value_.long_long_value);
case internal::ulong_long_type:
return vis(arg.value_.ulong_long_value);
case internal::bool_type:
return vis(arg.value_.int_value != 0);
case internal::char_type:
return vis(static_cast<char_type>(arg.value_.int_value));
case internal::double_type:
return vis(arg.value_.double_value);
case internal::long_double_type:
return vis(arg.value_.long_double_value);
case internal::cstring_type:
return vis(arg.value_.string.value);
case internal::string_type:
return vis(basic_string_view<char_type>(
arg.value_.string.value, arg.value_.string.size));
case internal::pointer_type:
return vis(arg.value_.pointer);
case internal::custom_type:
return vis(typename basic_format_arg<Context>::handle(arg.value_.custom));
}
return vis(monostate());
}
enum alignment {
ALIGN_DEFAULT, ALIGN_LEFT, ALIGN_RIGHT, ALIGN_CENTER, ALIGN_NUMERIC
};
......@@ -3231,8 +3195,8 @@ struct formatter<
specs_.precision_, specs_.precision_ref, ctx);
typedef output_range<typename FormatContext::iterator,
typename FormatContext::char_type> range_type;
return visit(arg_formatter<range_type>(ctx, &specs_),
internal::make_arg<FormatContext>(val));
return fmt::visit(arg_formatter<range_type>(ctx, &specs_),
internal::make_arg<FormatContext>(val));
}
private:
......@@ -3292,8 +3256,8 @@ class dynamic_formatter {
checker.end_precision();
typedef output_range<typename FormatContext::iterator,
typename FormatContext::char_type> range;
visit(arg_formatter<range>(ctx, &specs_),
internal::make_arg<FormatContext>(val));
fmt::visit(arg_formatter<range>(ctx, &specs_),
internal::make_arg<FormatContext>(val));
return ctx.out();
}
......@@ -3493,16 +3457,17 @@ inline wformat_context::iterator vformat_to(
return vformat_to<arg_formatter<range>>(buf, format_str, args);
}
template <typename String, typename... Args,
std::size_t SIZE = inline_buffer_size>
inline format_context::iterator format_to(
basic_memory_buffer<char, SIZE> &buf, const String &format_str,
template <
typename String, typename... Args,
std::size_t SIZE = inline_buffer_size,
typename Char = typename internal::format_string_traits<String>::char_type>
inline typename buffer_context<Char>::type::iterator format_to(
basic_memory_buffer<Char, SIZE> &buf, const String &format_str,
const Args & ... args) {
internal::check_format_string<Args...>(format_str);
typedef typename internal::format_string_traits<String>::char_type char_t;
return vformat_to(
buf, basic_string_view<char_t>(format_str),
make_format_args<typename buffer_context<char_t>::type>(args...));
buf, basic_string_view<Char>(format_str),
make_format_args<typename buffer_context<Char>::type>(args...));
}
template <typename OutputIt, typename Char = char>
......@@ -3725,10 +3690,13 @@ FMT_END_NAMESPACE
#if defined(FMT_STRING_ALIAS) && FMT_STRING_ALIAS
/**
\rst
Constructs a compile-time format string.
Constructs a compile-time format string. This macro is disabled by default to
prevent potential name collisions. To enable it define ``FMT_STRING_ALIAS`` to
1 before including ``fmt/format.h``.
**Example**::
#define FMT_STRING_ALIAS 1
#include <fmt/format.h>
// A compile-time error because 'd' is an invalid specifier for strings.
std::string s = format(fmt("{:d}"), "foo");
......
// Formatting library for C++ - locale support
//
// Copyright (c) 2012 - 2016, Victor Zverovich
// All rights reserved.
//
// For the license information refer to format.h.
#include "format.h"
#include <locale>
namespace fmt {
class locale
{
private:
std::locale locale_;
public:
explicit locale(std::locale loc = std::locale())
: locale_(loc)
{
}
std::locale get()
{
return locale_;
}
};
} // namespace fmt
......@@ -133,7 +133,7 @@ class arg_converter: public function<void> {
// unsigned).
template <typename T, typename Context, typename Char>
void convert_arg(basic_format_arg<Context> &arg, Char type) {
visit(arg_converter<T, Context>(arg, type), arg);
fmt::visit(arg_converter<T, Context>(arg, type), arg);
}
// Converts an integer argument to char for printf.
......@@ -454,7 +454,7 @@ unsigned basic_printf_context<OutputIt, Char, AF>::parse_header(
} else if (*it == '*') {
++it;
spec.width_ =
visit(internal::printf_width_handler<char_type>(spec), get_arg(it));
fmt::visit(internal::printf_width_handler<char_type>(spec), get_arg(it));
}
return arg_index;
}
......@@ -490,14 +490,14 @@ void basic_printf_context<OutputIt, Char, AF>::format() {
} else if (*it == '*') {
++it;
spec.precision_ =
visit(internal::printf_precision_handler(), get_arg(it));
fmt::visit(internal::printf_precision_handler(), get_arg(it));
} else {
spec.precision_ = 0;
}
}
format_arg arg = get_arg(it, arg_index);
if (spec.flag(HASH_FLAG) && visit(internal::is_zero_int(), arg))
if (spec.flag(HASH_FLAG) && fmt::visit(internal::is_zero_int(), arg))
spec.flags_ &= ~internal::to_unsigned<int>(HASH_FLAG);
if (spec.fill_ == '0') {
if (arg.is_arithmetic())
......@@ -551,7 +551,7 @@ void basic_printf_context<OutputIt, Char, AF>::format() {
break;
case 'c':
// TODO: handle wchar_t better?
visit(internal::char_converter<basic_printf_context>(arg), arg);
fmt::visit(internal::char_converter<basic_printf_context>(arg), arg);
break;
}
}
......@@ -559,7 +559,7 @@ void basic_printf_context<OutputIt, Char, AF>::format() {
start = it;
// Format argument.
visit(AF(buffer, spec, *this), arg);
fmt::visit(AF(buffer, spec, *this), arg);
}
buffer.append(pointer_from(start), pointer_from(it));
}
......
......@@ -87,6 +87,9 @@ class is_like_std_string {
!std::is_void<decltype(check<T>(FMT_NULL))>::value;
};
template <typename Char>
struct is_like_std_string<fmt::basic_string_view<Char>> : std::true_type {};
template <typename... Ts>
struct conditional_helper {};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment