Make buffer_context an alias template

This commit is contained in:
Victor Zverovich 2019-06-02 17:13:50 -07:00
parent ec6651087d
commit d54e64b3c8
8 changed files with 50 additions and 57 deletions

View File

@ -526,9 +526,9 @@ template <> struct is_string<std::FILE*> : std::false_type {};
template <> struct is_string<const std::FILE*> : std::false_type {};
template <typename Char>
std::basic_string<Char> vformat(
const text_style& ts, basic_string_view<Char> format_str,
basic_format_args<typename buffer_context<Char>::type> args) {
std::basic_string<Char> vformat(const text_style& ts,
basic_string_view<Char> format_str,
basic_format_args<buffer_context<Char> > args) {
basic_memory_buffer<Char> buffer;
bool has_style = false;
if (ts.has_emphasis()) {
@ -558,7 +558,7 @@ std::basic_string<Char> vformat(
template <typename S, typename Char = char_t<S> >
void vprint(std::FILE* f, const text_style& ts, const S& format,
basic_format_args<typename buffer_context<Char>::type> args) {
basic_format_args<buffer_context<Char> > args) {
bool has_style = false;
if (ts.has_emphasis()) {
has_style = true;
@ -592,9 +592,9 @@ template <typename S, typename... Args,
void print(std::FILE* f, const text_style& ts, const S& format_str,
const Args&... args) {
internal::check_format_string<Args...>(format_str);
typedef typename buffer_context<char_t<S> >::type context_t;
format_arg_store<context_t, Args...> as{args...};
vprint(f, ts, format_str, basic_format_args<context_t>(as));
using context = buffer_context<char_t<S> >;
format_arg_store<context, Args...> as{args...};
vprint(f, ts, format_str, basic_format_args<context>(as));
}
/**
@ -613,7 +613,7 @@ void print(const text_style& ts, const S& format_str, const Args&... args) {
template <typename S, typename Char = char_t<S> >
inline std::basic_string<Char> vformat(
const text_style& ts, const S& format_str,
basic_format_args<typename buffer_context<Char>::type> args) {
basic_format_args<buffer_context<Char> > args) {
return internal::vformat(ts, to_string_view(format_str), args);
}

View File

@ -1077,7 +1077,7 @@ template <typename OutputIt, typename Char> class basic_format_context {
public:
using iterator = OutputIt;
using format_arg = basic_format_arg<basic_format_context> ;
using format_arg = basic_format_arg<basic_format_context>;
template <typename T> using formatter_type = formatter<T, char_type>;
/**
@ -1108,13 +1108,12 @@ template <typename OutputIt, typename Char> class basic_format_context {
internal::locale_ref locale() { return loc_; }
};
template <typename Char> struct buffer_context {
typedef basic_format_context<
std::back_insert_iterator<internal::buffer<Char>>, Char>
type;
};
using format_context = buffer_context<char>::type;
using wformat_context = buffer_context<wchar_t>::type;
template <typename Char>
using buffer_context =
basic_format_context<std::back_insert_iterator<internal::buffer<Char>>,
Char>;
using format_context = buffer_context<char>;
using wformat_context = buffer_context<wchar_t>;
/**
\rst
@ -1130,8 +1129,9 @@ template <typename Context, typename... Args> class format_arg_store {
// Packed is a macro on MinGW so use IS_PACKED instead.
static const bool IS_PACKED = NUM_ARGS < internal::max_packed_args;
using value_type = typename std::conditional<IS_PACKED, internal::value<Context>,
basic_format_arg<Context>>::type;
using value_type =
typename std::conditional<IS_PACKED, internal::value<Context>,
basic_format_arg<Context>>::type;
// If the arguments are not packed, add one more element to mark the end.
static const size_t DATA_SIZE =
@ -1301,8 +1301,7 @@ template <typename Char> struct named_arg_base {
basic_string_view<Char> name;
// Serialized value<context>.
mutable char
data[sizeof(basic_format_arg<typename buffer_context<Char>::type>)];
mutable char data[sizeof(basic_format_arg<buffer_context<Char>>)];
named_arg_base(basic_string_view<Char> nm) : name(nm) {}
@ -1329,21 +1328,20 @@ void check_format_string(S);
template <typename S, typename... Args,
typename Char = enable_if_t<internal::is_string<S>::value, char_t<S>>>
inline format_arg_store<typename buffer_context<Char>::type, Args...>
make_args_checked(const S& format_str, const Args&... args) {
inline format_arg_store<buffer_context<Char>, Args...> make_args_checked(
const S& format_str, const Args&... args) {
internal::check_format_string<Args...>(format_str);
return {args...};
}
template <typename Char>
std::basic_string<Char> vformat(
basic_string_view<Char> format_str,
basic_format_args<typename buffer_context<Char>::type> args);
std::basic_string<Char> vformat(basic_string_view<Char> format_str,
basic_format_args<buffer_context<Char>> args);
template <typename Char>
typename buffer_context<Char>::type::iterator vformat_to(
typename buffer_context<Char>::iterator vformat_to(
internal::buffer<Char>& buf, basic_string_view<Char> format_str,
basic_format_args<typename buffer_context<Char>::type> args);
basic_format_args<buffer_context<Char>> args);
} // namespace internal
/**
@ -1387,12 +1385,10 @@ struct is_contiguous_back_insert_iterator<std::back_insert_iterator<Container>>
: is_contiguous<Container> {};
/** Formats a string and writes the output to ``out``. */
template <typename OutputIt, typename S,
typename Char = enable_if_t<
is_contiguous_back_insert_iterator<OutputIt>::value, char_t<S>>>
OutputIt vformat_to(
OutputIt out, const S& format_str,
basic_format_args<typename buffer_context<Char>::type> args) {
template <typename OutputIt, typename S, typename Char = char_t<S>,
FMT_ENABLE_IF(is_contiguous_back_insert_iterator<OutputIt>::value)>
OutputIt vformat_to(OutputIt out, const S& format_str,
basic_format_args<buffer_context<Char>> args) {
using container = typename std::remove_reference<decltype(
internal::get_container(out))>::type;
internal::container_buffer<container> buf((internal::get_container(out)));
@ -1413,8 +1409,7 @@ inline std::back_insert_iterator<Container> format_to(
template <typename S,
typename Char = enable_if_t<internal::is_string<S>::value, char_t<S>>>
inline std::basic_string<Char> vformat(
const S& format_str,
basic_format_args<typename buffer_context<Char>::type> args) {
const S& format_str, basic_format_args<buffer_context<Char>> args) {
return internal::vformat(to_string_view(format_str), args);
}

View File

@ -953,7 +953,7 @@ FMT_FUNC void report_windows_error(int error_code,
FMT_FUNC void vprint(std::FILE* f, string_view format_str, format_args args) {
memory_buffer buffer;
internal::vformat_to(buffer, format_str,
basic_format_args<buffer_context<char>::type>(args));
basic_format_args<buffer_context<char>>(args));
fwrite_fully(buffer.data(), 1, buffer.size(), f);
}

View File

@ -3046,7 +3046,7 @@ class format_int {
template <typename T, typename Char>
struct formatter<T, Char,
typename std::enable_if<internal::format_type<
typename buffer_context<Char>::type, T>::value>::type> {
buffer_context<Char>, T>::value>::type> {
FMT_CONSTEXPR formatter() : format_str_(nullptr) {}
// Parses format specifiers stopping either at the end of the range or at the
@ -3055,8 +3055,7 @@ struct formatter<T, Char,
FMT_CONSTEXPR typename ParseContext::iterator parse(ParseContext& ctx) {
format_str_ = ctx.begin();
typedef internal::dynamic_specs_handler<ParseContext> handler_type;
auto type =
internal::get_type<typename buffer_context<Char>::type, T>::value;
auto type = internal::get_type<buffer_context<Char>, T>::value;
internal::specs_checker<handler_type> handler(handler_type(specs_, ctx),
type);
auto it = parse_format_specs(ctx.begin(), ctx.end(), handler);
@ -3377,9 +3376,9 @@ std::basic_string<Char> to_string(const basic_memory_buffer<Char, SIZE>& buf) {
}
template <typename Char>
typename buffer_context<Char>::type::iterator internal::vformat_to(
typename buffer_context<Char>::iterator internal::vformat_to(
internal::buffer<Char>& buf, basic_string_view<Char> format_str,
basic_format_args<typename buffer_context<Char>::type> args) {
basic_format_args<buffer_context<Char>> args) {
typedef back_insert_range<internal::buffer<Char>> range;
return vformat_to<arg_formatter<range>>(buf, to_string_view(format_str),
args);
@ -3387,19 +3386,19 @@ typename buffer_context<Char>::type::iterator internal::vformat_to(
template <typename S, typename Char = char_t<S>,
FMT_ENABLE_IF(internal::is_string<S>::value)>
inline typename buffer_context<Char>::type::iterator vformat_to(
inline typename buffer_context<Char>::iterator vformat_to(
internal::buffer<Char>& buf, const S& format_str,
basic_format_args<typename buffer_context<Char>::type> args) {
basic_format_args<buffer_context<Char>> args) {
return internal::vformat_to(buf, to_string_view(format_str), args);
}
template <typename S, typename... Args, std::size_t SIZE = inline_buffer_size,
typename Char = enable_if_t<internal::is_string<S>::value, char_t<S>>>
inline typename buffer_context<Char>::type::iterator format_to(
inline typename buffer_context<Char>::iterator format_to(
basic_memory_buffer<Char, SIZE>& buf, const S& format_str,
const Args&... args) {
internal::check_format_string<Args...>(format_str);
using context = typename buffer_context<Char>::type;
using context = buffer_context<Char>;
format_arg_store<context, Args...> as{args...};
return internal::vformat_to(buf, to_string_view(format_str),
basic_format_args<context>(as));
@ -3554,7 +3553,7 @@ inline format_to_n_result<OutputIt> format_to_n(OutputIt out, std::size_t n,
template <typename Char>
inline std::basic_string<Char> internal::vformat(
basic_string_view<Char> format_str,
basic_format_args<typename buffer_context<Char>::type> args) {
basic_format_args<buffer_context<Char>> args) {
basic_memory_buffer<Char> buffer;
internal::vformat_to(buffer, format_str, args);
return fmt::to_string(buffer);

View File

@ -15,19 +15,19 @@ FMT_BEGIN_NAMESPACE
namespace internal {
template <typename Char>
typename buffer_context<Char>::type::iterator vformat_to(
typename buffer_context<Char>::iterator vformat_to(
const std::locale& loc, buffer<Char>& buf,
basic_string_view<Char> format_str,
basic_format_args<typename buffer_context<Char>::type> args) {
basic_format_args<buffer_context<Char>> args) {
typedef back_insert_range<buffer<Char>> range;
return vformat_to<arg_formatter<range>>(buf, to_string_view(format_str), args,
internal::locale_ref(loc));
}
template <typename Char>
std::basic_string<Char> vformat(
const std::locale& loc, basic_string_view<Char> format_str,
basic_format_args<typename buffer_context<Char>::type> args) {
std::basic_string<Char> vformat(const std::locale& loc,
basic_string_view<Char> format_str,
basic_format_args<buffer_context<Char>> args) {
basic_memory_buffer<Char> buffer;
internal::vformat_to(loc, buffer, format_str, args);
return fmt::to_string(buffer);
@ -37,7 +37,7 @@ std::basic_string<Char> vformat(
template <typename S, typename Char = char_t<S>>
inline std::basic_string<Char> vformat(
const std::locale& loc, const S& format_str,
basic_format_args<typename buffer_context<Char>::type> args) {
basic_format_args<buffer_context<Char>> args) {
return internal::vformat(loc, to_string_view(format_str), args);
}

View File

@ -121,7 +121,7 @@ struct convert_to_int<
template <typename Char>
void vprint(std::basic_ostream<Char>& os, basic_string_view<Char> format_str,
basic_format_args<typename buffer_context<Char>::type> args) {
basic_format_args<buffer_context<Char>> args) {
basic_memory_buffer<Char> buffer;
internal::vformat_to(buffer, format_str, args);
internal::write(os, buffer);

View File

@ -239,14 +239,14 @@ class prepared_format {
}
template <std::size_t SIZE = inline_buffer_size>
inline typename buffer_context<char_type>::type::iterator format_to(
inline typename buffer_context<char_type>::iterator format_to(
basic_memory_buffer<char_type, SIZE>& buf, const Args&... args) const {
typedef back_insert_range<internal::buffer<char_type>> range;
return this->vformat_to(range(buf), make_args_checked(format_, args...));
}
private:
typedef typename buffer_context<char_type>::type context;
typedef buffer_context<char_type> context;
template <typename Range>
typename context::iterator vformat_to(Range out,

View File

@ -643,8 +643,7 @@ struct formatter {
FMT_CONSTEXPR typename ParseContext::iterator parse(ParseContext& ctx) {
namespace internal = fmt::internal;
typedef internal::dynamic_specs_handler<ParseContext> handler_type;
auto type =
internal::get_type<typename fmt::buffer_context<Char>::type, T>::value;
auto type = internal::get_type<fmt::buffer_context<Char>, T>::value;
internal::specs_checker<handler_type> handler(handler_type(specs_, ctx),
type);
auto it = parse_format_specs(ctx.begin(), ctx.end(), handler);